public void Read_Archive_File_HardLink(TarFormat format, TestTarFormat testFormat)
        {
            string testCaseName = "file_hardlink";

            using MemoryStream ms = GetTarMemoryStream(CompressionMethod.Uncompressed, testFormat, testCaseName);

            using TarReader reader = new TarReader(ms);

            if (testFormat == TestTarFormat.pax_gea)
            {
                // The GEA are collected after reading the first entry, not on the constructor
                Assert.Null(reader.GlobalExtendedAttributes);
            }
            // Format is determined after reading the first entry, not on the constructor
            Assert.Equal(TarFormat.Unknown, reader.Format);
            TarEntry file = reader.GetNextEntry();

            Assert.Equal(format, reader.Format);
            if (testFormat == TestTarFormat.pax_gea)
            {
                Assert.NotNull(reader.GlobalExtendedAttributes);
                Assert.True(reader.GlobalExtendedAttributes.Any());
                Assert.Contains(AssetPaxGeaKey, reader.GlobalExtendedAttributes);
                Assert.Equal(AssetPaxGeaValue, reader.GlobalExtendedAttributes[AssetPaxGeaKey]);
            }

            Verify_Archive_RegularFile(file, format, reader.GlobalExtendedAttributes, "file.txt", $"Hello {testCaseName}");

            TarEntry hardLink = reader.GetNextEntry();

            // The 'tar' tool detects hardlinks as regular files and saves them as such in the archives, for all formats
            Verify_Archive_RegularFile(hardLink, format, reader.GlobalExtendedAttributes, "hardlink.txt", $"Hello {testCaseName}");

            Assert.Null(reader.GetNextEntry());
        }
        protected void Read_Archive_LongPath_Over255_Internal(TarEntryFormat format, TestTarFormat testFormat)
        {
            string testCaseName = "longpath_over255";

            using MemoryStream ms = GetTarMemoryStream(CompressionMethod.Uncompressed, testFormat, testCaseName);

            using TarReader reader = new TarReader(ms);

            if (testFormat is TestTarFormat.pax_gea)
            {
                VerifyGlobalExtendedAttributes(reader);
            }

            TarEntry directory = reader.GetNextEntry();

            VerifyDirectoryEntry(directory, format,
                                 "000000000011111111112222222222333333333344444444445555555555666666666677777777778888888888999999999900000000001111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000111111111122222222223333333333444444444455555/");

            TarEntry file = reader.GetNextEntry();

            VerifyRegularFileEntry(file, format,
                                   "000000000011111111112222222222333333333344444444445555555555666666666677777777778888888888999999999900000000001111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000111111111122222222223333333333444444444455555/00000000001111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999000000000011111111112222222222333333333344444444445.txt",
                                   $"Hello {testCaseName}");

            Assert.Null(reader.GetNextEntry());
        }
