Project

General

Profile

Watcher prototype » History » Version 16

Greg Burri, 09/10/2009 01:39 PM

1 1 Greg Burri
h1. Watcher prototype
2
3 2 Greg Burri
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.
4
5 9 Greg Burri
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.
6 2 Greg Burri
7
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.
8 3 Greg Burri
9 1 Greg Burri
h2. Native solution
10 9 Greg Burri
11
A better solution would be to use native platform API.
12 1 Greg Burri
13 8 Greg Burri
h3. Linux : inotify
14 1 Greg Burri
15 8 Greg Burri
On Linux it exists a function called "inotify":http://linux.die.net/man/7/inotify
16
17 10 Greg Burri
* The big issue is that inotify doesn't support the recursive watch of a directory.
18
* There is a limitation of the number of watcher, see @/proc/sys/fs/inotify/max_user_watches@, for example : 8192 under Debian.
19 11 Greg Burri
* There is no problem to create thousands of watcher, it's very light.
20 5 Greg Burri
21 16 Greg Burri
/!\ inotify is replaced by fsnotify in the kernel 2.6.31, see : http://lwn.net/Articles/339399/
22
 
23
24 13 Greg Burri
h3. Windows : ReadDirectoryChangesW and WaitForMultiplesObjects
25 1 Greg Burri
26 13 Greg Burri
_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
27 12 Greg Burri
28 13 Greg Burri
Then, a thread can wait an event by calling _WaitForMultiplesObjects_, see : http://msdn.microsoft.com/en-us/library/aa365261%28VS.85%29.aspx
29 14 Greg Burri
30 15 Greg Burri
h4. Events when copying :
31 14 Greg Burri
32
Beginning of the copy :
33
<pre>
34
waitEvent
35
Action =  1 (FILE_ACTION_ADDED)
36
filename =  "ACDC - Back In Black.mpg"
37
38
waitEvent
39
Action =  3 (FILE_ACTION_MODIFIED)
40
filename =  "ACDC - Back In Black.mpg"
41
</pre>
42
43
End of the copy :
44
<pre>
45
waitEvent
46
Action =  3 (FILE_ACTION_MODIFIED)
47
filename =  "ACDC - Back In Black.mpg"
48
<pre>