Skip to content

Commit

Permalink
Handle atomic writes when using fsevents
Browse files Browse the repository at this point in the history
Closes gh-161
  • Loading branch information
es128 committed Oct 19, 2014
1 parent 30a7d9e commit 95c6dfc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ FSWatcher.prototype._watchWithFsEvents = function(watchPath) {
if (event === 'add') {
this._addToWatchedDir(parent, item);
} else if (event === 'unlink') {
this._remove(parent, item);
// suppress unlink events on never before seen files (from atomic write)
if (info.type === 'directory' || watchedDir.indexOf(item) !== -1) {
this._remove(parent, item);
}
return; // Don't emit event twice.
}
var eventName = info.type === 'file' ? event : event + 'Dir';
Expand Down Expand Up @@ -276,7 +279,7 @@ FSWatcher.prototype._watchWithFsEvents = function(watchPath) {
return handleEvent('unlink');
case 'moved':
return fs.stat(path, function(error, stats) {
handleEvent(stats ? flags === 72960 ? 'change' : 'add' : 'unlink');
stats ? addOrChange() : handleEvent('unlink');
});
}
}.bind(this));
Expand Down

0 comments on commit 95c6dfc

Please sign in to comment.