Esempio n. 1
0
        protected async Task Read_Archive_Folder_File_Async_Internal(TarEntryFormat format, TestTarFormat testFormat)
        {
            string testCaseName = "folder_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 directory = await reader.GetNextEntryAsync();

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

                    TarEntry file = await reader.GetNextEntryAsync();

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

                    Assert.Null(await reader.GetNextEntryAsync());
                }
            }
        }
Esempio n. 2
0
 public void Verify_Checksum_RegularFile(TarEntryFormat format) =>
 Verify_Checksum_Internal(
     format,
     // Convert to V7RegularFile if format is V7
     GetTarEntryTypeForTarEntryFormat(TarEntryType.RegularFile, format),
     longLink: false,
     longPath: false);
Esempio n. 3
0
        private void VerifyDirectoryEntry(TarEntry directory, TarEntryFormat format, string expectedFileName)
        {
            Assert.NotNull(directory);
            VerifyType(directory, format);

            Assert.True(directory.Checksum > 0);
            Assert.Null(directory.DataStream);

            Assert.Equal(TarEntryType.Directory, directory.EntryType);

            Assert.Equal(AssetGid, directory.Gid);
            Assert.Equal(0, directory.Length);
            Assert.Equal(DefaultLinkName, directory.LinkName);
            Assert.Equal(AssetMode, directory.Mode);
            Assert.True(directory.ModificationTime > DateTimeOffset.UnixEpoch);
            Assert.Equal(expectedFileName, directory.Name);
            Assert.Equal(AssetUid, directory.Uid);

            if (directory is PosixTarEntry posix)
            {
                Assert.Equal(DefaultDeviceMajor, posix.DeviceMajor);
                Assert.Equal(DefaultDeviceMinor, posix.DeviceMinor);
                Assert.Equal(AssetGName, posix.GroupName);
                Assert.Equal(AssetUName, posix.UserName);
            }

            if (directory is PaxTarEntry pax)
            {
                VerifyExtendedAttributeTimestamps(pax);
            }
            else if (directory is GnuTarEntry gnu)
            {
                VerifyGnuTimestamps(gnu);
            }
        }
Esempio n. 4
0
        private void VerifyFifoEntry(PosixTarEntry fifo, TarEntryFormat format, string expectedFileName)
        {
            Assert.NotNull(fifo);
            VerifyType(fifo, format);

            Assert.True(fifo.Checksum > 0);
            Assert.Null(fifo.DataStream);

            Assert.Equal(TarEntryType.Fifo, fifo.EntryType);

            Assert.Equal(AssetGid, fifo.Gid);
            Assert.Equal(0, fifo.Length);
            Assert.Equal(DefaultLinkName, fifo.LinkName);
            Assert.Equal(AssetSpecialFileMode, fifo.Mode);
            Assert.True(fifo.ModificationTime > DateTimeOffset.UnixEpoch);
            Assert.Equal(expectedFileName, fifo.Name);
            Assert.Equal(AssetUid, fifo.Uid);

            Assert.Equal(DefaultDeviceMajor, fifo.DeviceMajor);
            Assert.Equal(DefaultDeviceMinor, fifo.DeviceMinor);
            Assert.Equal(AssetGName, fifo.GroupName);
            Assert.Equal(AssetUName, fifo.UserName);

            if (fifo is PaxTarEntry pax)
            {
                VerifyExtendedAttributeTimestamps(pax);
            }
            else if (fifo is GnuTarEntry gnu)
            {
                VerifyGnuTimestamps(gnu);
            }
        }
Esempio n. 5
0
        private void VerifyType(TarEntry entry, TarEntryFormat format, bool isGea = false)
        {
            Assert.Equal(format, entry.Format);
            switch (format)
            {
            case TarEntryFormat.V7:
                Assert.True(entry is V7TarEntry, "Entry was not V7");
                break;

            case TarEntryFormat.Ustar:
                Assert.True(entry is UstarTarEntry, "Entry was not Ustar");
                break;

            case TarEntryFormat.Gnu:
                Assert.True(entry is GnuTarEntry, "Entry was not Gnu");
                break;

            case TarEntryFormat.Pax:
                if (isGea)
                {
                    Assert.Equal(TarEntryType.GlobalExtendedAttributes, entry.EntryType);
                    Assert.True(entry is PaxGlobalExtendedAttributesTarEntry, "Entry was not PAX GEA");
                }
                else
                {
                    Assert.True(entry is PaxTarEntry, "Entry was not PAX");
                }
                break;

            default:
                throw new Exception($"Unexpected format: {format}");
            }
        }
