public void Add_BlockDevice_Async(TarEntryFormat format) { RemoteExecutor.Invoke(async(string strFormat) => { TarEntryFormat expectedFormat = Enum.Parse <TarEntryFormat>(strFormat); using (TempDirectory root = new TempDirectory()) { string blockDevicePath = Path.Join(root.Path, AssetBlockDeviceFileName); // Creating device files needs elevation Interop.CheckIo(Interop.Sys.CreateBlockDevice(blockDevicePath, (int)DefaultMode, TestBlockDeviceMajor, TestBlockDeviceMinor)); await using (MemoryStream archive = new MemoryStream()) { await using (TarWriter writer = new TarWriter(archive, expectedFormat, leaveOpen: true)) { await writer.WriteEntryAsync(fileName: blockDevicePath, entryName: AssetBlockDeviceFileName); } archive.Seek(0, SeekOrigin.Begin); await using (TarReader reader = new TarReader(archive)) { PosixTarEntry entry = await reader.GetNextEntryAsync() as PosixTarEntry; Assert.Equal(expectedFormat, entry.Format); Assert.NotNull(entry); Assert.Equal(AssetBlockDeviceFileName, entry.Name); Assert.Equal(DefaultLinkName, entry.LinkName); Assert.Equal(TarEntryType.BlockDevice, entry.EntryType); Assert.Null(entry.DataStream); VerifyPlatformSpecificMetadata(blockDevicePath, entry); Assert.Equal(TestBlockDeviceMajor, entry.DeviceMajor); Assert.Equal(TestBlockDeviceMinor, entry.DeviceMinor); Assert.Null(await reader.GetNextEntryAsync()); } } } }, format.ToString(), new RemoteInvokeOptions { RunAsSudo = true }).Dispose(); }
public void Add_Fifo_Async(TarEntryFormat format) { RemoteExecutor.Invoke(async(string strFormat) => { TarEntryFormat expectedFormat = Enum.Parse <TarEntryFormat>(strFormat); using (TempDirectory root = new TempDirectory()) { string fifoName = "fifofile"; string fifoPath = Path.Join(root.Path, fifoName); Interop.CheckIo(Interop.Sys.MkFifo(fifoPath, (int)DefaultMode)); await using (MemoryStream archive = new MemoryStream()) { await using (TarWriter writer = new TarWriter(archive, expectedFormat, leaveOpen: true)) { await writer.WriteEntryAsync(fileName: fifoPath, entryName: fifoName); } archive.Seek(0, SeekOrigin.Begin); await using (TarReader reader = new TarReader(archive)) { PosixTarEntry entry = await reader.GetNextEntryAsync() as PosixTarEntry; Assert.Equal(expectedFormat, entry.Format); Assert.NotNull(entry); Assert.Equal(fifoName, entry.Name); Assert.Equal(DefaultLinkName, entry.LinkName); Assert.Equal(TarEntryType.Fifo, entry.EntryType); Assert.Null(entry.DataStream); VerifyPlatformSpecificMetadata(fifoPath, entry); Assert.Null(await reader.GetNextEntryAsync()); } } } }, format.ToString(), new RemoteInvokeOptions { RunAsSudo = true }).Dispose(); }