Skip to content

Commit

Permalink
Add isDir argument to relevant events.
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Jan 22, 2014
1 parent 52bfa18 commit ed7b091
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ Prerequisit is to have the `inotifywait` command in the current PATH. On debian/

### Events

* add (p1 = filename): received when a file or directory is added
* change (p1 = filename): received when a file is modified
* unlink (p1 = filename): received when a file or directory is deleted
* add (p1 = filename, isDir): received when a file or directory is added
* change (p1 = filename, isDir): received when a file is modified
* unlink (p1 = filename, isDir): received when a file or directory is deleted
* unknown (p1 = filename, p2 = full raw event object): received when unknown action is done on a file or directory

* ready (p1 = unix process object): received when inotifywait is ready to watch files or directories
Expand Down
6 changes: 3 additions & 3 deletions lib/inotifywait.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var INotifyWait = function(wpath, options) {
fs.lstat(event.file, function (err, stats) {
if (!err && !stats.isDirectory() && (stats.isSymbolicLink() || stats.nlink > 1)) {
// symlink and hard link does not receive any CLOSE event
self.emit('add', event.file);
self.emit('add', event.file, isDir);
delete self.currentEvents[event.file];
}
});
Expand All @@ -76,10 +76,10 @@ var INotifyWait = function(wpath, options) {
self.currentEvents[event.file] = 'change';
}
} else if (event.type.indexOf('DELETE') != -1) {
self.emit('unlink', event.file);
self.emit('unlink', event.file, isDir);
} else if (event.type.indexOf('CLOSE') != -1) {
if (self.currentEvents[event.file]) {
self.emit(self.currentEvents[event.file], event.file);
self.emit(self.currentEvents[event.file], event.file, isDir);
delete self.currentEvents[event.file];
} else {
self.emit('unknown', event.file, event);
Expand Down
27 changes: 22 additions & 5 deletions test/inotifywait.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ describe('inotifywait', function () {
it('should detect when a new file is added @2', function (done) {
var f = '';
var w = new INotifyWait(__dirname + '/data');
w.on('add', function (name) {
w.on('add', function (name, isDir) {
expect(name).to.eql(f);
expect(isDir).to.eql(false);
w.close();
done();
});
Expand All @@ -52,8 +53,9 @@ describe('inotifywait', function () {

it('should detect when a file is removed @4', function (done) {
var w = new INotifyWait(__dirname + '/data');
w.on('unlink', function (name) {
w.on('unlink', function (name, isDir) {
expect(name).to.eql(fakeFile);
expect(isDir).to.eql(false);
w.close();
done();
});
Expand All @@ -65,8 +67,9 @@ describe('inotifywait', function () {
it('should detect when a folder is created @5', function (done) {
var d = __dirname + '/data/lol';
var w = new INotifyWait(__dirname + '/data', { watchDirectory: true });
w.on('add', function (name) {
w.on('add', function (name, isDir) {
expect(name).to.eql(d);
expect(isDir).to.eql(true);
w.close();
done();
});
Expand Down Expand Up @@ -242,8 +245,22 @@ describe('inotifywait', function () {
});
});
});


it('should detect when a folder is removed @14', function (done) {
var d = __dirname + '/data/lol';
var w = new INotifyWait(__dirname + '/data', { watchDirectory: true });
w.on('unlink', function (name, isDir) {
expect(name).to.eql(d);
expect(isDir).to.eql(true);
w.close();
done();
});
w.on('ready', function () {
mkdirp.sync(d);
setTimeout(function () {
remove.removeSync(d);
}, 10);
});
})
});

after(function(){
Expand Down

0 comments on commit ed7b091

Please sign in to comment.