@@ -833,7 +833,7 @@ public void ParseHeaderWithEncoding(int length, string encodingName)
833
833
reparseHeader . ParseBuffer ( headerbytes , enc ) ;
834
834
Assert . AreEqual ( name , reparseHeader . Name ) ;
835
835
// top 100 bytes are name field in tar header
836
- for ( int i = 0 ; i < encodedName . Length ; i ++ )
836
+ for ( int i = 0 ; i < encodedName . Length ; i ++ )
837
837
{
838
838
Assert . AreEqual ( encodedName [ i ] , headerbytes [ i ] ) ;
839
839
}
@@ -852,9 +852,9 @@ public async Task StreamWithJapaneseNameAsync(int length, string encodingName)
852
852
var entryName = new string ( ( char ) 0x3042 , length ) ;
853
853
var data = new byte [ 32 ] ;
854
854
var encoding = Encoding . GetEncoding ( encodingName ) ;
855
- using ( var memoryStream = new MemoryStream ( ) )
855
+ using ( var memoryStream = new MemoryStream ( ) )
856
856
{
857
- using ( var tarOutput = new TarOutputStream ( memoryStream , encoding ) )
857
+ using ( var tarOutput = new TarOutputStream ( memoryStream , encoding ) )
858
858
{
859
859
var entry = TarEntry . CreateTarEntry ( entryName ) ;
860
860
entry . Size = 32 ;
@@ -874,5 +874,47 @@ public async Task StreamWithJapaneseNameAsync(int length, string encodingName)
874
874
File . WriteAllBytes ( Path . Combine ( Path . GetTempPath ( ) , $ "jpnametest_{ length } _{ encodingName } .tar") , memoryStream . ToArray ( ) ) ;
875
875
}
876
876
}
877
+ /// <summary>
878
+ /// This test could be considered integration test. it creates a tar archive with the root directory specified
879
+ /// Then extracts it and compares the two folders. This used to fail on unix due to issues with root folder handling
880
+ /// in the tar archive.
881
+ /// </summary>
882
+ [ Test ]
883
+ [ Category ( "Tar" ) ]
884
+ public void RootPathIsRespected ( )
885
+ {
886
+ using ( var extractDirectory = new TempDir ( ) )
887
+ using ( var tarFileName = new TempFile ( ) )
888
+ using ( var tempDirectory = new TempDir ( ) )
889
+ {
890
+ tempDirectory . CreateDummyFile ( ) ;
891
+
892
+ using ( var tarFile = File . Open ( tarFileName . FullName , FileMode . Create ) )
893
+ {
894
+ using ( var tarOutputStream = TarArchive . CreateOutputTarArchive ( tarFile ) )
895
+ {
896
+ tarOutputStream . RootPath = tempDirectory . FullName ;
897
+ var entry = TarEntry . CreateEntryFromFile ( tempDirectory . FullName ) ;
898
+ tarOutputStream . WriteEntry ( entry , true ) ;
899
+ }
900
+ }
901
+
902
+ using ( var file = File . OpenRead ( tarFileName . FullName ) )
903
+ {
904
+ using ( var archive = TarArchive . CreateInputTarArchive ( file , Encoding . UTF8 ) )
905
+ {
906
+ archive . ExtractContents ( extractDirectory . FullName ) ;
907
+ }
908
+ }
909
+
910
+ var expectationDirectory = new DirectoryInfo ( tempDirectory . FullName ) ;
911
+ foreach ( var checkFile in expectationDirectory . GetFiles ( "" , SearchOption . AllDirectories ) )
912
+ {
913
+ var relativePath = checkFile . FullName . Substring ( expectationDirectory . FullName . Length + 1 ) ;
914
+ FileAssert . Exists ( Path . Combine ( extractDirectory . FullName , relativePath ) ) ;
915
+ FileAssert . AreEqual ( checkFile . FullName , Path . Combine ( extractDirectory . FullName , relativePath ) ) ;
916
+ }
917
+ }
918
+ }
877
919
}
878
920
}
0 commit comments