Which mechanism does Dropbox use to monitor the folders? I am interested in the mechanism supported by a programming language, by operating systems or some file system functionalities.
Asked
Active
Viewed 433 times
4
-
1Perfectly valid question if a bit rephrased. Don't know who and why marked it as offtopic. – Eugene Mayevski 'Callback Aug 18 '13 at 06:50
-
1On Windows the best way (and it's used by many tools) is to employ a filesystem filter driver - this is a reliable and precise mechanism unlike FindFirstChangeNotification and its derivatives (FileSystemWatcher etc). The only drawback is writing a driver yourself is time-consuming and complicated task. Use of the pre-created driver solves this problem. – Eugene Mayevski 'Callback Aug 18 '13 at 06:51
1 Answers
2
There are a number of options you may want to consider:
- Java has a WatchService
- .NET has a FileSystemWatcher
- Flavors of Linux can use inotify
- Windows native has FindFirstChangeNotification
- You can implement a custom file system using FUSE
- OP also pointed to Apache Commons IO's solution for Java.
Some info used from this SO question.
-
Thank you, that is a nice overview. I am currently testing some monitoring functionalities with Java, but I am worried about some [usability problems](http://stackoverflow.com/questions/6255463/java7-watchservice-access-denied-error-trying-to-delete-recursively-watched-ne). – Tom Maier Aug 17 '13 at 21:49
-
1That's the risk of using something like Java since it's basically going to wrap what the native OS provides. But I think that's also a windows idiom - it's like having a text file open and then deleting the folder containing that file - usually windows complains. – NG. Aug 17 '13 at 21:53
-
Yes, unfortunately it's just a simple file lock. What do you think about the [Apache Commons IO features for recursive file monitoring](http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/monitor/package-summary.html)? – Tom Maier Aug 17 '13 at 22:01
-
1I had never seen that before, but it looks interesting. Thanks for the info! Will add to the answer. I did a quick skim of the source - it seems that its basically a nice little wrapper around polling the file system for changes. – NG. Aug 17 '13 at 22:16
-
1I just tested the API. The key benefit is that it doesn't need an open file handle all the time. – Tom Maier Aug 17 '13 at 22:21
-
That's pretty cool - what interval did you use for your monitor (or what frequency were you calling checkAndNotify)? I guess the con would be that you may not get instant changes, but a slight delay is probably acceptable – NG. Aug 17 '13 at 22:23
-
For test purposes I tried an interval of 250 ms. I have seen that the API implements a file tree walker which compares the old and new state and I don't know whether 250 ms are a to short interval. – Tom Maier Aug 17 '13 at 22:34