public void Constructor_Name_FullPath_DestinationDirectory_Match() { using TempDirectory root = new TempDirectory(); string fullPath = Path.Join(root.Path, "file.txt"); GnuTarEntry entry = new GnuTarEntry(TarEntryType.RegularFile, 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(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"; GnuTarEntry entry = new GnuTarEntry(entryType, fileName); entry.LinkName = linkTarget; Assert.Throws <InvalidOperationException>(() => entry.ExtractToFile(fileName, overwrite: false)); Assert.Equal(0, Directory.GetFileSystemEntries(root.Path).Count()); }
public void Constructor_Name_FullPath_DestinationDirectory_Mismatch_Throws() { using TempDirectory root = new TempDirectory(); string fullPath = Path.Join(Path.GetPathRoot(root.Path), "dir", "file.txt"); GnuTarEntry entry = new GnuTarEntry(TarEntryType.RegularFile, fullPath); entry.DataStream = new MemoryStream(); entry.DataStream.Write(new byte[] { 0x1 }); entry.DataStream.Seek(0, SeekOrigin.Begin); Assert.Throws <IOException>(() => entry.ExtractToFile(root.Path, overwrite: false)); Assert.False(File.Exists(fullPath)); }