@@ -94,35 +94,56 @@ public void Extract_LinkEntry_TargetOutsideDirectory(TarEntryType entryType)
9494 Assert . Equal ( 0 , Directory . GetFileSystemEntries ( root . Path ) . Count ( ) ) ;
9595 }
9696
97- [ ConditionalFact ( typeof ( MountHelper ) , nameof ( MountHelper . CanCreateSymbolicLinks ) ) ]
98- public void Extract_SymbolicLinkEntry_TargetInsideDirectory ( ) => Extract_LinkEntry_TargetInsideDirectory_Internal ( TarEntryType . SymbolicLink ) ;
99-
100- [ ConditionalFact ( typeof ( PlatformDetection ) , nameof ( PlatformDetection . SupportsHardLinkCreation ) ) ]
101- public void Extract_HardLinkEntry_TargetInsideDirectory ( ) => Extract_LinkEntry_TargetInsideDirectory_Internal ( TarEntryType . HardLink ) ;
102-
103- private void Extract_LinkEntry_TargetInsideDirectory_Internal ( TarEntryType entryType )
97+ [ ConditionalTheory ( typeof ( MountHelper ) , nameof ( MountHelper . CanCreateSymbolicLinks ) ) ]
98+ [ InlineData ( TarEntryFormat . Pax ) ]
99+ [ InlineData ( TarEntryFormat . Gnu ) ]
100+ public void Extract_SymbolicLinkEntry_TargetInsideDirectory ( TarEntryFormat format ) => Extract_LinkEntry_TargetInsideDirectory_Internal ( TarEntryType . SymbolicLink , format , null ) ;
101+
102+ [ ConditionalTheory ( typeof ( PlatformDetection ) , nameof ( PlatformDetection . SupportsHardLinkCreation ) ) ]
103+ [ InlineData ( TarEntryFormat . Pax ) ]
104+ [ InlineData ( TarEntryFormat . Gnu ) ]
105+ public void Extract_HardLinkEntry_TargetInsideDirectory ( TarEntryFormat format ) => Extract_LinkEntry_TargetInsideDirectory_Internal ( TarEntryType . HardLink , format , null ) ;
106+
107+ [ ConditionalTheory ( typeof ( MountHelper ) , nameof ( MountHelper . CanCreateSymbolicLinks ) ) ]
108+ [ InlineData ( TarEntryFormat . Pax ) ]
109+ [ InlineData ( TarEntryFormat . Gnu ) ]
110+ public void Extract_SymbolicLinkEntry_TargetInsideDirectory_LongBaseDir ( TarEntryFormat format ) => Extract_LinkEntry_TargetInsideDirectory_Internal ( TarEntryType . SymbolicLink , format , new string ( 'a' , 99 ) ) ;
111+
112+ [ ConditionalTheory ( typeof ( PlatformDetection ) , nameof ( PlatformDetection . SupportsHardLinkCreation ) ) ]
113+ [ InlineData ( TarEntryFormat . Pax ) ]
114+ [ InlineData ( TarEntryFormat . Gnu ) ]
115+ public void Extract_HardLinkEntry_TargetInsideDirectory_LongBaseDir ( TarEntryFormat format ) => Extract_LinkEntry_TargetInsideDirectory_Internal ( TarEntryType . HardLink , format , new string ( 'a' , 99 ) ) ;
116+
117+ // This test would not pass for the V7 and Ustar formats in some OSs like MacCatalyst, tvOSSimulator and OSX, because the TempDirectory gets created in
118+ // a folder with a path longer than 100 bytes, and those tar formats have no way of handling pathnames and linknames longer than that length.
119+ // The rest of the OSs create the TempDirectory in a path that does not surpass the 100 bytes, so the 'subfolder' parameter gives a chance to extend
120+ // the base directory past that length, to ensure this scenario is tested everywhere.
121+ private void Extract_LinkEntry_TargetInsideDirectory_Internal ( TarEntryType entryType , TarEntryFormat format , string subfolder )
104122 {
105123 using TempDirectory root = new TempDirectory ( ) ;
106124
125+ string baseDir = string . IsNullOrEmpty ( subfolder ) ? root . Path : Path . Join ( root . Path , subfolder ) ;
126+ Directory . CreateDirectory ( baseDir ) ;
127+
107128 string linkName = "link" ;
108129 string targetName = "target" ;
109- string targetPath = Path . Join ( root . Path , targetName ) ;
130+ string targetPath = Path . Join ( baseDir , targetName ) ;
110131
111132 File . Create ( targetPath ) . Dispose ( ) ;
112133
113134 using MemoryStream archive = new MemoryStream ( ) ;
114- using ( TarWriter writer = new TarWriter ( archive , TarEntryFormat . Ustar , leaveOpen : true ) )
135+ using ( TarWriter writer = new TarWriter ( archive , format , leaveOpen : true ) )
115136 {
116- UstarTarEntry entry = new UstarTarEntry ( entryType , linkName ) ;
137+ TarEntry entry = InvokeTarEntryCreationConstructor ( format , entryType , linkName ) ;
117138 entry . LinkName = targetPath ;
118139 writer . WriteEntry ( entry ) ;
119140 }
120141
121142 archive . Seek ( 0 , SeekOrigin . Begin ) ;
122143
123- TarFile . ExtractToDirectory ( archive , root . Path , overwriteFiles : false ) ;
144+ TarFile . ExtractToDirectory ( archive , baseDir , overwriteFiles : false ) ;
124145
125- Assert . Equal ( 2 , Directory . GetFileSystemEntries ( root . Path ) . Count ( ) ) ;
146+ Assert . Equal ( 2 , Directory . GetFileSystemEntries ( baseDir ) . Count ( ) ) ;
126147 }
127148 }
128149}
0 commit comments