iNotifyTree

iNotifyTree
(
string path
,
uint mask
)

Examples

1 import std.process;
2 import core.thread;
3 
4 executeShell("rm -rf tmp");
5 executeShell("mkdir -p tmp/dir1/dir11");
6 executeShell("mkdir -p tmp/dir1/dir12");
7 auto ntree = iNotifyTree("tmp/dir1", IN_CREATE | IN_DELETE);
8 executeShell("touch tmp/dir1/dir11/a.tmp");
9 executeShell("touch tmp/dir1/dir12/b.tmp");
10 executeShell("rm -rf tmp/dir1/dir12");
11 auto evs = ntree.read();
12 assert(evs.length == 4);
13 // a & b files created
14 assert(evs[0].mask == IN_CREATE && evs[0].path == "tmp/dir1/dir11/a.tmp");
15 assert(evs[1].mask == IN_CREATE && evs[1].path == "tmp/dir1/dir12/b.tmp");
16 // b deleted as part of sub-tree
17 assert(evs[2].mask == IN_DELETE && evs[2].path == "tmp/dir1/dir12/b.tmp");
18 assert(evs[3].mask == (IN_DELETE | IN_ISDIR) && evs[3].path == "tmp/dir1/dir12");
19 evs = ntree.read(10.msecs);
20 assert(evs.length == 0);
21 auto t = new Thread((){
22     Thread.sleep(1000.msecs);
23     executeShell("touch tmp/dir1/dir11/c.tmp");
24 }).start();
25 evs = ntree.read(10.msecs);
26 t.join();
27 assert(evs.length == 0);
28 evs = ntree.read(10.msecs);
29 assert(evs.length == 1);

Meta