diff --git a/lib/DirectoryWatcher.js b/lib/DirectoryWatcher.js index 091f198..0868dbd 100644 --- a/lib/DirectoryWatcher.js +++ b/lib/DirectoryWatcher.js @@ -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); @@ -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(); });