Skip to content

Commit

Permalink
Fixed polling
Browse files Browse the repository at this point in the history
Calling stats synchronously seemed to do the trick
Also fixed some formatting in watchEventSource.js because lint told me to
  • Loading branch information
ArjhanToteck committed Mar 16, 2024
1 parent fa835be commit 6072f3b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
45 changes: 26 additions & 19 deletions lib/DirectoryWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class DirectoryWatcher extends EventEmitter {
}
}
};
this.watcher.on("change", this.onWatchEvent.bind(this));
} else {
if (IS_OSX) {
this.watchInParentDirectory();
Expand Down Expand Up @@ -628,21 +627,34 @@ class DirectoryWatcher extends EventEmitter {
}
});
for (const itemPath of itemPaths) {
const handleStats = (err2, stats) => {
const handleStatsError = err2 => {
if (
err2.code === "ENOENT" ||
err2.code === "EPERM" ||
err2.code === "EACCES" ||
err2.code === "EBUSY"
) {
this.setMissing(itemPath, initial, "scan (" + err2.code + ")");
} else {
this.onScanError(err2);
}
itemFinished();
return;
};
fs.lstat(itemPath, (err2, stats) => {
if (this.closed) return;
if (err2) {
if (
err2.code === "ENOENT" ||
err2.code === "EPERM" ||
err2.code === "EACCES" ||
err2.code === "EBUSY"
) {
this.setMissing(itemPath, initial, "scan (" + err2.code + ")");
} else {
this.onScanError(err2);
handleStatsError(err2);
}
if (
stats.isSymbolicLink() &&
this.watcherManager.options.followSymlinks
) {
try {
stats = fs.statSync(itemPath);
} catch (err3) {
handleStatsError(err3);
}
itemFinished();
return;
}
if (stats.isFile() || stats.isSymbolicLink()) {
if (stats.mtime) {
Expand All @@ -665,12 +677,7 @@ class DirectoryWatcher extends EventEmitter {
);
}
itemFinished();
};
if (this.watcherManager.options.followSymlinks) {
fs.stat(itemPath, handleStats);
} else {
fs.lstat(itemPath, handleStats);
}
});
}
itemFinished();
});
Expand Down
4 changes: 3 additions & 1 deletion lib/watchEventSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ class RecursiveWatcher {
if (!filename) {
if (recursiveWatcherLogging) {
process.stderr.write(
`[watchpack] dispatch ${type} event in recursive watcher (${this.rootPath}) to all watchers\n`
`[watchpack] dispatch ${type} event in recursive watcher (${
this.rootPath
}) to all watchers\n`
);
}
for (const w of this.mapWatcherToPath.keys()) {
Expand Down

0 comments on commit 6072f3b

Please sign in to comment.