Esempio n. 6
0
        private void VerifySymbolicLinkEntry(TarEntry symbolicLink, TarEntryFormat format, string expectedFileName, string expectedTargetName)
        {
            Assert.NotNull(symbolicLink);
            VerifyType(symbolicLink, format);

            Assert.True(symbolicLink.Checksum > 0);
            Assert.Null(symbolicLink.DataStream);

            Assert.Equal(TarEntryType.SymbolicLink, symbolicLink.EntryType);

            Assert.Equal(AssetGid, symbolicLink.Gid);
            Assert.Equal(0, symbolicLink.Length);
            Assert.Equal(expectedTargetName, symbolicLink.LinkName);
            Assert.Equal(AssetSymbolicLinkMode, symbolicLink.Mode);
            Assert.True(symbolicLink.ModificationTime > DateTimeOffset.UnixEpoch);
            Assert.Equal(expectedFileName, symbolicLink.Name);
            Assert.Equal(AssetUid, symbolicLink.Uid);

            if (symbolicLink is PosixTarEntry posix)
            {
                Assert.Equal(DefaultDeviceMajor, posix.DeviceMajor);
                Assert.Equal(DefaultDeviceMinor, posix.DeviceMinor);
                Assert.Equal(AssetGName, posix.GroupName);
                Assert.Equal(AssetUName, posix.UserName);
            }

            if (symbolicLink is PaxTarEntry pax)
            {
                VerifyExtendedAttributeTimestamps(pax);
            }
            else if (symbolicLink is GnuTarEntry gnu)
            {
                VerifyGnuTimestamps(gnu);
            }
        }
Esempio n. 7
0
        protected async Task Read_Archive_LongPath_Over255_Async_Internal(TarEntryFormat format, TestTarFormat testFormat)
        {
            string testCaseName = "longpath_over255";

            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 directory = await reader.GetNextEntryAsync();

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

                    TarEntry file = await reader.GetNextEntryAsync();

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

                    Assert.Null(await reader.GetNextEntryAsync());
                }
            }
        }
Esempio n. 8
0
        protected async Task Read_Archive_File_HardLink_Async_Internal(TarEntryFormat format, TestTarFormat testFormat)
        {
            string testCaseName = "file_hardlink";

            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}");

                    TarEntry hardLink = await reader.GetNextEntryAsync();

                    // 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(await reader.GetNextEntryAsync());
                }
            }
        }
Esempio n. 9
0
        protected async Task Read_Archive_SpecialFiles_Async_Internal(TarEntryFormat format, TestTarFormat testFormat)
        {
            string testCaseName = "specialfiles";

            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);
                    }

                    PosixTarEntry blockDevice = await reader.GetNextEntryAsync() as PosixTarEntry;

                    VerifyBlockDeviceEntry(blockDevice, format, AssetBlockDeviceFileName);

                    PosixTarEntry characterDevice = await reader.GetNextEntryAsync() as PosixTarEntry;

                    VerifyCharacterDeviceEntry(characterDevice, format, AssetCharacterDeviceFileName);

                    PosixTarEntry fifo = await reader.GetNextEntryAsync() as PosixTarEntry;

                    VerifyFifoEntry(fifo, format, "fifofile");

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

            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}");

            TarEntry symbolicLink = reader.GetNextEntry();

            VerifySymbolicLinkEntry(symbolicLink, format,
                                    "link.txt",
                                    "000000000011111111112222222222333333333344444444445555555555666666666677777777778888888888999999999900000000001111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000111111111122222222223333333333444444444455555/00000000001111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999000000000011111111112222222222333333333344444444445.txt");

            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());
        }
