@@ -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,34 @@ class DirectoryWatcher extends EventEmitter {
627627 }
628628 } ) ;
629629 for ( const itemPath of itemPaths ) {
630- const handleStats = ( err2 , stats ) => {
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+ } ;
644+ fs . lstat ( itemPath , ( 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+ if (
650+ stats . isSymbolicLink ( ) &&
651+ this . watcherManager . options . followSymlinks
652+ ) {
653+ try {
654+ stats = fs . statSync ( itemPath ) ;
655+ } catch ( err3 ) {
656+ handleStatsError ( err3 ) ;
642657 }
643- itemFinished ( ) ;
644- return ;
645658 }
646659 if ( stats . isFile ( ) || stats . isSymbolicLink ( ) ) {
647660 if ( stats . mtime ) {
@@ -664,12 +677,7 @@ class DirectoryWatcher extends EventEmitter {
664677 ) ;
665678 }
666679 itemFinished ( ) ;
667- } ;
668- if ( this . watcherManager . options . followSymlinks ) {
669- fs . stat ( itemPath , handleStats ) ;
670- } else {
671- fs . lstat ( itemPath , handleStats ) ;
672- }
680+ } ) ;
673681 }
674682 itemFinished ( ) ;
675683 } ) ;
0 commit comments