Beispiel #3
0
        public void Read_Archive_Folder_File_Utf8(TarEntryFormat format, TestTarFormat testFormat)
        {
            string testCaseName = "folder_file_utf8";

            using MemoryStream ms = GetTarMemoryStream(CompressionMethod.Uncompressed, testFormat, testCaseName);

            using TarReader reader = new TarReader(ms);
            if (testFormat == TestTarFormat.pax_gea)
            {
                // The GEA are collected after reading the first entry, not on the constructor
                Assert.Null(reader.GlobalExtendedAttributes);
            }

            // Format is determined after reading the first entry, not on the constructor
            Assert.Equal(TarEntryFormat.Unknown, reader.Format);
            TarEntry directory = reader.GetNextEntry();

            Assert.Equal(format, reader.Format);
            if (testFormat == TestTarFormat.pax_gea)
            {
                Assert.NotNull(reader.GlobalExtendedAttributes);
                Assert.True(reader.GlobalExtendedAttributes.Any());
                Assert.Contains(AssetPaxGeaKey, reader.GlobalExtendedAttributes);
                Assert.Equal(AssetPaxGeaValue, reader.GlobalExtendedAttributes[AssetPaxGeaKey]);
            }

            Verify_Archive_Directory(directory, reader.GlobalExtendedAttributes, "földër/");

            TarEntry file = reader.GetNextEntry();

            Verify_Archive_RegularFile(file, format, reader.GlobalExtendedAttributes, "földër/áöñ.txt", $"Hello {testCaseName}");

            Assert.Null(reader.GetNextEntry());
        }
        protected void Read_Archive_SpecialFiles_Internal(TarEntryFormat format, TestTarFormat testFormat)
        {
            string testCaseName = "specialfiles";

            using MemoryStream ms = GetTarMemoryStream(CompressionMethod.Uncompressed, testFormat, testCaseName);

            using TarReader reader = new TarReader(ms);

            if (testFormat is TestTarFormat.pax_gea)
            {
                VerifyGlobalExtendedAttributes(reader);
            }

            PosixTarEntry blockDevice = reader.GetNextEntry() as PosixTarEntry;

            VerifyBlockDeviceEntry(blockDevice, format, AssetBlockDeviceFileName);

            PosixTarEntry characterDevice = reader.GetNextEntry() as PosixTarEntry;

            VerifyCharacterDeviceEntry(characterDevice, format, AssetCharacterDeviceFileName);

            PosixTarEntry fifo = reader.GetNextEntry() as PosixTarEntry;

            VerifyFifoEntry(fifo, format, "fifofile");

            Assert.Null(reader.GetNextEntry());
        }
        public void Read_Archive_LongPath_Over255(TarFormat format, TestTarFormat testFormat)
        {
            string testCaseName = "longpath_over255";

            using MemoryStream ms = GetTarMemoryStream(CompressionMethod.Uncompressed, testFormat, testCaseName);

            using TarReader reader = new TarReader(ms);
            if (testFormat == TestTarFormat.pax_gea)
            {
                // The GEA are collected after reading the first entry, not on the constructor
                Assert.Null(reader.GlobalExtendedAttributes);
            }

            // Format is determined after reading the first entry, not on the constructor
            Assert.Equal(TarFormat.Unknown, reader.Format);
            TarEntry directory = reader.GetNextEntry();

            Assert.Equal(format, reader.Format);
            if (testFormat == TestTarFormat.pax_gea)
            {
                Assert.NotNull(reader.GlobalExtendedAttributes);
                Assert.True(reader.GlobalExtendedAttributes.Any());
                Assert.Contains(AssetPaxGeaKey, reader.GlobalExtendedAttributes);
                Assert.Equal(AssetPaxGeaValue, reader.GlobalExtendedAttributes[AssetPaxGeaKey]);
            }

            Verify_Archive_Directory(directory, reader.GlobalExtendedAttributes, "000000000011111111112222222222333333333344444444445555555555666666666677777777778888888888999999999900000000001111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000111111111122222222223333333333444444444455555/");

            TarEntry file = reader.GetNextEntry();

            Verify_Archive_RegularFile(file, format, reader.GlobalExtendedAttributes, "000000000011111111112222222222333333333344444444445555555555666666666677777777778888888888999999999900000000001111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000111111111122222222223333333333444444444455555/00000000001111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999000000000011111111112222222222333333333344444444445.txt", $"Hello {testCaseName}");

            Assert.Null(reader.GetNextEntry());
        }
Beispiel #6
0
        protected static string GetTarFilePath(CompressionMethod compressionMethod, TestTarFormat format, string testCaseName)
        {
            (string compressionMethodFolder, string fileExtension) = compressionMethod switch
            {
                CompressionMethod.Uncompressed => ("tar", ".tar"),
                CompressionMethod.GZip => ("targz", ".tar.gz"),
                _ => throw new InvalidOperationException($"Unexpected compression method: {compressionMethod}"),
            };

            return(Path.Join(Directory.GetCurrentDirectory(), compressionMethodFolder, format.ToString(), testCaseName + fileExtension));
        }
