Reputation: 400
Let's say I run robocopy, using winapi's CreateProcess function. If I stop the process before it exits, will this create corrupted files of any kind? For example I have a maximum of 10000ms to run robocopy, before I have to stop it and do something else.
For example:
DWORD state = WaitForSingleObject(robocopyProcessInfo.hProcess, 10000);
if (state == WAIT_FAILED || state == WAIT_TIMEOUT)
{
CloseHandle(robocopyProcessInfo.hProcess);
CloseHandle(robocopyProcessInfo.hThread);
return;
}
If this times out, is it possible to end up with corrupted files at the destination, and if so how do I prevent this, or solve this problem in a different way? I couldn't find any argument for robocopy that specifies timeout or something similar, or any info about this topic.
Upvotes: -1
Views: 265
Reputation: 671
Yes and No... ;)
The steps robocopy would take are:
If it gets interrupted at this point, there is no guarantee that the file is not "corrupted". But rather it is only "unfinished". If you start the robocopy job again, it will detect the timestamp being "much older" and therefore start copying that file again.
Only if robocopy finishes the copying of a file, it will set the timestamp to the correct value taken from the original (and according to the parameter configuration).
So, yes, intermediately there can be files which are incomplete. But after robocopy was able to run to completeness, the files are complete.
In short: It is perfectly fine to interrupt/pause/kill robocopy at any given time and resume later.
Upvotes: 0