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();
1021
1021
mode = 0 ;
1022
1022
}
1023
1023
var node ;
1024
+ var isBrokenLink ;
1024
1025
if ( typeof path = = 'object' ) {
1025
1026
node = path ;
1026
1027
} else {
1027
1028
path = PATH . normalize ( path ) ;
1028
1029
try {
1029
- var lookup = FS . lookupPath ( path , {
1030
- follow : ! ( flags & { { { cDefs . O_NOFOLLOW } } } )
1031
- } ) ;
1030
+ var lookup = FS . lookupPath ( path ) ;
1032
1031
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
+ }
1033
1036
} 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 ;
1035
1042
}
1036
1043
}
1037
1044
// perhaps we need to create the node
@@ -1044,6 +1051,10 @@ FS.staticInit();
1044
1051
}
1045
1052
} else {
1046
1053
// 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
+ }
1047
1058
node = FS . mknod ( path , mode , 0 ) ;
1048
1059
created = true ;
1049
1060
}
You can’t perform that action at this time.
0 commit comments