Created
July 14, 2010 21:32
-
-
Save c4milo/476119 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sys = require('sys'); | |
fs = require('fs'); | |
Inotify = require('node-inotify').Inotify; | |
//You can use `new Inotify(false)` for non persistent mode | |
var inotify = new Inotify(); //persistent by default | |
var callback = function(event) { | |
var mask = event.mask; | |
var type = mask & inotify.IN_ISDIR ? 'Directory ' : 'File '; | |
event.name ? type += ' ' + event.name + ' ': ' '; | |
if(mask & inotify.IN_ACCESS) { | |
sys.puts(type + 'was accessed '); | |
} else if(mask & inotify.IN_MODIFY) { | |
sys.puts(type + 'was modified '); | |
} else if(mask & inotify.IN_OPEN) { | |
sys.puts(type + 'was opened '); | |
} else if(mask & inotify.IN_CLOSE_NOWRITE) { | |
sys.puts(type + ' opened for reading was closed '); | |
} else if(mask & inotify.IN_CLOSE_WRITE) { | |
sys.puts(type + ' opened for writing was closed '); | |
} else if(mask & inotify.IN_MOVE) { | |
sys.puts(type + 'was moved '); | |
} else if(mask & inotify.IN_ATTRIB) { | |
sys.puts(type + 'metadata changed '); | |
} else if(mask & inotify.IN_CREATE) { | |
sys.puts(type + 'created'); | |
} else if(mask & inotify.IN_DELETE) { | |
sys.puts(type + 'deleted'); | |
} else if(mask & inotify.IN_DELETE_SELF) { | |
sys.puts(type + 'watched deleted '); | |
} else if(mask & inotify.IN_MOVE_SELF) { | |
sys.puts(type + 'watched moved'); | |
} else if(mask & inotify.IN_IGNORED) { | |
sys.puts(type + 'watch was removed'); | |
} | |
//sys.puts(sys.inspect(event)); | |
} | |
var home_dir = { path: '/home/camilo', | |
watch_for: inotify.IN_ALL_EVENTS, | |
callback: callback | |
}; | |
var home_watch_descriptor = inotify.addWatch(home_dir); | |
var home2_dir = { path: '/home/bob', | |
watch_for: inotify.IN_ALL_EVENTS, | |
callback: callback | |
}; | |
var home2_watch_descriptor = inotify.addWatch(home2_dir); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment