Skip to content

Commit

Permalink
Fixed polling
Browse files Browse the repository at this point in the history
  • Loading branch information
ArjhanToteck committed Mar 17, 2024
1 parent c54bf67 commit 8aafd4a
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions lib/DirectoryWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class DirectoryWatcher extends EventEmitter {
this.watchInParentDirectory();
}
this.watcher = watchEventSource.watch(this.path);
this.watcher.on("change", this.onWatchEvent.bind(this));
this.watcher.on("error", this.onWatcherError.bind(this));
this.watcher.on("change", this.onWatchEvent.bind(this));
}
} catch (err) {
this.onWatcherError(err);
Expand Down Expand Up @@ -627,21 +627,35 @@ class DirectoryWatcher extends EventEmitter {
}
});
for (const itemPath of itemPaths) {
const handleStatsError = err2 => {
if (
err2.code === "ENOENT" ||
err2.code === "EPERM" ||
err2.code === "EACCES" ||
err2.code === "EBUSY"
) {
this.setMissing(itemPath, initial, "scan (" + err2.code + ")");

Check warning on line 637 in lib/DirectoryWatcher.js

View check run for this annotation

Codecov / codecov/patch

lib/DirectoryWatcher.js#L637

Added line #L637 was not covered by tests
} else {
this.onScanError(err2);
}
itemFinished();
return;
};
const handleStats = (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);

Check warning on line 647 in lib/DirectoryWatcher.js

View check run for this annotation

Codecov / codecov/patch

lib/DirectoryWatcher.js#L647

Added line #L647 was not covered by tests
}
let symlinkStats;
if (
stats.isSymbolicLink() &&
this.watcherManager.options.followSymlinks
) {
try {
symlinkStats = fs.statSync(itemPath);
} catch (err3) {
handleStatsError(err3);
}
itemFinished();
return;
}
if (stats.isFile() || stats.isSymbolicLink()) {
if (stats.mtime) {
Expand All @@ -654,7 +668,11 @@ class DirectoryWatcher extends EventEmitter {
true,
"scan (file)"
);
} else if (stats.isDirectory()) {
}
if (
stats.isDirectory() ||
(symlinkStats && symlinkStats.isDirectory())
) {
if (!initial || !this.directories.has(itemPath))
this.setDirectory(
itemPath,
Expand All @@ -665,11 +683,7 @@ class DirectoryWatcher extends EventEmitter {
}
itemFinished();
};
if (this.watcherManager.options.followSymlinks) {
fs.stat(itemPath, handleStats);
} else {
fs.lstat(itemPath, handleStats);
}
fs.lstat(itemPath, handleStats);
}
itemFinished();
});
Expand Down

0 comments on commit 8aafd4a

Please sign in to comment.