From ae7bd2e5afedf75ede129221fcb41a12c73d0119 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Mon, 26 Sep 2016 19:49:52 -0400 Subject: [PATCH] Ignore meaningless initial fs.watchFile callback. As a reminder, we use fs.watchFile only as a fallback in environments where pathwatcher.watch is not available, such as on network or virtual file systems. --- tools/fs/safe-pathwatcher.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/fs/safe-pathwatcher.js b/tools/fs/safe-pathwatcher.js index 9bcd5ee0d4..3005229830 100644 --- a/tools/fs/safe-pathwatcher.js +++ b/tools/fs/safe-pathwatcher.js @@ -36,7 +36,7 @@ function acquireWatcher(absPath, callback) { } function startNewWatcher(absPath) { - let lastPathwatcherEventTime = 0; + let lastPathwatcherEventTime = +new Date; const callbacks = new Set; let latestHash = hashOrNull(absPath); let watcherCleanupTimer = null; @@ -72,7 +72,16 @@ function startNewWatcher(absPath) { : NO_PATHWATCHER_POLLING_INTERVAL; function watchFileWrapper(...args) { - const self = this; + const [newStat, oldStat] = args; + + if (newStat.ino === 0 && + oldStat.ino === 0 && + +newStat.mtime === +oldStat.mtime) { + // Node calls the watchFile listener once with bogus identical stat + // objects, which should not trigger a file change event. + return; + } + // If a pathwatcher event fired in the last polling interval, ignore // this event. if (new Date - lastPathwatcherEventTime > pollingInterval) {