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)));
        }
        public async Task ExtractToFile_Link_Throws_Async(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;

                await Assert.ThrowsAsync <InvalidOperationException>(() => entry.ExtractToFileAsync(fileName, overwrite: false));

                Assert.Equal(0, Directory.GetFileSystemEntries(root.Path).Count());
            }
        }
        public async Task Constructor_Name_FullPath_DestinationDirectory_Match_Async(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);

                await entry.ExtractToFileAsync(fullPath, overwrite : false);

                Assert.True(File.Exists(fullPath));
            }
        }
示例#4
0
        public async Task ExtractGlobalExtendedAttributesEntry_Throws_Async()
        {
            using (TempDirectory root = new TempDirectory())
            {
                await using (MemoryStream archiveStream = new MemoryStream())
                {
                    await using (TarWriter writer = new TarWriter(archiveStream, leaveOpen: true))
                    {
                        PaxGlobalExtendedAttributesTarEntry gea = new PaxGlobalExtendedAttributesTarEntry(new Dictionary <string, string>());
                        await writer.WriteEntryAsync(gea);
                    }

                    archiveStream.Position = 0;

                    await using (TarReader reader = new TarReader(archiveStream, leaveOpen: false))
                    {
                        TarEntry entry = await reader.GetNextEntryAsync();

                        await Assert.ThrowsAsync <InvalidOperationException>(() => entry.ExtractToFileAsync(Path.Join(root.Path, "file"), overwrite: true));
                    }
                }
            }
        }