Skip to content

Commit 8aafd4a

Browse files
committed
Fixed polling
1 parent c54bf67 commit 8aafd4a

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

lib/DirectoryWatcher.js

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ class DirectoryWatcher extends EventEmitter {
111111
this.watchInParentDirectory();
112112
}
113113
this.watcher = watchEventSource.watch(this.path);
114-
this.watcher.on("change", this.onWatchEvent.bind(this));
115114
this.watcher.on("error", this.onWatcherError.bind(this));
115+
this.watcher.on("change", this.onWatchEvent.bind(this));
116116
}
117117
} catch (err) {
118118
this.onWatcherError(err);
@@ -627,21 +627,35 @@ class DirectoryWatcher extends EventEmitter {
627627
}
628628
});
629629
for (const itemPath of itemPaths) {
630+
const handleStatsError = err2 => {
631+
if (
632+
err2.code === "ENOENT" ||
633+
err2.code === "EPERM" ||
634+
err2.code === "EACCES" ||
635+
err2.code === "EBUSY"
636+
) {
637+
this.setMissing(itemPath, initial, "scan (" + err2.code + ")");
638+
} else {
639+
this.onScanError(err2);
640+
}
641+
itemFinished();
642+
return;
643+
};
630644
const handleStats = (err2, stats) => {
631645
if (this.closed) return;
632646
if (err2) {
633-
if (
634-
err2.code === "ENOENT" ||
635-
err2.code === "EPERM" ||
636-
err2.code === "EACCES" ||
637-
err2.code === "EBUSY"
638-
) {
639-
this.setMissing(itemPath, initial, "scan (" + err2.code + ")");
640-
} else {
641-
this.onScanError(err2);
647+
handleStatsError(err2);
648+
}
649+
let symlinkStats;
650+
if (
651+
stats.isSymbolicLink() &&
652+
this.watcherManager.options.followSymlinks
653+
) {
654+
try {
655+
symlinkStats = fs.statSync(itemPath);
656+
} catch (err3) {
657+
handleStatsError(err3);
642658
}
643-
itemFinished();
644-
return;
645659
}
646660
if (stats.isFile() || stats.isSymbolicLink()) {
647661
if (stats.mtime) {
@@ -654,7 +668,11 @@ class DirectoryWatcher extends EventEmitter {
654668
true,
655669
"scan (file)"
656670
);
657-
} else if (stats.isDirectory()) {
671+
}
672+
if (
673+
stats.isDirectory() ||
674+
(symlinkStats && symlinkStats.isDirectory())
675+
) {
658676
if (!initial || !this.directories.has(itemPath))
659677
this.setDirectory(
660678
itemPath,
@@ -665,11 +683,7 @@ class DirectoryWatcher extends EventEmitter {
665683
}
666684
itemFinished();
667685
};
668-
if (this.watcherManager.options.followSymlinks) {
669-
fs.stat(itemPath, handleStats);
670-
} else {
671-
fs.lstat(itemPath, handleStats);
672-
}
686+
fs.lstat(itemPath, handleStats);
673687
}
674688
itemFinished();
675689
});

0 commit comments

Comments
 (0)