Forum > General

Copy a Linux file in use?

(1/4) > >>

KarenT:
UPDATE: I have managed to step through FileUtil.inc to this line and this is where it hangs. It is supposed to have 3-tries and then fail, but it goes wandering off when I step into line #600 in my copy of FileUtil.inc. It never returns to increment the retry count.

SrcHandle := LazFileUtils.FileOpenUTF8(SrcFilename, fmOpenRead or fmShareDenyWrite);

Hi, I need to copy some files as a backup and I am hitting a wall with CopyFile, Laz 1.8.4 and Ubuntu 16.04. This backup is just for my own use, so I tried changing file permissions in the offending folder but still it hits the wall.


--- Code: ---  CopyGood:=CopyFile(Filefrom,FileTo,[cffOverwriteFile,cffCreateDestDirectory,cffPreserveTime]);

--- End code ---

The backup is working well until it hits the Veracrypt folder that **appears** to have a file in use or locked. I say "appears," as I am not sure of the cause of the problem, but it just stops before a file.


--- Quote ---.config/VeraCrypt/Configuration.xml
.config/VeraCrypt/Favorite Volumes.xml
// I think the following file is the problem
.config/VeraCrypt/.show-request-queue

--- End quote ---

If I shut down Veracrypt, the ".config/VeraCrypt/.show-request-queue" is no longer there and the backup works fine. But then I have nowhere safe to store the backups so I need Veracrypt running. :)

I tried using a "try-except" but it still hangs there. How can I get it ignore this and carry on?

Thanks

soerensen3:
Probably it's something in VeraCrypt that locks the file for writing, the same way you try to do it (fmShareDenyWrite). Maybe there is a way to tell if a file is already locked before you try to open it, maybe you can open it for reading only then. What happens if you try to copy it from a file manager?

I don't have any idea about the function crashing in this strange way though.

lucamar:

--- Quote from: KarenT on November 14, 2018, 06:10:23 pm ---UPDATE: I have managed to step through FileUtil.inc to this line and this is where it hangs. It is supposed to have 3-tries and then fail, but it goes wandering off when I step into line #600 in my copy of FileUtil.inc. It never returns to increment the retry count.

SrcHandle := LazFileUtils.FileOpenUTF8(SrcFilename, fmOpenRead or fmShareDenyWrite);

--- End quote ---

It shouldn't "go wandering off": it goes only from there through LazFileUtils to end up in sysutils and back again. What is really happening is that, by default,  ExceptionOnError, the last parameter of CopyFile(), is set to False, so the call fails silently.

Try to see what happens if you use:

CopyGood:=CopyFile(Filefrom, FileTo, [cffOverwriteFile,cffCreateDestDirectory,cffPreserveTime], True);

You can catch that exception and do whatever it's you want done, in this case you can probably ignore the error and go on to the next file, since the cause is almost certainly what soerensen3 said.

HTH!

ETA: On second thought, even without that parameter it should just return False which you could catch with an old-fashioned: if not CopyGood . . . If it's not doing that then something else is (very?) wrong.

Thaddy:
From the manual:
"Note that sharing is advisory on Unix-like platforms." so your mileage may vary anyway.
Indeed, checking the function result is a better idea.

https://www.freepascal.org/docs-html/rtl/classes/tfilestream.create.html

KarenT:

--- Quote from: lucamar on November 14, 2018, 10:19:15 pm ---If it's not doing that then something else is (very?) wrong.

--- End quote ---

Thanks, I had already tried all of those things and it was still doing the wandering off. The program would go dark and stay that way.

I was able to trace another level deeper and it is getting to the SystUtils OpenFile call and not coming back but have been unable to get any deeper into it than that.

I also tried changing the FileUtil.inc Permissions to allow me to change the "OpenFile" flags to "DenyNone" but still it crashes. I am with you, something is VERY wrong.

For now I will hard program out the Veracrypt folder. But, methinks a bug is wallowing in there somewhere.

Navigation

[0] Message Index

[#] Next page

Go to full version