Esempio n. 12
0
        private int GetNameChecksum(TarEntryFormat format, bool longPath, out string entryName)
        {
            int expectedChecksum = 0;

            if (!longPath)
            {
                // 'a.b' = 97 + 46 + 98 = 241
                entryName         = "a.b";
                expectedChecksum += 241;
            }
            else
            {
                entryName = new string('a', 150);
                // 100 * 97 = 9700 (first 100 bytes go into 'name' field)
                expectedChecksum += 9700;

                // - V7 does not support name fields larger than 100, writes what it can
                // - Gnu writes first 100 bytes in 'name' field, then the full name is written in a LonPath entry
                // that precedes this one.
                if (format is TarEntryFormat.Ustar or TarEntryFormat.Pax)
                {
                    // 50 * 97 = 4850 (rest of bytes go into 'prefix' field)
                    expectedChecksum += 4850;
                }
            }
            return(expectedChecksum);
        }
        public void Write_RegularFileEntry_As_V7RegularFileEntry(TarEntryFormat entryFormat)
        {
            using MemoryStream archive = new MemoryStream();
            using (TarWriter writer = new TarWriter(archive, archiveFormat: TarEntryFormat.V7, leaveOpen: true))
            {
                TarEntry entry = entryFormat switch
                {
                    TarEntryFormat.Ustar => new UstarTarEntry(TarEntryType.RegularFile, InitialEntryName),
                    TarEntryFormat.Pax => new PaxTarEntry(TarEntryType.RegularFile, InitialEntryName),
                    TarEntryFormat.Gnu => new GnuTarEntry(TarEntryType.RegularFile, InitialEntryName),
                    _ => throw new FormatException()
                };

                // Should be written as V7RegularFile
                writer.WriteEntry(entry);
            }

            archive.Seek(0, SeekOrigin.Begin);
            using (TarReader reader = new TarReader(archive))
            {
                TarEntry entry = reader.GetNextEntry();
                Assert.True(entry is V7TarEntry);
                Assert.Equal(TarEntryType.V7RegularFile, entry.EntryType);

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

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

            using TarReader reader = new TarReader(ms);

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

            TarEntry parent = reader.GetNextEntry();

            VerifyDirectoryEntry(parent, format, "parent/");

            TarEntry child = reader.GetNextEntry();

            VerifyDirectoryEntry(child, format, "parent/child/");

            TarEntry file = reader.GetNextEntry();

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

            Assert.Null(reader.GetNextEntry());
        }
Esempio n. 15
0
 protected void VerifyDirectory(TarEntry entry, TarEntryFormat format, string name)
 {
     Assert.NotNull(entry);
     Assert.Equal(format, entry.Format);
     Assert.Equal(TarEntryType.Directory, entry.EntryType);
     Assert.Equal(name, entry.Name);
 }
Esempio n. 16
0
        private static TarHeader?TryReadAttributes(TarEntryFormat initialFormat, Span <byte> buffer)
        {
            // Confirms if v7 or pax, or tentatively selects ustar
            TarHeader?header = TryReadCommonAttributes(buffer, initialFormat);

            if (header != null)
            {
                // Confirms if gnu, or tentatively selects ustar
                header.ReadMagicAttribute(buffer);

                if (header._format != TarEntryFormat.V7)
                {
                    // Confirms if gnu
                    header.ReadVersionAttribute(buffer);

                    // Fields that ustar, pax and gnu share identically
                    header.ReadPosixAndGnuSharedAttributes(buffer);

                    Debug.Assert(header._format is TarEntryFormat.Ustar or TarEntryFormat.Pax or TarEntryFormat.Gnu);
                    if (header._format == TarEntryFormat.Ustar)
                    {
                        header.ReadUstarAttributes(buffer);
                    }
                    else if (header._format == TarEntryFormat.Gnu)
                    {
                        header.ReadGnuAttributes(buffer);
                    }
                    // In PAX, there is nothing to read in this section (empty space)
                }
            }
            return(header);
        }
Esempio n. 17
0
        public void ReadAndWriteMultipleGlobalExtendedAttributesEntries(TarEntryFormat format)
        {
            Dictionary <string, string> attrs = new Dictionary <string, string>()
            {
                { "hello", "world" },
                { "dotnet", "runtime" }
            };

            using MemoryStream archiveStream = new MemoryStream();
            using (TarWriter writer = new TarWriter(archiveStream, leaveOpen: true))
            {
                PaxGlobalExtendedAttributesTarEntry gea1 = new PaxGlobalExtendedAttributesTarEntry(attrs);
                writer.WriteEntry(gea1);

                TarEntry entry1 = InvokeTarEntryCreationConstructor(format, TarEntryType.Directory, "dir1");
                writer.WriteEntry(entry1);

                PaxGlobalExtendedAttributesTarEntry gea2 = new PaxGlobalExtendedAttributesTarEntry(attrs);
                writer.WriteEntry(gea2);

                TarEntry entry2 = InvokeTarEntryCreationConstructor(format, TarEntryType.Directory, "dir2");
                writer.WriteEntry(entry2);
            }

            archiveStream.Position = 0;

            using (TarReader reader = new TarReader(archiveStream, leaveOpen: false))
            {
                VerifyGlobalExtendedAttributesEntry(reader.GetNextEntry(), attrs);
                VerifyDirectory(reader.GetNextEntry(), format, "dir1");
                VerifyGlobalExtendedAttributesEntry(reader.GetNextEntry(), attrs);
                VerifyDirectory(reader.GetNextEntry(), format, "dir2");
                Assert.Null(reader.GetNextEntry());
            }
        }
Esempio n. 18
0
        public void WriteEntry_RespectDefaultWriterFormat(TarEntryFormat expectedFormat)
        {
            using TempDirectory root = new TempDirectory();

            string path = Path.Join(root.Path, "file.txt");

            File.Create(path).Dispose();

            using MemoryStream archiveStream = new MemoryStream();
            using (TarWriter writer = new TarWriter(archiveStream, expectedFormat, leaveOpen: true))
            {
                writer.WriteEntry(path, "file.txt");
            }

            archiveStream.Position = 0;
            using (TarReader reader = new TarReader(archiveStream, leaveOpen: false))
            {
                TarEntry entry = reader.GetNextEntry();
                Assert.Equal(expectedFormat, entry.Format);

                Type expectedType = GetTypeForFormat(expectedFormat);

                Assert.Equal(expectedType, entry.GetType());
            }
        }
Esempio n. 19
0
        public async Task Write_V7RegularFileEntry_In_OtherFormatsWriter_Async(TarEntryFormat writerFormat)
        {
            using MemoryStream archive = new MemoryStream();
            TarWriter writer = new TarWriter(archive, format: writerFormat, leaveOpen: true);

            await using (writer)
            {
                V7TarEntry entry = new V7TarEntry(TarEntryType.V7RegularFile, InitialEntryName);

                // Should be written in the format of the entry
                await writer.WriteEntryAsync(entry);
            }

            archive.Seek(0, SeekOrigin.Begin);
            TarReader reader = new TarReader(archive);

            await using (reader)
            {
                TarEntry entry = await reader.GetNextEntryAsync();

                Assert.NotNull(entry);
                Assert.Equal(TarEntryFormat.V7, entry.Format);
                Assert.True(entry is V7TarEntry);

                Assert.Null(await reader.GetNextEntryAsync());
            }
        }
        public void Constructor_ConversionFromUstar_From_UnseekableTarReader(TarEntryFormat writerFormat)
        {
            using MemoryStream source         = GetTarMemoryStream(CompressionMethod.Uncompressed, TestTarFormat.ustar, "file");
            using WrappedStream wrappedSource = new WrappedStream(source, canRead: true, canWrite: false, canSeek: false);

            using TarReader sourceReader = new TarReader(wrappedSource, leaveOpen: true);
            UstarTarEntry ustarEntry = sourceReader.GetNextEntry(copyData: false) as UstarTarEntry;
            V7TarEntry    v7Entry    = new V7TarEntry(other: ustarEntry); // Convert, and avoid advancing wrappedSource position

            using MemoryStream destination = new MemoryStream();
            using (TarWriter writer = new TarWriter(destination, writerFormat, leaveOpen: true))
            {
                writer.WriteEntry(v7Entry); // Write DataStream exactly where the wrappedSource position was left
            }

            destination.Position = 0; // Rewind
            using (TarReader destinationReader = new TarReader(destination, leaveOpen: false))
            {
                V7TarEntry resultEntry = destinationReader.GetNextEntry() as V7TarEntry;
                Assert.NotNull(resultEntry);
                using (StreamReader streamReader = new StreamReader(resultEntry.DataStream))
                {
                    Assert.Equal("Hello file", streamReader.ReadToEnd());
                }
            }
        }
Esempio n. 21
0
        // Constructor called when creating a new 'TarEntry*' instance that can be passed to a TarWriter.
        internal TarEntry(TarEntryType entryType, string entryName, TarEntryFormat format)
        {
            ArgumentException.ThrowIfNullOrEmpty(entryName);

            // Throws if format is unknown or out of range
            TarHelpers.VerifyEntryTypeIsSupported(entryType, format, forWriting: false);

            _readerOfOrigin = null;

            _header = default;

            _header._extendedAttributes = new Dictionary <string, string>();

            _header._name     = entryName;
            _header._linkName = string.Empty;
            _header._typeFlag = entryType;
            _header._mode     = (int)TarHelpers.DefaultMode;

            _header._gName = string.Empty;
            _header._uName = string.Empty;

            DateTimeOffset now = DateTimeOffset.Now;

            _header._mTime = now;
            _header._aTime = now;
            _header._cTime = now;
        }
Esempio n. 22
0
        public void Read_Archive_File_HardLink(TarEntryFormat 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(TarEntryFormat.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());
        }
Esempio n. 23
0
        public void Read_Archive_LongPath_Over255(TarEntryFormat 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(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, "000000000011111111112222222222333333333344444444445555555555666666666677777777778888888888999999999900000000001111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000111111111122222222223333333333444444444455555/");

            TarEntry file = reader.GetNextEntry();

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

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

            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,
                                 "00000000001111111111222222222233333333334444444444555555555566666666667777777777888888888899999999/");

            TarEntry file = reader.GetNextEntry();

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

            Assert.Null(reader.GetNextEntry());
        }
