-
Notifications
You must be signed in to change notification settings - Fork 39
/
example.js
67 lines (59 loc) · 2.17 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var http = require('http');
var Inotify = require('./inotify').Inotify;
var inotify = new Inotify(); //persistent by default, new Inotify(false) //no persistent
var data = {}; //used to correlate two events
var callback = function(event) {
var mask = event.mask;
var type = mask & Inotify.IN_ISDIR ? 'directory ' : 'file ';
if (event.name) {
type += ' ' + event.name + ' ';
} else {
type += ' ';
}
//the porpuse of this hell of 'if'
//statements is only illustrative.
if (mask & Inotify.IN_ACCESS) {
console.log(type + 'was accessed ');
} else if (mask & Inotify.IN_MODIFY) {
console.log(type + 'was modified ');
} else if (mask & Inotify.IN_OPEN) {
console.log(type + 'was opened ');
} else if (mask & Inotify.IN_CLOSE_NOWRITE) {
console.log(type + ' opened for reading was closed ');
} else if (mask & Inotify.IN_CLOSE_WRITE) {
console.log(type + ' opened for writing was closed ');
} else if (mask & Inotify.IN_ATTRIB) {
console.log(type + 'metadata changed ');
} else if (mask & Inotify.IN_CREATE) {
console.log(type + 'created');
} else if (mask & Inotify.IN_DELETE) {
console.log(type + 'deleted');
} else if (mask & Inotify.IN_DELETE_SELF) {
console.log(type + 'watched deleted ');
} else if (mask & Inotify.IN_MOVE_SELF) {
console.log(type + 'watched moved');
} else if (mask & Inotify.IN_IGNORED) {
console.log(type + 'watch was removed');
} else if (mask & Inotify.IN_MOVED_FROM) {
data = event;
data.type = type;
} else if (mask & Inotify.IN_MOVED_TO) {
if ( Object.keys(data).length &&
data.cookie === event.cookie) {
console.log(data.type + ' moved to ' + type);
data = {};
}
}
};
var dir = {
path: './',
watch_for: Inotify.IN_ALL_EVENTS,
callback: callback
};
var watch = inotify.addWatch(dir);
//inotify.removeWatch(watch);
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8124);
console.log('Http server started in 8124');