@@ -52,7 +52,7 @@ FS.staticInit();
52
52
streams : [ ] ,
53
53
nextInode : 1 ,
54
54
nameTable : null ,
55
- currentPath : '/' ,
55
+ currentPath : null ,
56
56
initialized : false ,
57
57
// Whether we are currently ignoring permissions. Useful when preparing the
58
58
// filesystem and creating files inside read-only folders.
@@ -173,21 +173,22 @@ FS.staticInit();
173
173
//
174
174
lookupPath ( path , opts = { } ) {
175
175
if ( ! path ) return { path : '' , node : null } ;
176
- opts . follow_mount ??= true
176
+ opts . follow_mount ??= true ;
177
177
178
- if ( ! PATH . isAbs ( path ) ) {
179
- path = FS . cwd ( ) + '/' + path ;
178
+ var current ;
179
+ var current_path ;
180
+ if ( PATH . isAbs ( path ) ) {
181
+ current = FS . root ;
182
+ current_path = "/" ;
183
+ } else {
184
+ current = FS . currentNode ;
185
+ current_path = FS . currentPath ;
180
186
}
187
+ var pathParts = ( x ) => x . split ( '/' ) . filter ( ( p ) => ! ! p && ( p !== '.' ) ) ;
188
+ var parts = pathParts ( path ) ;
181
189
182
190
// limit max consecutive symlinks to 40 (SYMLOOP_MAX).
183
191
linkloop : for ( var nlinks = 0 ; nlinks < 40 ; nlinks ++ ) {
184
- // split the absolute path
185
- var parts = path . split ( '/' ) . filter ( ( p ) => ! ! p && ( p !== '.' ) ) ;
186
-
187
- // start at the root
188
- var current = FS . root ;
189
- var current_path = '/' ;
190
-
191
192
for ( var i = 0 ; i < parts . length ; i ++ ) {
192
193
var islast = ( i === parts . length - 1 ) ;
193
194
if ( islast && opts . parent ) {
@@ -226,10 +227,14 @@ FS.staticInit();
226
227
throw new FS . ErrnoError ( { { { cDefs . ENOSYS } } } ) ;
227
228
}
228
229
var link = current . node_ops . readlink ( current ) ;
229
- if ( ! PATH . isAbs ( link ) ) {
230
- link = PATH . dirname ( current_path ) + '/' + link ;
230
+ if ( PATH . isAbs ( link ) ) {
231
+ current = FS . root ;
232
+ current_path = "/" ;
233
+ } else {
234
+ current = current . parent ;
235
+ current_path = PATH . dirname ( current_path ) ;
231
236
}
232
- path = link + '/' + parts . slice ( i + 1 ) . join ( '/' ) ;
237
+ parts = [ ] . concat ( pathParts ( link ) , parts . slice ( i + 1 ) ) ;
233
238
continue linkloop ;
234
239
}
235
240
}
@@ -405,7 +410,7 @@ FS.staticInit();
405
410
if ( ! FS . isDir ( node . mode ) ) {
406
411
return { { { cDefs . ENOTDIR } } } ;
407
412
}
408
- if ( FS . isRoot ( node ) || FS . getPath ( node ) === FS . cwd ( ) ) {
413
+ if ( FS . isRoot ( node ) || node === FS . currentNode ) {
409
414
return { { { cDefs. EBUSY } } } ;
410
415
}
411
416
} else {
@@ -886,8 +891,9 @@ FS.staticInit();
886
891
#endif
887
892
} ,
888
893
readdir ( path ) {
889
- var lookup = FS . lookupPath ( path , { follow : true } ) ;
890
- var node = lookup . node ;
894
+ FS . readdirNode ( FS . lookupPath ( path , { follow : true } ) . node ) ;
895
+ } ,
896
+ readdirNode ( node ) {
891
897
if ( ! node . node_ops . readdir ) {
892
898
throw new FS . ErrnoError ( { { { cDefs . ENOTDIR } } } ) ;
893
899
}
@@ -944,6 +950,9 @@ FS.staticInit();
944
950
if ( ! node ) {
945
951
throw new FS . ErrnoError ( { { { cDefs . ENOENT } } } ) ;
946
952
}
953
+ return FS . statNode ( node ) ;
954
+ } ,
955
+ statNode ( node ) {
947
956
if ( ! node . node_ops . getattr ) {
948
957
throw new FS . ErrnoError ( { { { cDefs . EPERM } } } ) ;
949
958
}
@@ -1366,6 +1375,7 @@ FS.staticInit();
1366
1375
throw new FS . ErrnoError ( errCode ) ;
1367
1376
}
1368
1377
FS . currentPath = lookup . path ;
1378
+ FS . currentNode = lookup . node ;
1369
1379
} ,
1370
1380
createDefaultDirectories ( ) {
1371
1381
FS . mkdir ( '/ tmp ') ;
@@ -1479,6 +1489,7 @@ FS.staticInit();
1479
1489
FS . nameTable = new Array ( 4096 ) ;
1480
1490
1481
1491
FS . mount ( MEMFS , { } , '/' ) ;
1492
+ FS . chdir ( '/' ) ;
1482
1493
1483
1494
FS . createDefaultDirectories ( ) ;
1484
1495
FS . createDefaultDevices ( ) ;
0 commit comments