File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -108,11 +108,13 @@ module.exports = class CacheFS {
108
108
_lookup ( filepath , follow = true ) {
109
109
let dir = this . _root ;
110
110
let partialPath = '/'
111
- for ( let part of path . split ( filepath ) ) {
111
+ let parts = path . split ( filepath )
112
+ for ( let i = 0 ; i < parts . length ; ++ i ) {
113
+ let part = parts [ i ] ;
112
114
dir = dir . get ( part ) ;
113
115
if ( ! dir ) throw new ENOENT ( filepath ) ;
114
116
// Follow symlinks
115
- if ( follow ) {
117
+ if ( follow || i < parts . length - 1 ) {
116
118
const stat = dir . get ( STAT )
117
119
if ( stat . type === 'symlink' ) {
118
120
let target = stat . target
Original file line number Diff line number Diff line change @@ -430,6 +430,20 @@ describe("fs.promises module", () => {
430
430
} ) ;
431
431
} ) ;
432
432
} ) ;
433
+ it ( "readlink operates on paths with symlinks" , done => {
434
+ fs . mkdir ( "/readlink" ) . finally ( ( ) => {
435
+ fs . symlink ( "/readlink" , "/readlink/sub" ) . then ( ( ) => {
436
+ fs . writeFile ( "/readlink/c.txt" , "hello" ) . then ( ( ) => {
437
+ fs . symlink ( "/readlink/c.txt" , "/readlink/d.txt" ) . then ( ( ) => {
438
+ fs . readlink ( "/readlink/sub/d.txt" ) . then ( data => {
439
+ expect ( data ) . toBe ( "/readlink/c.txt" )
440
+ done ( ) ;
441
+ } ) ;
442
+ } ) ;
443
+ } ) ;
444
+ } ) ;
445
+ } ) ;
446
+ } ) ;
433
447
} ) ;
434
448
435
449
} ) ;
Original file line number Diff line number Diff line change @@ -427,6 +427,21 @@ describe("fs module", () => {
427
427
} ) ;
428
428
} ) ;
429
429
} ) ;
430
+ it ( "readlink operates on paths with symlinks" , done => {
431
+ fs . mkdir ( "/readlink" , ( ) => {
432
+ fs . symlink ( "/readlink" , "/readlink/sub" , ( ) => {
433
+ fs . writeFile ( "/readlink/c.txt" , "hello" , ( ) => {
434
+ fs . symlink ( "/readlink/c.txt" , "/readlink/d.txt" , ( ) => {
435
+ fs . readlink ( "/readlink/sub/d.txt" , ( err , data ) => {
436
+ expect ( err ) . toBe ( null )
437
+ expect ( data ) . toBe ( "/readlink/c.txt" )
438
+ done ( ) ;
439
+ } ) ;
440
+ } ) ;
441
+ } ) ;
442
+ } ) ;
443
+ } ) ;
444
+ } ) ;
430
445
} ) ;
431
446
432
447
} ) ;
You can’t perform that action at this time.
0 commit comments