Beispiel #7
0
        public void Extract_Archive_File(TestTarFormat testFormat)
        {
            string sourceArchiveFileName = GetTarFilePath(CompressionMethod.Uncompressed, testFormat, "file");

            using TempDirectory destination = new TempDirectory();

            string filePath = Path.Join(destination.Path, "file.txt");

            TarFile.ExtractToDirectory(sourceArchiveFileName, destination.Path, overwriteFiles: false);

            Assert.True(File.Exists(filePath));
        }
        public void Read_Archive_Many_Small_Files(TarFormat format, TestTarFormat testFormat)
        {
            string testCaseName = "many_small_files";

            using MemoryStream ms = GetTarMemoryStream(CompressionMethod.Uncompressed, testFormat, testCaseName);

            using TarReader reader = new TarReader(ms);
            if (testFormat == TestTarFormat.pax_gea)
            {
                // The GEA are collected after reading the first entry, not on the constructor
                Assert.Null(reader.GlobalExtendedAttributes);
            }

            // Format is determined after reading the first entry, not on the constructor
            Assert.Equal(TarFormat.Unknown, reader.Format);

            List <TarEntry> entries = new List <TarEntry>();
            TarEntry        entry;
            bool            isFirstEntry = true;

            while ((entry = reader.GetNextEntry()) != null)
            {
                if (isFirstEntry)
                {
                    Assert.Equal(format, reader.Format);
                    if (testFormat == TestTarFormat.pax_gea)
                    {
                        Assert.NotNull(reader.GlobalExtendedAttributes);
                        Assert.True(reader.GlobalExtendedAttributes.Any());
                        Assert.Contains(AssetPaxGeaKey, reader.GlobalExtendedAttributes);
                        Assert.Equal(AssetPaxGeaValue, reader.GlobalExtendedAttributes[AssetPaxGeaKey]);
                    }

                    isFirstEntry = false;
                }
                entries.Add(entry);
            }

            int directoriesCount = entries.Count(e => e.EntryType == TarEntryType.Directory);

            Assert.Equal(10, directoriesCount);

            TarEntryType regularFileEntryType = format == TarFormat.V7 ? TarEntryType.V7RegularFile : TarEntryType.RegularFile;

            for (int i = 0; i < 10; i++)
            {
                int filesCount = entries.Count(e => e.EntryType == regularFileEntryType && e.Name.StartsWith($"{i}/"));
                Assert.Equal(10, filesCount);
            }
        }
        protected void Read_Archive_File_Internal(TarEntryFormat format, TestTarFormat testFormat)
        {
            string testCaseName = "file";

            using MemoryStream ms = GetTarMemoryStream(CompressionMethod.Uncompressed, testFormat, testCaseName);

            using TarReader reader = new TarReader(ms);

            if (testFormat is TestTarFormat.pax_gea)
            {
                VerifyGlobalExtendedAttributes(reader);
            }

            TarEntry file = reader.GetNextEntry();

            VerifyRegularFileEntry(file, format, "file.txt", $"Hello {testCaseName}");

            Assert.Null(reader.GetNextEntry());
        }
        protected void Read_Archive_Many_Small_Files_Internal(TarEntryFormat format, TestTarFormat testFormat)
        {
            string testCaseName = "many_small_files";

            using MemoryStream ms = GetTarMemoryStream(CompressionMethod.Uncompressed, testFormat, testCaseName);

            using TarReader reader = new TarReader(ms);

            if (testFormat is TestTarFormat.pax_gea)
            {
                VerifyGlobalExtendedAttributes(reader);
            }

            List <TarEntry> entries = new List <TarEntry>();
            TarEntry        entry;
            bool            isFirstEntry = true;

            while ((entry = reader.GetNextEntry()) != null)
            {
                if (isFirstEntry)
                {
                    isFirstEntry = false;
                }
                Assert.Equal(format, entry.Format);
                entries.Add(entry);
            }

            int directoriesCount = entries.Count(e => e.EntryType == TarEntryType.Directory);

            Assert.Equal(10, directoriesCount);

            TarEntryType actualEntryType = format is TarEntryFormat.V7 ? TarEntryType.V7RegularFile : TarEntryType.RegularFile;

            for (int i = 0; i < 10; i++)
            {
                int filesCount = entries.Count(e => e.EntryType == actualEntryType && e.Name.StartsWith($"{i}/"));
                Assert.Equal(10, filesCount);
            }
        }
        public void Read_Archive_SpecialFiles(TarFormat format, TestTarFormat testFormat)
        {
            string testCaseName = "specialfiles";

            using MemoryStream ms = GetTarMemoryStream(CompressionMethod.Uncompressed, testFormat, testCaseName);

            using TarReader reader = new TarReader(ms);
            if (testFormat == TestTarFormat.pax_gea)
            {
                // The GEA are collected after reading the first entry, not on the constructor
                Assert.Null(reader.GlobalExtendedAttributes);
            }

            // Format is determined after reading the first entry, not on the constructor
            Assert.Equal(TarFormat.Unknown, reader.Format);
            PosixTarEntry blockDevice = reader.GetNextEntry() as PosixTarEntry;

            Assert.Equal(format, reader.Format);
            if (testFormat == TestTarFormat.pax_gea)
            {
                Assert.NotNull(reader.GlobalExtendedAttributes);
                Assert.True(reader.GlobalExtendedAttributes.Any());
                Assert.Contains(AssetPaxGeaKey, reader.GlobalExtendedAttributes);
                Assert.Equal(AssetPaxGeaValue, reader.GlobalExtendedAttributes[AssetPaxGeaKey]);
            }

            Verify_Archive_BlockDevice(blockDevice, reader.GlobalExtendedAttributes, AssetBlockDeviceFileName);

            PosixTarEntry characterDevice = reader.GetNextEntry() as PosixTarEntry;

            Verify_Archive_CharacterDevice(characterDevice, reader.GlobalExtendedAttributes, AssetCharacterDeviceFileName);

            PosixTarEntry fifo = reader.GetNextEntry() as PosixTarEntry;

            Verify_Archive_Fifo(fifo, reader.GlobalExtendedAttributes, "fifofile");

            Assert.Null(reader.GetNextEntry());
        }
