diff --git a/lib/nodefs-handler.js b/lib/nodefs-handler.js index 52fda9fe..2a116ee2 100644 --- a/lib/nodefs-handler.js +++ b/lib/nodefs-handler.js @@ -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 @@ -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); } } @@ -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); } }