public void Constructor_Name_FullPath_DestinationDirectory_Match(TarEntryFormat format) { using TempDirectory root = new TempDirectory(); string fullPath = Path.Join(root.Path, "file.txt"); TarEntry entry = InvokeTarEntryCreationConstructor(format, GetTarEntryTypeForTarEntryFormat(TarEntryType.RegularFile, format), fullPath); entry.DataStream = new MemoryStream(); entry.DataStream.Write(new byte[] { 0x1 }); entry.DataStream.Seek(0, SeekOrigin.Begin); entry.ExtractToFile(fullPath, overwrite: false); Assert.True(File.Exists(fullPath)); }
public void ExtractToFile_Link_Throws(TarEntryFormat format, TarEntryType entryType) { using TempDirectory root = new TempDirectory(); string fileName = "mylink"; string fullPath = Path.Join(root.Path, fileName); string linkTarget = PlatformDetection.IsWindows ? @"C:\Windows\system32\notepad.exe" : "/usr/bin/nano"; TarEntry entry = InvokeTarEntryCreationConstructor(format, entryType, fileName); entry.LinkName = linkTarget; Assert.Throws <InvalidOperationException>(() => entry.ExtractToFile(fileName, overwrite: false)); Assert.Equal(0, Directory.GetFileSystemEntries(root.Path).Count()); }
public void ExtractGlobalExtendedAttributesEntry_Throws() { using TempDirectory root = new TempDirectory(); using MemoryStream archiveStream = new MemoryStream(); using (TarWriter writer = new TarWriter(archiveStream, leaveOpen: true)) { PaxGlobalExtendedAttributesTarEntry gea = new PaxGlobalExtendedAttributesTarEntry(new Dictionary <string, string>()); writer.WriteEntry(gea); } archiveStream.Position = 0; using (TarReader reader = new TarReader(archiveStream, leaveOpen: false)) { TarEntry entry = reader.GetNextEntry(); Assert.Throws <InvalidOperationException>(() => entry.ExtractToFile(Path.Join(root.Path, "file"), overwrite: true)); } }