Beispiel #12
0
        protected async Task Read_Archive_File_Async_Internal(TarEntryFormat format, TestTarFormat testFormat)
        {
            string testCaseName = "file";

            await using (MemoryStream ms = GetTarMemoryStream(CompressionMethod.Uncompressed, testFormat, testCaseName))
            {
                await using (TarReader reader = new TarReader(ms))
                {
                    if (testFormat is TestTarFormat.pax_gea)
                    {
                        TarEntry entry = await reader.GetNextEntryAsync();

                        VerifyGlobalExtendedAttributes(entry);
                    }

                    TarEntry file = await reader.GetNextEntryAsync();

                    VerifyRegularFileEntry(file, format, "file.txt", $"Hello {testCaseName}");

                    Assert.Null(await reader.GetNextEntryAsync());
                }
            }
        }
        protected void Read_Archive_Folder_File_Utf8_Internal(TarEntryFormat format, TestTarFormat testFormat)
        {
            string testCaseName = "folder_file_utf8";

            using MemoryStream ms = GetTarMemoryStream(CompressionMethod.Uncompressed, testFormat, testCaseName);

            using TarReader reader = new TarReader(ms);

            if (testFormat is TestTarFormat.pax_gea)
            {
                VerifyGlobalExtendedAttributes(reader);
            }

            TarEntry directory = reader.GetNextEntry();

            VerifyDirectoryEntry(directory, format, "f\u00f6ld\u00ebr/"); //földër

            TarEntry file = reader.GetNextEntry();

            VerifyRegularFileEntry(file, format, "f\u00f6ld\u00ebr/\u00e1\u00f6\u00f1.txt", $"Hello {testCaseName}"); // földër/áöñ.txt

            Assert.Null(reader.GetNextEntry());
        }
        protected void Read_Archive_File_HardLink_Internal(TarEntryFormat format, TestTarFormat testFormat)
        {
            string testCaseName = "file_hardlink";

            using MemoryStream ms = GetTarMemoryStream(CompressionMethod.Uncompressed, testFormat, testCaseName);

            using TarReader reader = new TarReader(ms);

            if (testFormat is TestTarFormat.pax_gea)
            {
                VerifyGlobalExtendedAttributes(reader);
            }

            TarEntry file = reader.GetNextEntry();

            VerifyRegularFileEntry(file, format, "file.txt", $"Hello {testCaseName}");

            TarEntry hardLink = reader.GetNextEntry();

            // The 'tar' tool detects hardlinks as regular files and saves them as such in the archives, for all formats
            VerifyRegularFileEntry(hardLink, format, "hardlink.txt", $"Hello {testCaseName}");

            Assert.Null(reader.GetNextEntry());
        }
