I am writing a program to duplicate what user do in one computer, and repeat in another computer. Basically a sync program between computers.
I have succesfully copied create and delete event, even partially modified files, but I have a little problem with files that moves between folders.
Not every folders are under my watcher, and my program can monitor several folders. Therefore I made a combined log for all operations from many different watchers. But for those under my watcher, they shows as created and deleted events on my log. My current method is delay all the process, and transfer the log in a batch.
So far it runs good, but I keep thinking, that this method is not reliable to detect moves. for example, if a file moved, it will generate delete + create event. What if when the time due for another update, and one of those 2 events are not captured? for example, the watcher registers a delete event, then before it register create event, the log get shipped? That way, the other computer will delete a file, then next due operation, it will have to download the file again because of late create event. It just has not happenned yet because my computer is only a test environment. But real life PC will have multiple files move and created at once. A delete event is easy, but a late create event will make a problem, especially with big files.
How many miliseconds is a safe threshold to wait for the second event? Or better yet, is there any other good method on how to detect these 2 events as whole reliably, before it transmit the log?
UPDATE: Let me make something clear.. The log shows as these example:
create file A
delete file B
create file B
delete file C
-> log transmitted
create file C
create file D
modify file E
-> log transmitted
In this example, server would do sync twice. Now, file B won't have a problem since my program have detected B fingerprint on both operation at first log, and move file B accordingly, but file C will have to be retransmitted. My problem is, is there a way on how to prevent C deleted while waiting for create log?
UPDATE:
If I send IO operation log to remote computer in parallel, this would happen:
create file A
-> log transmitted
delete file B
-> log transmitted
create file B
-> log transmitted
delete file C
-> log transmitted
create file C
-> log transmitted
create file D
-> log transmitted
modify file E
-> log transmitted
Then file B and C would have been deleted when watcher send create operation.
And please, as you should have probably noticed, I am NOT asking how to code watcher. I have made my watcher, and it is WORKING. Albeit sometime high cost for unfortunate move operation. I am looking for a way to know if that a delete operation would or would not have another create operation follows.
Thank you