Skip to content

Commit 696a67a

Browse files
committed
Watch symlink stats async
1 parent 8aafd4a commit 696a67a

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

lib/DirectoryWatcher.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -641,22 +641,7 @@ class DirectoryWatcher extends EventEmitter {
641641
itemFinished();
642642
return;
643643
};
644-
const handleStats = (err2, stats) => {
645-
if (this.closed) return;
646-
if (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);
658-
}
659-
}
644+
const handleStats = (stats, symlinkStats) => {
660645
if (stats.isFile() || stats.isSymbolicLink()) {
661646
if (stats.mtime) {
662647
ensureFsAccuracy(stats.mtime);
@@ -683,7 +668,28 @@ class DirectoryWatcher extends EventEmitter {
683668
}
684669
itemFinished();
685670
};
686-
fs.lstat(itemPath, handleStats);
671+
fs.lstat(itemPath, (err2, stats) => {
672+
if (this.closed) return;
673+
if (err2) {
674+
handleStatsError(err2);
675+
return;
676+
}
677+
if (
678+
stats.isSymbolicLink() &&
679+
this.watcherManager.options.followSymlinks
680+
) {
681+
fs.stat(itemPath, (err3, symlinkStats) => {
682+
if (this.closed) return;
683+
if (err3) {
684+
handleStatsError(err3);
685+
return;
686+
}
687+
handleStats(stats, symlinkStats);
688+
});
689+
} else {
690+
handleStats(stats);
691+
}
692+
});
687693
}
688694
itemFinished();
689695
});

0 commit comments

Comments
 (0)