Watcher prototype » History » Revision 16
« Previous |
Revision 16/17
(diff)
| Next »
Greg Burri, 09/10/2009 01:39 PM
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.
Native solution¶
A better solution would be to use native platform API.
Linux : inotify¶
On Linux it exists a function called 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.
/!\ inotify is replaced by fsnotify in the kernel 2.6.31, see : http://lwn.net/Articles/339399/
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, a thread can wait an event by calling WaitForMultiplesObjects, see : http://msdn.microsoft.com/en-us/library/aa365261%28VS.85%29.aspx
Events when copying :¶
Beginning of the copy :
waitEvent Action = 1 (FILE_ACTION_ADDED) filename = "ACDC - Back In Black.mpg" waitEvent Action = 3 (FILE_ACTION_MODIFIED) filename = "ACDC - Back In Black.mpg"
End of the copy :
waitEvent Action = 3 (FILE_ACTION_MODIFIED) filename = "ACDC - Back In Black.mpg" <pre>
Updated by Greg Burri over 15 years ago · 16 revisions