Created
March 13, 2012 18:57
-
-
Save nicokruger/2030769 to your computer and use it in GitHub Desktop.
inotify-test.js
This file contains hidden or 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
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 '; | |
event.name ? type += ' ' + event.name + ' ': ' '; | |
//the porpuse of this hell of 'if' | |
//statements is only illustrative. | |
console.log(JSON.stringify(event)); | |
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) { | |
console.log(type + 'moved from'); | |
} else if(mask & Inotify.IN_MOVED_TO) { | |
console.log(type + "moved to"); | |
} | |
}; | |
var home2_dir = { path: __dirname + '/incoming', // <--- change this for a valid directory in your machine | |
watch_for: Inotify.IN_ALL_EVENTS, | |
// Inotify.IN_CREATE | Inotify.CLOSE_WRITE | |
callback: callback | |
}; | |
var home2_wd = inotify.addWatch(home2_dir); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment