Skip to content

Commit

Permalink
handle simultaneous change of LastAccessTime and ModifiedTime (#793)
Browse files Browse the repository at this point in the history
  • Loading branch information
markablov authored and paulmillr committed Feb 9, 2019
1 parent c7cf6e9 commit c5f9718
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/nodefs-handler.js
Expand Up @@ -11,6 +11,11 @@ var isBinaryPath = require('is-binary-path');
// (may be shared across chokidar FSWatcher instances)
var FsWatchInstances = Object.create(null);

// atime and mtime are changing simultaneously by OS
// so we need threshold (in ms) to understand when file is changed
// or when only atime is updated (which we want to ignore)
var accessTimeDelayThreshold = 1000;

// Private function: Instantiates the fs.watch interface

// * path - string, path to be watched
Expand Down Expand Up @@ -266,7 +271,8 @@ function(file, stats, initialAdd, callback) {
} else {
// Check that change event was not fired because of changed accessTime.
var at = newStats.atime.getTime();
if (!at || at <= newStats.mtime.getTime()) {
var mt = newStats.mtime.getTime();
if (!at || at <= mt || (at - mt) <= accessTimeDelayThreshold) {
this._emit('change', file, newStats);
}
}
Expand All @@ -275,7 +281,8 @@ function(file, stats, initialAdd, callback) {
} else if (parent.has(basename)) {
// Check that change event was not fired because of changed accessTime.
var at = newStats.atime.getTime();
if (!at || at <= newStats.mtime.getTime()) {
var mt = newStats.mtime.getTime();
if (!at || at <= mt || (at - mt) <= accessTimeDelayThreshold) {
this._emit('change', file, newStats);
}
}
Expand Down

0 comments on commit c5f9718

Please sign in to comment.