Beispiel #15
0
 public void Read_Archive_File_SymbolicLink(TarEntryFormat format, TestTarFormat testFormat) =>
 Read_Archive_File_SymbolicLink_Internal(format, testFormat);
        public void Read_Archive_FolderSymbolicLink_Folder_Subfolder_File(TarFormat format, TestTarFormat testFormat)
        {
            string testCaseName = "foldersymlink_folder_subfolder_file";

            using MemoryStream ms = GetTarMemoryStream(CompressionMethod.Uncompressed, testFormat, testCaseName);

            using TarReader reader = new TarReader(ms);
            if (testFormat == TestTarFormat.pax_gea)
            {
                // The GEA are collected after reading the first entry, not on the constructor
                Assert.Null(reader.GlobalExtendedAttributes);
            }

            // Format is determined after reading the first entry, not on the constructor
            Assert.Equal(TarFormat.Unknown, reader.Format);
            TarEntry childlink = reader.GetNextEntry();

            Assert.Equal(format, reader.Format);
            if (testFormat == TestTarFormat.pax_gea)
            {
                Assert.NotNull(reader.GlobalExtendedAttributes);
                Assert.True(reader.GlobalExtendedAttributes.Any());
                Assert.Contains(AssetPaxGeaKey, reader.GlobalExtendedAttributes);
                Assert.Equal(AssetPaxGeaValue, reader.GlobalExtendedAttributes[AssetPaxGeaKey]);
            }

            Verify_Archive_SymbolicLink(childlink, reader.GlobalExtendedAttributes, "childlink", "parent/child");

            TarEntry parent = reader.GetNextEntry();

            Verify_Archive_Directory(parent, reader.GlobalExtendedAttributes, "parent/");

            TarEntry child = reader.GetNextEntry();

            Verify_Archive_Directory(child, reader.GlobalExtendedAttributes, "parent/child/");

            TarEntry file = reader.GetNextEntry();

            Verify_Archive_RegularFile(file, format, reader.GlobalExtendedAttributes, "parent/child/file.txt", $"Hello {testCaseName}");

            Assert.Null(reader.GetNextEntry());
        }
Beispiel #17
0
 public void Read_Archive_SpecialFiles(TarEntryFormat format, TestTarFormat testFormat) =>
 Read_Archive_SpecialFiles_Internal(format, testFormat);
Beispiel #18
0
 public void Read_Archive_LongFileName_Over100_Under255(TarEntryFormat format, TestTarFormat testFormat) =>
 Read_Archive_LongFileName_Over100_Under255_Internal(format, testFormat);
 private static async Task VerifyDataStreamOfTarGzInternalAsync(TestTarFormat testTarFormat, string testCaseName, bool copyData)
 {
     await using MemoryStream archiveStream = GetTarMemoryStream(CompressionMethod.GZip, testTarFormat, testCaseName);
     await using GZipStream decompressor    = new GZipStream(archiveStream, CompressionMode.Decompress);
     await VerifyDataStreamOfTarInternalAsync(decompressor, copyData);
 }
 public Task Read_Archive_LongFileName_Over100_Under255_Async(TarEntryFormat format, TestTarFormat testFormat) =>
 Read_Archive_LongFileName_Over100_Under255_Async_Internal(format, testFormat);
 public Task Read_Archive_Many_Small_Files_Async(TarEntryFormat format, TestTarFormat testFormat) =>
 Read_Archive_Many_Small_Files_Async_Internal(format, testFormat);
 public Task Read_Archive_Folder_File_Utf8_Async(TarEntryFormat format, TestTarFormat testFormat) =>
 Read_Archive_Folder_File_Utf8_Async_Internal(format, testFormat);
 public Task Read_Archive_SpecialFiles_Async(TarEntryFormat format, TestTarFormat testFormat) =>
 Read_Archive_SpecialFiles_Async_Internal(format, testFormat);
Beispiel #24
0
 public void Read_Archive_Folder_File_Utf8(TarEntryFormat format, TestTarFormat testFormat) =>
 Read_Archive_Folder_File_Utf8_Internal(format, testFormat);
 public Task Read_Archive_File_HardLink_Async(TarEntryFormat format, TestTarFormat testFormat) =>
 Read_Archive_File_HardLink_Async_Internal(format, testFormat);
Beispiel #26
0
 public void Read_Archive_FolderSymbolicLink_Folder_Subfolder_File(TarEntryFormat format, TestTarFormat testFormat) =>
 Read_Archive_FolderSymbolicLink_Folder_Subfolder_File_Internal(format, testFormat);
 public Task Read_Archive_FolderSymbolicLink_Folder_Subfolder_File_Async(TarEntryFormat format, TestTarFormat testFormat) =>
 Read_Archive_FolderSymbolicLink_Folder_Subfolder_File_Async_Internal(format, testFormat);
Beispiel #28
0
 public void Read_Archive_Many_Small_Files(TarEntryFormat format, TestTarFormat testFormat) =>
 Read_Archive_Many_Small_Files_Internal(format, testFormat);
 public Task Read_Archive_LongPath_Splitable_Under255_Async(TarEntryFormat format, TestTarFormat testFormat) =>
 Read_Archive_LongPath_Splitable_Under255_Async_Internal(format, testFormat);
Beispiel #30
0
 public void Read_Archive_LongPath_Splitable_Under255(TarEntryFormat format, TestTarFormat testFormat) =>
 Read_Archive_LongPath_Splitable_Under255_Internal(format, testFormat);