@@ -177,57 +177,47 @@ FS.staticInit();
177177
178178      var  defaults  =  { 
179179        follow_mount : true , 
180-         recurse_count : 0 
181180      } ; 
182181      opts  =  Object . assign ( defaults ,  opts ) 
183182
184-       if  ( opts . recurse_count  >  8 )  {   // max recursive lookup of 8 
185-         throw  new  FS . ErrnoError ( { { {  cDefs. ELOOP  } } } ) ; 
186-       } 
187- 
188-       // split the absolute path 
189-       var  parts  =  path . split ( '/' ) . filter ( ( p )  =>  ! ! p ) ; 
183+       // limit max consecutive symlinks to 40 (SYMLOOP_MAX). 
184+       linkloop : for  ( var  nlinks  =  0 ;  nlinks  <  40 ;  nlinks  ++ )  { 
185+         // split the absolute path 
186+         var  parts =  path . split ( '/' ) . filter ( ( p )  =>  ! ! p ) ; 
190187
191-       // start at the root 
192-       var  current  =  FS . root ; 
193-       var  current_path  =  '/' ; 
188+          // start at the root 
189+          var  current  =  FS . root ; 
190+          var  current_path  =  '/' ; 
194191
195-       for  ( var  i  =  0 ;  i  <  parts . length ;  i ++ )  { 
196-         var  islast  =  ( i  ===  parts . length - 1 ) ; 
197-         if  ( islast  &&  opts . parent )  { 
198-           // stop resolving 
199-           break; 
200-         } 
192+          for  ( var  i  =  0 ;  i  <  parts . length ;  i ++ )  { 
193+            var  islast =  ( i  ===  parts . length - 1 ) ; 
194+            if  ( islast  &&  opts . parent )  { 
195+              // stop resolving 
196+              break; 
197+            } 
201198
202-         current  =  FS . lookupNode ( current ,  parts [ i ] ) ; 
203-         current_path  =  PATH . join2 ( current_path ,  parts [ i ] ) ; 
199+            current  =  FS . lookupNode ( current ,  parts [ i ] ) ; 
200+            current_path  =  PATH . join2 ( current_path ,  parts [ i ] ) ; 
204201
205-         // jump to the mount's root node if this is a mountpoint 
206-         if  ( FS . isMountpoint ( current ) )  { 
207-           if  ( ! islast  ||  ( islast  &&  opts . follow_mount ) )  { 
202+           // jump to the mount's root node if this is a mountpoint 
203+           if  ( FS . isMountpoint ( current )  &&  ( ! islast  ||  opts . follow_mount ) )  { 
208204            current =  current . mounted . root ; 
209205          } 
210-         } 
211- 
212-         // by default, lookupPath will not follow a symlink if it is the final path component. 
213-         // setting opts.follow = true will override this behavior. 
214-         if  ( ! islast  ||  opts . follow )  { 
215-           var  count  =  0 ; 
216-           while  ( FS . isLink ( current . mode ) )  { 
217-             var  link  =  FS . readlink ( current_path ) ; 
218-             current_path  =  PATH_FS . resolve ( PATH . dirname ( current_path ) ,  link ) ; 
219206
220-              var   lookup   =   FS . lookupPath ( current_path ,   {   recurse_count :  opts . recurse_count   +   1   } ) ; 
221-              current  =  lookup . node ; 
222- 
223-             if  ( count ++   >   40 )  {    // limit max consecutive symlinks to 40 (SYMLOOP_MAX). 
224-               throw  new  FS . ErrnoError ( { { {  cDefs. ELOOP  } } } ) ; 
207+           // by default, lookupPath will not follow a symlink if it is the final path component. 
208+           // setting opts.follow  = true will override this behavior. 
209+            if   ( FS . isLink ( current . mode )   &&   ( ! islast   ||   opts . follow ) )   { 
210+             if  ( ! current . node_ops . readlink )  { 
211+               throw  new  FS . ErrnoError ( { { {  cDefs . ENOSYS  } } } ) ; 
225212            } 
213+             var  link  =  current . node_ops . readlink ( current ) ; 
214+             path  =  PATH_FS . resolve ( PATH . dirname ( current_path ) ,  link ,  ...parts . slice ( i  +  1 ) ) ; 
215+             continue  linkloop ; 
226216          } 
227217        } 
218+         return  {  path : current_path ,  node : current  } ; 
228219      } 
229- 
230-       return  {  path : current_path ,  node : current  } ; 
220+       throw  new  FS . ErrnoError ( { { {  cDefs. ELOOP  } } } ) ; 
231221    } , 
232222    getPath ( node )  { 
233223      var  path ; 
0 commit comments