Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent change on add in node watcher #86

Merged
merged 2 commits into from
Feb 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/node_watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,12 @@ NodeWatcher.prototype.processChange = function(dir, event, file) {

NodeWatcher.prototype.emitEvent = function(type, file, stat) {
var key = type + '-' + file;
var addKey = ADD_EVENT + '-' + file;
if (type === CHANGE_EVENT && this.changeTimers[addKey]) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just return from here. And add a comment to say something like:

// Ignore the change event that is immediately fired after an add event.
// (This happens on Linux).

// Ignore the change event that is immediately fired after an add event.
// (This happens on Linux).
return;
}
clearTimeout(this.changeTimers[key]);
this.changeTimers[key] = setTimeout(function() {
delete this.changeTimers[key];
Expand Down
3 changes: 3 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ function harness(mode) {
assert.equal(dir, testdir);
done();
});
this.watcher.on('change', function(filepath, dir, stat) {
done(new Error('Should not emit change on add'))
})
this.watcher.on('ready', function() {
fs.writeFileSync(testfile, 'wow');
});
Expand Down