Skip to content

Commit

Permalink
Fix fast adding missing files issue #552
Browse files Browse the repository at this point in the history
  • Loading branch information
srguiwiz committed May 27, 2018
1 parent 28a70c4 commit e2b720c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions index.js
Expand Up @@ -273,13 +273,18 @@ FSWatcher.prototype._throttle = function(action, path, timeout) {
this._throttled[action] = Object.create(null);
}
var throttled = this._throttled[action];
if (path in throttled) return false;
if (path in throttled) {
throttled[path].count++;
return false;
}
function clear() {
var count = throttled[path] ? throttled[path].count : 0;
delete throttled[path];
clearTimeout(timeoutObject);
return count;
}
var timeoutObject = setTimeout(clear, timeout);
throttled[path] = {timeoutObject: timeoutObject, clear: clear};
throttled[path] = {timeoutObject: timeoutObject, clear: clear, count: 0};
return throttled[path];
};

Expand Down
5 changes: 4 additions & 1 deletion lib/nodefs-handler.js
Expand Up @@ -380,7 +380,7 @@ function(dir, stats, initialAdd, depth, target, wh, callback) {
this._addToNodeFs(path, initialAdd, wh, depth + 1);
}
}.bind(this)).on('end', function() {
if (throttler) throttler.clear();
var wasThrottled = throttler ? throttler.clear() : false;
if (done) done();

// Files that absent in current directory snapshot
Expand All @@ -398,6 +398,9 @@ function(dir, stats, initialAdd, depth, target, wh, callback) {
}).forEach(function(item) {
this._remove(directory, item);
}, this);

// one more time for any missed in case changes came in extremely quickly
if (wasThrottled) read(directory, false);
}.bind(this)).on('error', this._handleError.bind(this));
}.bind(this);

Expand Down

0 comments on commit e2b720c

Please sign in to comment.