@@ -54,6 +54,8 @@ const parse_js_1 = require("./parse.js");
5454const strip_absolute_path_js_1 = require ( "./strip-absolute-path.js" ) ;
5555const wc = __importStar ( require ( "./winchars.js" ) ) ;
5656const path_reservations_js_1 = require ( "./path-reservations.js" ) ;
57+ const symlink_error_js_1 = require ( "./symlink-error.js" ) ;
58+ const process_umask_js_1 = require ( "./process-umask.js" ) ;
5759const ONENTRY = Symbol ( 'onEntry' ) ;
5860const CHECKFS = Symbol ( 'checkFs' ) ;
5961const CHECKFS2 = Symbol ( 'checkFs2' ) ;
@@ -64,6 +66,7 @@ const DIRECTORY = Symbol('directory');
6466const LINK = Symbol ( 'link' ) ;
6567const SYMLINK = Symbol ( 'symlink' ) ;
6668const HARDLINK = Symbol ( 'hardlink' ) ;
69+ const ENSURE_NO_SYMLINK = Symbol ( 'ensureNoSymlink' ) ;
6770const UNSUPPORTED = Symbol ( 'unsupported' ) ;
6871const CHECKPATH = Symbol ( 'checkPath' ) ;
6972const STRIPABSOLUTEPATH = Symbol ( 'stripAbsolutePath' ) ;
@@ -226,7 +229,7 @@ class Unpack extends parse_js_1.Parser {
226229 this . processUmask =
227230 ! this . chmod ? 0
228231 : typeof opt . processUmask === 'number' ? opt . processUmask
229- : process . umask ( ) ;
232+ : ( 0 , process_umask_js_1 . umask ) ( ) ;
230233 this . umask =
231234 typeof opt . umask === 'number' ? opt . umask : this . processUmask ;
232235 // default mode for dirs created as parents
@@ -301,6 +304,7 @@ class Unpack extends parse_js_1.Parser {
301304 }
302305 return true ;
303306 }
307+ // no IO, just string checking for absolute indicators
304308 [ CHECKPATH ] ( entry ) {
305309 const p = ( 0 , normalize_windows_path_js_1 . normalizeWindowsPath ) ( entry . path ) ;
306310 const parts = p . split ( '/' ) ;
@@ -561,11 +565,33 @@ class Unpack extends parse_js_1.Parser {
561565 entry . resume ( ) ;
562566 }
563567 [ SYMLINK ] ( entry , done ) {
564- this [ LINK ] ( entry , String ( entry . linkpath ) , 'symlink' , done ) ;
568+ const parts = ( 0 , normalize_windows_path_js_1 . normalizeWindowsPath ) ( node_path_1 . default . relative ( this . cwd , node_path_1 . default . resolve ( node_path_1 . default . dirname ( String ( entry . absolute ) ) , String ( entry . linkpath ) ) ) ) . split ( '/' ) ;
569+ this [ ENSURE_NO_SYMLINK ] ( entry , this . cwd , parts , ( ) => this [ LINK ] ( entry , String ( entry . linkpath ) , 'symlink' , done ) , er => {
570+ this [ ONERROR ] ( er , entry ) ;
571+ done ( ) ;
572+ } ) ;
565573 }
566574 [ HARDLINK ] ( entry , done ) {
567575 const linkpath = ( 0 , normalize_windows_path_js_1 . normalizeWindowsPath ) ( node_path_1 . default . resolve ( this . cwd , String ( entry . linkpath ) ) ) ;
568- this [ LINK ] ( entry , linkpath , 'link' , done ) ;
576+ const parts = ( 0 , normalize_windows_path_js_1 . normalizeWindowsPath ) ( String ( entry . linkpath ) ) . split ( '/' ) ;
577+ this [ ENSURE_NO_SYMLINK ] ( entry , this . cwd , parts , ( ) => this [ LINK ] ( entry , linkpath , 'link' , done ) , er => {
578+ this [ ONERROR ] ( er , entry ) ;
579+ done ( ) ;
580+ } ) ;
581+ }
582+ [ ENSURE_NO_SYMLINK ] ( entry , cwd , parts , done , onError ) {
583+ const p = parts . shift ( ) ;
584+ if ( this . preservePaths || p === undefined )
585+ return done ( ) ;
586+ const t = node_path_1 . default . resolve ( cwd , p ) ;
587+ node_fs_1 . default . lstat ( t , ( er , st ) => {
588+ if ( er )
589+ return done ( ) ;
590+ if ( st ?. isSymbolicLink ( ) ) {
591+ return onError ( new symlink_error_js_1 . SymlinkError ( t , node_path_1 . default . resolve ( t , parts . join ( '/' ) ) ) ) ;
592+ }
593+ this [ ENSURE_NO_SYMLINK ] ( entry , t , parts , done , onError ) ;
594+ } ) ;
569595 }
570596 [ PEND ] ( ) {
571597 this [ PENDING ] ++ ;
@@ -699,7 +725,6 @@ class Unpack extends parse_js_1.Parser {
699725 }
700726 }
701727 [ LINK ] ( entry , linkpath , link , done ) {
702- // XXX: get the type ('symlink' or 'junction') for windows
703728 node_fs_1 . default [ link ] ( linkpath , String ( entry . absolute ) , er => {
704729 if ( er ) {
705730 this [ ONERROR ] ( er , entry ) ;
@@ -901,10 +926,25 @@ class UnpackSync extends Unpack {
901926 return er ;
902927 }
903928 }
929+ [ ENSURE_NO_SYMLINK ] ( _entry , cwd , parts , done , onError ) {
930+ if ( this . preservePaths || ! parts . length )
931+ return done ( ) ;
932+ let t = cwd ;
933+ for ( const p of parts ) {
934+ t = node_path_1 . default . resolve ( t , p ) ;
935+ const [ er , st ] = callSync ( ( ) => node_fs_1 . default . lstatSync ( t ) ) ;
936+ if ( er )
937+ return done ( ) ;
938+ if ( st . isSymbolicLink ( ) ) {
939+ return onError ( new symlink_error_js_1 . SymlinkError ( t , node_path_1 . default . resolve ( cwd , parts . join ( '/' ) ) ) ) ;
940+ }
941+ }
942+ done ( ) ;
943+ }
904944 [ LINK ] ( entry , linkpath , link , done ) {
905- const ls = `${ link } Sync` ;
945+ const linkSync = `${ link } Sync` ;
906946 try {
907- node_fs_1 . default [ ls ] ( linkpath , String ( entry . absolute ) ) ;
947+ node_fs_1 . default [ linkSync ] ( linkpath , String ( entry . absolute ) ) ;
908948 done ( ) ;
909949 entry . resume ( ) ;
910950 }
0 commit comments