Page 1 of 1

Copy partially locked file, overwrite: target is removed

Posted: 2007-05-18, 09:08 UTC
by Flint
Report from the Russian forum.

When PCAD 2006 is running and the file primer.lib opened in it, it is "partially locked". I don't know what that means, but if you have another primer.lib and try to copy the locked primer.lib onto this copy (overwriting it), TC first remove the target file, and then shows a message that the source file cannot be read.

This has also been testing with SpeedCommander 11.6, with the same result. It removes the target file and then shows a message (translated it from Russian into English - so, may be not exact):
Cannot copy "primer.lib"
Error 33: The process cannot access the file as the part of this file is locked by another process.
I don't have PCAD on my computer, so I cannot check it currently...

Posted: 2007-05-20, 08:45 UTC
by ghisler(Author)
This is called "record locking". The problem is that Windows returns an error on ReadFile in the middle of the file. There is no chance to know that beforehand. TC would have to read the entire file into memory first, which is just not feasible for very big files! So what happens is that TC starts reading the file (which works), then it truncates the target and starts writing to it. When reading fails, TC shows an error and deletes the target file (which is incomplete and unusable). Unfortunately TC cannot simply rename the target to keep it for this case, because then the special attributes and permissions of that file would be lost.

Record locking is often used for databases, which can be serveral Gigabytes large. The database should be closed before it is copied, e.g. by closing the program first.

Posted: 2007-05-20, 09:44 UTC
by Flint
OK, that's what I supposed. Thanks for the explanation.

Posted: 2007-05-20, 10:22 UTC
by Hacker
[mod]Moved to the TC7 beta discussion forum.

Hacker (Moderator)[/mod]