views:

155

answers:

1

I am working on a directory syncing program that uses jnotify to check for changes.

The idea is whenever jnotify detects a change, a sync is performed. The problem is that when many files are copied to or modified in a directory, many syncs are performed instead of one large sync.

Ideally if you were to copy 100 large files to directory A, the sync to directory B would not occur until all the files are fully copied to directory A.

I have thought about somehow using a temp directory (A1) to hold files until they are fully copied and then moving them into A1. But this solution does not work well because I am using unison to perform the sync which only sends file deltas - and that is a feature I would like to use and not circumvent.

Perhaps there is a way to use i/jnotify to detect when multiple files are being updated at once?

A: 

Here's a suggestion. How about setting up a set on your application and have it collect up "modified" files/etc it would add that file to a set and when the number of files exceed a certain amount of number, say 100, you would then do a sync. It would also be a good idea to set up a timer too if you want it to be reasonable responsive, like if there is no new changes/etc that is being added to the set for X amount of time go ahead and do a sync also.

Pharaun
Thanks for the response. So far, I am thinking it might work as follows until I can find a better solution... Whenever an action (ie - CREATE) occurs, have a listener thread wait up to 1 second to see if another action is detected. If no action is detected, then perform the sync. Then once a sync is initiated postpone further calls to sync to until the current sync has been finished. If files are left to sync, perform another sync after the first one. This will force syncs into batches of small file groups. Or will sync one large file at a time. Which seems kind of reasonable.
Jono
@Jono - That seems reasonable, I would personally have a bit longer delay myself but the general idea seems reasonable, it would need some work to implement but its doable. How are you going to deal with changes to a file? (a direct copy, or something like rsync)
Pharaun
Not sure what you mean by dealing with changes to a file. I will be using inotify on the whole directory to check for any changes within it.
Jono
By that I mean, like how are you going to be copying over the changed file/directory? aka using rsync or just regular copy each time?
Pharaun
ah. I am planning on using unison. I need two way syncing. I would prefer something written in Java which will integrate with my code better, but it seems like the best tool for the job.
Jono
aha, sounds like the best bet to me :) I've used unison before, its pretty nice.
Pharaun