Skip to content

Instantly share code, notes, and snippets.

@fastman
Created August 22, 2012 12:02
Show Gist options
  • Save fastman/3424886 to your computer and use it in GitHub Desktop.
Save fastman/3424886 to your computer and use it in GitHub Desktop.
node inotify
developer@clouddev:~/dev/tests$ cat watch.js
var fs = require('fs');
var data = 'sample data';
var file = '/tmp/watch_test_file';
fs.writeFileSync(file, data);
fs.watchFile(file, function (curr, prev) {
console.log('File changed');
});
fs.writeFile(file, data, function (err) {
if (err) {
console.log('error writing file');
} else {
console.log('file saved');
}
});
developer@clouddev:~/dev/tests$ node watch.js
File changed
File changed
file saved
----
libuv/src/unix/linux/inotify.c:
146 if (e->mask & (UV__IN_ATTRIB|UV__IN_MODIFY))
147 events |= UV_CHANGE;
148 if (e->mask & ~(UV__IN_ATTRIB|UV__IN_MODIFY))
149 events |= UV_RENAME;
libuv/src/unix/linux/syscalls.h:
60 #define UV__IN_MODIFY 0x002
linux/inotify.h
#define IN_MODIFY 0x00000002 /* File was modified */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment