@@ -2605,3 +2605,56 @@ t.test('handle errors on fs.close', t => {
2605
2605
cwd : dir + '/sync' , strict : true ,
2606
2606
} ) . end ( data ) , poop , 'sync' )
2607
2607
} )
2608
+
2609
+ t . test ( 'drop entry from dirCache if no longer a directory' , t => {
2610
+ const dir = path . resolve ( unpackdir , 'dir-cache-error' )
2611
+ mkdirp . sync ( dir + '/sync/y' )
2612
+ mkdirp . sync ( dir + '/async/y' )
2613
+ const data = makeTar ( [
2614
+ {
2615
+ path : 'x' ,
2616
+ type : 'Directory' ,
2617
+ } ,
2618
+ {
2619
+ path : 'x' ,
2620
+ type : 'SymbolicLink' ,
2621
+ linkpath : './y' ,
2622
+ } ,
2623
+ {
2624
+ path : 'x/ginkoid' ,
2625
+ type : 'File' ,
2626
+ size : 'ginkoid' . length ,
2627
+ } ,
2628
+ 'ginkoid' ,
2629
+ '' ,
2630
+ '' ,
2631
+ ] )
2632
+ t . plan ( 2 )
2633
+ const WARNINGS = { }
2634
+ const check = ( t , path ) => {
2635
+ t . equal ( fs . statSync ( path + '/x' ) . isDirectory ( ) , true )
2636
+ t . equal ( fs . lstatSync ( path + '/x' ) . isSymbolicLink ( ) , true )
2637
+ t . equal ( fs . statSync ( path + '/y' ) . isDirectory ( ) , true )
2638
+ t . strictSame ( fs . readdirSync ( path + '/y' ) , [ ] )
2639
+ t . throws ( ( ) => fs . readFileSync ( path + '/x/ginkoid' ) , { code : 'ENOENT' } )
2640
+ t . strictSame ( WARNINGS [ path ] , [
2641
+ 'TAR_ENTRY_ERROR' ,
2642
+ 'Cannot extract through symbolic link' ,
2643
+ ] )
2644
+ t . end ( )
2645
+ }
2646
+ t . test ( 'async' , t => {
2647
+ const path = dir + '/async'
2648
+ new Unpack ( { cwd : path } )
2649
+ . on ( 'warn' , ( code , msg ) => WARNINGS [ path ] = [ code , msg ] )
2650
+ . on ( 'end' , ( ) => check ( t , path ) )
2651
+ . end ( data )
2652
+ } )
2653
+ t . test ( 'sync' , t => {
2654
+ const path = dir + '/sync'
2655
+ new UnpackSync ( { cwd : path } )
2656
+ . on ( 'warn' , ( code , msg ) => WARNINGS [ path ] = [ code , msg ] )
2657
+ . end ( data )
2658
+ check ( t , path )
2659
+ } )
2660
+ } )
1 commit comments
RonSherfey commentedon Aug 17, 2021
changes to NPM vulnerabilities