Project

General

Profile

Watcher prototype » History » Revision 13

Revision 12 (Greg Burri, 08/07/2009 12:52 PM) → Revision 13/17 (Greg Burri, 08/07/2009 12:56 PM)

h1. Watcher prototype 

 The cache file structure store all the hashes of the shared files. If a file is added or removed from a shared directory (or a subfolder) it should be added or removed from the cache. 

 As far as I know there is no way to watch changes recursively of a folder tree with Qt. The Qt class _QFileSystemWatcher_ cannot watch recursively. 

 The only way to synchronize is to periodically scan all the shared data and compare to the cached one. It can be a bit CPU consumer so it should be done with a low priority thread and maybe with a pause between each file hashing. 

 h2. Native solution 

 A better solution would be to use native platform API. 

 h3. Linux : inotify 

 On Linux it exists a function called "inotify":http://linux.die.net/man/7/inotify 

 * The big issue is that inotify doesn't support the recursive watch of a directory. 
 * There is a limitation of the number of watcher, see @/proc/sys/fs/inotify/max_user_watches@, for example : 8192 under Debian. 
 * There is no problem to create thousands of watcher, it's very light. 

 h3. Windows : ReadDirectoryChangesW and WaitForMultiplesObjects 

 _ReadDirectoryChangesW_ can watch recursively and asynchronously any change from a given directory. See : http://msdn.microsoft.com/en-us/library/aa365465%28VS.85%29.aspx 

 Then, There is a thread can wait an event simplest way by calling _WaitForMultiplesObjects_, see using _FindFirstChangeNotification_ but it doesn't report any details of the change (name of the file, etc..). See : http://msdn.microsoft.com/en-us/library/aa365261%28VS.85%29.aspx