Skip to content

Commit

Permalink
ajust mtime later, to get more accurate fs accurency
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Feb 9, 2016
1 parent b0482e9 commit 2ad1e7d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/DirectoryWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ DirectoryWatcher.prototype.setFileTime = function setFileTime(filePath, mtime, i
var now = Date.now();
var old = this.files[filePath];

this.files[filePath] = [initial ? Math.min(now, mtime) : now, mtime];

// we add the fs accurency to reach the maximum possible mtime
mtime = mtime + FS_ACCURENCY;

this.files[filePath] = [initial ? Math.min(now, mtime) : now, mtime];
if(!old) {
if(mtime) {
if(this.watchers[withoutCase(filePath)]) {
Expand Down Expand Up @@ -199,8 +200,9 @@ DirectoryWatcher.prototype.watch = function watch(filePath, startTime) {
}
process.nextTick(function() {
if(data) {
if(data[0] > startTime)
watcher.emit("change", data[1]);
var ts = data[0] === data[1] ? data[0] + FS_ACCURENCY : data[0];
if(ts > startTime)
watcher.emit("change", data[1] + FS_ACCURENCY);
} else if(this.initialScan && this.initialScanRemoved.indexOf(filePath) >= 0) {
watcher.emit("remove");
}
Expand Down Expand Up @@ -295,7 +297,7 @@ DirectoryWatcher.prototype.getTimes = function() {
Object.keys(this.files).forEach(function(file) {
var data = this.files[file];
if(data[1]) {
var time = Math.max(data[0], data[1]);
var time = Math.max(data[0], data[1] + FS_ACCURENCY);
obj[file] = time;
if(time > selfTime)
selfTime = time;
Expand Down

0 comments on commit 2ad1e7d

Please sign in to comment.