Skip to content

Commit

Permalink
Watch symlink stats async
Browse files Browse the repository at this point in the history
  • Loading branch information
ArjhanToteck committed Mar 18, 2024
1 parent 8aafd4a commit 696a67a
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions lib/DirectoryWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,22 +641,7 @@ class DirectoryWatcher extends EventEmitter {
itemFinished();
return;
};
const handleStats = (err2, stats) => {
if (this.closed) return;
if (err2) {
handleStatsError(err2);
}
let symlinkStats;
if (
stats.isSymbolicLink() &&
this.watcherManager.options.followSymlinks
) {
try {
symlinkStats = fs.statSync(itemPath);
} catch (err3) {
handleStatsError(err3);
}
}
const handleStats = (stats, symlinkStats) => {
if (stats.isFile() || stats.isSymbolicLink()) {
if (stats.mtime) {
ensureFsAccuracy(stats.mtime);
Expand All @@ -683,7 +668,28 @@ class DirectoryWatcher extends EventEmitter {
}
itemFinished();
};
fs.lstat(itemPath, handleStats);
fs.lstat(itemPath, (err2, stats) => {
if (this.closed) return;
if (err2) {
handleStatsError(err2);
return;
}
if (
stats.isSymbolicLink() &&
this.watcherManager.options.followSymlinks
) {
fs.stat(itemPath, (err3, symlinkStats) => {
if (this.closed) return;
if (err3) {
handleStatsError(err3);
return;
}
handleStats(stats, symlinkStats);
});
} else {
handleStats(stats);
}
});
}
itemFinished();
});
Expand Down

0 comments on commit 696a67a

Please sign in to comment.