File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -1021,17 +1021,24 @@ FS.staticInit();
10211021        mode =  0 ; 
10221022      } 
10231023      var  node ; 
1024+       var  isBrokenLink ; 
10241025      if  ( typeof  path  = =  'object' )  { 
10251026        node =  path ; 
10261027      }  else  { 
10271028        path  =  PATH . normalize ( path ) ; 
10281029        try  { 
1029-           var  lookup =  FS . lookupPath ( path ,  { 
1030-             follow : ! ( flags  &  { { {  cDefs . O_NOFOLLOW  } } } ) 
1031-           } ) ; 
1030+           var  lookup  =  FS . lookupPath ( path ) ; 
10321031          node  =  lookup . node ; 
1032+           if  ( ( ! ( flags  &  { { {  cDefs . O_NOFOLLOW  } } } ) )  &&  node  &&  FS . isLink ( node . mode ) )  { 
1033+             var  lookup =  FS . lookupPath ( path ,  { follow : true } ) ; 
1034+             node  =  lookup . node ; 
1035+           } 
10331036        }  catch  ( e )  { 
1034-           // ignore 
1037+           // If node is defined but we raised an error, it's because the first 
1038+           // lookup succeeded but the lookup with follow raised ENOENT. Thus, we 
1039+           // have a broken symlink. 
1040+           isBrokenLink =  ! ! node ; 
1041+           node  =  undefined ; 
10351042        } 
10361043      } 
10371044      // perhaps we need to create the node 
@@ -1044,6 +1051,10 @@ FS.staticInit();
10441051          } 
10451052        }  else  { 
10461053          // node doesn't exist, try to create it 
1054+           if  ( isBrokenLink )  { 
1055+             // If there's a broken link we have to remove it first 
1056+             FS . unlink ( path) ; 
1057+           } 
10471058          node =  FS . mknod ( path ,  mode ,  0 ) ; 
10481059          created  =  true ; 
10491060        } 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments