I have a function that is supposed to create a backup of a source folder by copying all files from the source to a destination folder. The function uses a while loop driven by FindFirstFile
/ FindNextFile
, then invokes CopyFile
for each file found by the Find...
function.
Now when the source folder is an SMB network path (regardless of whether I use a mapped drive or a UNC path), it sometimes happens that FindNextFile
"sees" a file, but CopyFile
refuses to copy the file. The error code is 2, i.e. ERROR_FILE_NOT_FOUND
.
I found this hard to believe, so I added a call to _access
to the backup function that checks for file existence just before CopyFile
is called. The result is the same as for CopyFile
, i.e. _access
reports that the file does not exist (return code -1 and errno
is 2, i.e. ENOENT
).
So my main question is: How is it possible that FindFirstFile
/ FindNextFile
"sees" files on a network folder that neither CopyFile
nor _access
can see?
Additional information / diagnostics:
- The problematic file is a file that is created immediately before the backup function is run. Specifically it works like this: A process that runs on the client machine has a network connection to a process that runs on the server machine. The client process tells the server process to create the file. This is supposed to work synchronously: Only after the server process acknowledges that it has created the file does the client process go on to perform the backup.
- I added a retry mechanism to the backup function. With this,
CopyFile
and_access
suddenly start to see the file in question after about 4 seconds of retrying. This indicates to me that there is indeed some sort of network-delay involved. It appears as ifFindFirstFile
/FindNextFile
access the network path differently thanCopyFile
/_access
.
Unfortunately my research to this effect did not turn up any useful information, so I can only speculate. If FindFirstFile
/ FindNextFile
/ CopyFile
indeed do not work well together, do you know of a different set of find/copy API functions that work more reliable?