| File: System\Formats\Tar\TarEntry.Unix.cs | Web Access |
| Project: src\runtime\src\libraries\System.Formats.Tar\src\System.Formats.Tar.csproj (System.Formats.Tar) |
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; using System.IO; using Microsoft.Win32.SafeHandles; namespace System.Formats.Tar { // Unix specific methods for the TarEntry class. public abstract partial class TarEntry { // Unix specific implementation of the method that extracts the current entry as a block device. private void ExtractAsBlockDevice(string destinationFileName) { Debug.Assert(EntryType is TarEntryType.BlockDevice); Interop.CheckIo(Interop.Sys.CreateBlockDevice(destinationFileName, (uint)Mode, (uint)_header._devMajor, (uint)_header._devMinor), destinationFileName); } // Unix specific implementation of the method that extracts the current entry as a character device. private void ExtractAsCharacterDevice(string destinationFileName) { Debug.Assert(EntryType is TarEntryType.CharacterDevice); Interop.CheckIo(Interop.Sys.CreateCharacterDevice(destinationFileName, (uint)Mode, (uint)_header._devMajor, (uint)_header._devMinor), destinationFileName); } // Unix specific implementation of the method that extracts the current entry as a fifo file. private void ExtractAsFifo(string destinationFileName) { Debug.Assert(EntryType is TarEntryType.Fifo); Interop.CheckIo(Interop.Sys.MkFifo(destinationFileName, (uint)Mode), destinationFileName); } // Unix specific implementation of the method that extracts the current entry as a hard link. private void ExtractAsHardLink(string targetFilePath, string hardLinkFilePath) { Debug.Assert(EntryType is TarEntryType.HardLink); Debug.Assert(!string.IsNullOrEmpty(targetFilePath)); Debug.Assert(!string.IsNullOrEmpty(hardLinkFilePath)); File.CreateHardLink(hardLinkFilePath, targetFilePath); } // On Unix-like systems no explicit step is needed to make a file sparse: the kernel // creates a hole whenever a write is preceded by a seek past the previous end. Most // modern file systems (ext4, btrfs, xfs, APFS, ...) support sparse files; on those that // do not, the SetLength call performed after the segment copy will still produce a // correct (but fully allocated) result. #pragma warning disable IDE0060 private static void TryMarkFileSparse(FileStream fs) { } #pragma warning restore IDE0060 } }