in reply to Those unreliable file stat operations in Win32
The problem arises because NTFS preallocates the space for the whole file in one hit if it knows the final size, which it obviously does when using the CopyFile() API or an application that resolves to it. This is what allows the OS to report "There is not enough space on the disk." before it actually starts transfering data.
Perhaps the simplest way of determining when the copy is finished would be to loop over trying to open the file until you suceed. If the application doing the copying cooperates by opening it's output file with an exclusive lock, this will tell you when the file has been closed and the copy completed.
If the application doing the copying isn't being nice and opening the output file exclusively, then you could use the native API OpenFile (via Win32::API::Prototype or similar) to try and open the file OF_SHARE_EXCLUSIVE yourself. Once this succeeds, the copy has finished.
You might also try looking at the functions Win32::File to see if one of those will allow you to attempt an exclusive open of the file, but I've never managed to decypher what's going on in there -- the pod is scary:)
|
|---|