Esempio n. 25
0
 // Constructor called when reading a TarEntry from a TarReader.
 internal TarEntry(TarHeader header, TarReader readerOfOrigin, TarEntryFormat format)
 {
     // This constructor is called after reading a header from the archive,
     // and we should've already detected the format of the header.
     Debug.Assert(header._format == format);
     _header         = header;
     _readerOfOrigin = readerOfOrigin;
 }
        public Task ExtractToFileAsync_Cancel(TarEntryFormat format)
        {
            TarEntry entry             = InvokeTarEntryCreationConstructor(format, TarEntryType.Directory, "dir");
            CancellationTokenSource cs = new CancellationTokenSource();

            cs.Cancel();
            return(Assert.ThrowsAsync <TaskCanceledException>(() => entry.ExtractToFileAsync("dir", overwrite: true, cs.Token)));
        }
Esempio n. 27
0
 // Constructor called when the user creates a TarEntry instance from scratch.
 internal PosixTarEntry(TarEntryType entryType, string entryName, TarEntryFormat format, bool isGea)
     : base(entryType, entryName, format, isGea)
 {
     _header._uName    = string.Empty;
     _header._gName    = string.Empty;
     _header._devMajor = 0;
     _header._devMinor = 0;
 }
Esempio n. 28
0
        public void Extract(TarEntryFormat format, TarEntryType entryType)
        {
            using TempDirectory root = new TempDirectory();

            (string entryName, string destination, TarEntry entry) = Prepare_Extract(root, format, entryType);

            entry.ExtractToFile(destination, overwrite: true);

            Verify_Extract(destination, entry, entryType);
        }
Esempio n. 29
0
 protected async Task WriteEntry_Null_Throws_Async_Internal(TarEntryFormat format)
 {
     await using (MemoryStream archiveStream = new MemoryStream())
     {
         await using (TarWriter writer = new TarWriter(archiveStream, format, leaveOpen: false))
         {
             await Assert.ThrowsAsync <ArgumentNullException>(() => writer.WriteEntryAsync(null));
         }
     }
 }
Esempio n. 30
0
        public async Task Extract_SpecialFiles_Async(TarEntryFormat format, TarEntryType entryType)
        {
            using TempDirectory root = new TempDirectory();

            (string entryName, string destination, PosixTarEntry entry) = Prepare_Extract_SpecialFiles(root, format, entryType);

            await entry.ExtractToFileAsync(destination, overwrite : true);

            Verify_Extract_SpecialFiles(destination, entry, entryType);
        }