dinotify

A tiny library to work with Linux's kernel inotify subsystem.

Members

Functions

iNotify
auto iNotify()

Create new INotify struct

iNotifyTree
auto iNotifyTree(string path, uint mask)

Structs

Event
struct Event

D-ified inotify event, holds slice to temporary buffer with z-string.

INotify
struct INotify
INotifyTree
struct INotifyTree

Track events in the whole directory tree, automatically adding watches to any new sub-directories and stopping watches in the deleted ones.

TreeEvent
struct TreeEvent

Event as returned by INotifyTree. In constrast to Event, it has full path and no watch descriptor.

Watch
struct Watch

Type-safe watch descriptor to help discern it from normal file descriptors

Examples

1 import std.process, std.stdio : writeln, writefln;
2 
3 auto monitor = iNotify();
4 executeShell("rm -rf tmp");
5 executeShell("mkdir tmp");
6 // literals are zero-terminated
7 monitor.add("tmp".ptr, IN_CREATE | IN_DELETE);
8 ubyte[] data = [1, 2, 3, 4];
9 executeShell("touch tmp/killme");
10 auto events = monitor.read();
11 assert(events[0].mask == IN_CREATE);
12 assert(events[0].name == "killme");
13 
14 executeShell("rm -rf tmp/killme");
15 events = monitor.read();
16 assert(events[0].mask == IN_DELETE);
17 
18 // Note: watched directory doesn't track events in sub-directories
19 executeShell("mkdir tmp/some-dir");
20 executeShell("touch tmp/some-dir/victim");
21 events = monitor.read();
22 assert(events.length == 1);
23 assert(events[0].mask == (IN_ISDIR | IN_CREATE));
24 assert(events[0].name == "some-dir");

Meta