Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions src/libraries/System.Formats.Tar/ref/System.Formats.Tar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ namespace System.Formats.Tar
{
public sealed partial class GnuTarEntry : System.Formats.Tar.PosixTarEntry
{
public GnuTarEntry(System.Formats.Tar.TarEntry other) { }
public GnuTarEntry(System.Formats.Tar.TarEntryType entryType, string entryName) { }
public System.DateTimeOffset AccessTime { get { throw null; } set { } }
public System.DateTimeOffset ChangeTime { get { throw null; } set { } }
}
public sealed partial class PaxGlobalExtendedAttributesTarEntry : System.Formats.Tar.PosixTarEntry
{
public PaxGlobalExtendedAttributesTarEntry(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>> globalExtendedAttributes) { }
public System.Collections.Generic.IReadOnlyDictionary<string, string> GlobalExtendedAttributes { get { throw null; } }
}
public sealed partial class PaxTarEntry : System.Formats.Tar.PosixTarEntry
{
public PaxTarEntry(System.Formats.Tar.TarEntry other) { }
public PaxTarEntry(System.Formats.Tar.TarEntryType entryType, string entryName) { }
public PaxTarEntry(System.Formats.Tar.TarEntryType entryType, string entryName, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>> extendedAttributes) { }
public System.Collections.Generic.IReadOnlyDictionary<string, string> ExtendedAttributes { get { throw null; } }
Expand All @@ -32,6 +39,7 @@ internal TarEntry() { }
public int Checksum { get { throw null; } }
public System.IO.Stream? DataStream { get { throw null; } set { } }
public System.Formats.Tar.TarEntryType EntryType { get { throw null; } }
public System.Formats.Tar.TarEntryFormat Format { get { throw null; } }
public int Gid { get { throw null; } set { } }
public long Length { get { throw null; } }
public string LinkName { get { throw null; } set { } }
Expand All @@ -42,6 +50,14 @@ internal TarEntry() { }
public void ExtractToFile(string destinationFileName, bool overwrite) { }
public override string ToString() { throw null; }
}
public enum TarEntryFormat
{
Unknown = 0,
V7 = 1,
Ustar = 2,
Pax = 3,
Gnu = 4,
}
public enum TarEntryType : byte
{
V7RegularFile = (byte)0,
Expand Down Expand Up @@ -87,37 +103,29 @@ public enum TarFileMode
GroupSpecial = 1024,
UserSpecial = 2048,
}
public enum TarFormat
{
Unknown = 0,
V7 = 1,
Ustar = 2,
Pax = 3,
Gnu = 4,
}
public sealed partial class TarReader : System.IDisposable
{
public TarReader(System.IO.Stream archiveStream, bool leaveOpen = false) { }
public System.Formats.Tar.TarFormat Format { get { throw null; } }
public System.Collections.Generic.IReadOnlyDictionary<string, string>? GlobalExtendedAttributes { get { throw null; } }
public void Dispose() { }
public System.Formats.Tar.TarEntry? GetNextEntry(bool copyData = false) { throw null; }
}
public sealed partial class TarWriter : System.IDisposable
{
public TarWriter(System.IO.Stream archiveStream, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>>? globalExtendedAttributes = null, bool leaveOpen = false) { }
public TarWriter(System.IO.Stream archiveStream, System.Formats.Tar.TarFormat archiveFormat, bool leaveOpen = false) { }
public System.Formats.Tar.TarFormat Format { get { throw null; } }
public TarWriter(System.IO.Stream archiveStream) { }
public TarWriter(System.IO.Stream archiveStream, System.Formats.Tar.TarEntryFormat archiveFormat = System.Formats.Tar.TarEntryFormat.Pax, bool leaveOpen = false) { }
public System.Formats.Tar.TarEntryFormat Format { get { throw null; } }
public void Dispose() { }
public void WriteEntry(System.Formats.Tar.TarEntry entry) { }
public void WriteEntry(string fileName, string? entryName) { }
}
public sealed partial class UstarTarEntry : System.Formats.Tar.PosixTarEntry
{
public UstarTarEntry(System.Formats.Tar.TarEntry other) { }
public UstarTarEntry(System.Formats.Tar.TarEntryType entryType, string entryName) { }
}
public sealed partial class V7TarEntry : System.Formats.Tar.TarEntry
{
public V7TarEntry(System.Formats.Tar.TarEntry other) { }
public V7TarEntry(System.Formats.Tar.TarEntryType entryType, string entryName) { }
}
}
6 changes: 0 additions & 6 deletions src/libraries/System.Formats.Tar/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@
<data name="TarDuplicateExtendedAttribute" xml:space="preserve">
<value>The entry '{0}' has a duplicate extended attribute.</value>
</data>
<data name="TarEntriesInDifferentFormats" xml:space="preserve">
<value>An entry in '{0}' format was found in an archive where other entries of format '{1}' have been found.</value>
</data>
<data name="TarEntryBlockOrCharacterExpected" xml:space="preserve">
<value>Cannot set the 'DeviceMajor' or 'DeviceMinor' fields on an entry that does not represent a block or character device.</value>
</data>
Expand Down Expand Up @@ -240,9 +237,6 @@
<data name="TarSymbolicLinkTargetNotExists" xml:space="preserve">
<value>Cannot create the symbolic link '{0}' because the specified target '{1}' does not exist.</value>
</data>
<data name="TarTooManyGlobalExtendedAttributesEntries" xml:space="preserve">
<value>The archive has more than one global extended attributes entry.</value>
</data>
<data name="TarUnexpectedMetadataEntry" xml:space="preserve">
<value>A metadata entry of type '{0}' was unexpectedly found after a metadata entry of type '{1}'.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
<Compile Include="System\Formats\Tar\TarEntry.cs" />
<Compile Include="System\Formats\Tar\UstarTarEntry.cs" />
<Compile Include="System\Formats\Tar\GnuTarEntry.cs" />
<Compile Include="System\Formats\Tar\PaxGlobalExtendedAttributesTarEntry.cs" />
<Compile Include="System\Formats\Tar\PaxTarEntry.cs" />
<Compile Include="System\Formats\Tar\TarEntryType.cs" />
<Compile Include="System\Formats\Tar\TarFile.cs" />
<Compile Include="System\Formats\Tar\TarFormat.cs" />
<Compile Include="System\Formats\Tar\TarEntryFormat.cs" />
<Compile Include="System\Formats\Tar\TarReader.cs" />
<Compile Include="System\Formats\Tar\TarWriter.cs" />
<Compile Include="System\Formats\Tar\SubReadStream.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace System.Formats.Tar
/// <summary>
/// Represents a tar entry from an archive of the GNU format.
/// </summary>
/// <remarks>Even though the <see cref="TarFormat.Gnu"/> format is not POSIX compatible, it implements and supports the Unix-specific fields that were defined in the POSIX IEEE P1003.1 standard from 1988: <c>devmajor</c>, <c>devminor</c>, <c>gname</c> and <c>uname</c>.</remarks>
/// <remarks>Even though the <see cref="TarEntryFormat.Gnu"/> format is not POSIX compatible, it implements and supports the Unix-specific fields that were defined in the POSIX IEEE P1003.1 standard from 1988: <c>devmajor</c>, <c>devminor</c>, <c>gname</c> and <c>uname</c>.</remarks>
public sealed class GnuTarEntry : PosixTarEntry
{
// Constructor used when reading an existing archive.
Expand All @@ -29,10 +29,25 @@ internal GnuTarEntry(TarHeader header, TarReader readerOfOrigin)
/// </list>
/// </remarks>
public GnuTarEntry(TarEntryType entryType, string entryName)
: base(entryType, entryName, TarFormat.Gnu)
: base(entryType, entryName, TarEntryFormat.Gnu)
{
}

/// <summary>
/// Initializes a new <see cref="GnuTarEntry"/> instance by converting the specified <paramref name="other"/> entry into the GNU format.
/// </summary>
public GnuTarEntry(TarEntry other)
: base(other._header, other._readerOfOrigin!)
{
if (_header._typeFlag == TarEntryType.V7RegularFile)
{
_header._typeFlag = TarEntryType.RegularFile;
}
TarHelpers.VerifyEntryTypeIsSupported(_header._typeFlag, TarEntryFormat.Gnu, forWriting: false);

_header._format = TarEntryFormat.Gnu;
}

/// <summary>
/// A timestamp that represents the last time the file represented by this entry was accessed.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;

namespace System.Formats.Tar
{
/// <summary>
/// Represents a Global Extended Attributes tar entry from an archive of the PAX format.
/// </summary>
public sealed class PaxGlobalExtendedAttributesTarEntry : PosixTarEntry
{
private ReadOnlyDictionary<string, string>? _readOnlyGlobalExtendedAttributes;

// Constructor used when reading an existing archive.
internal PaxGlobalExtendedAttributesTarEntry(TarHeader header, TarReader readerOfOrigin)
: base(header, readerOfOrigin)
{
_readOnlyGlobalExtendedAttributes = null;
}

/// <summary>
/// Initializes a new <see cref="PaxGlobalExtendedAttributesTarEntry"/> instance with the specified Global Extended Attributes enumeration.
/// </summary>
/// <param name="globalExtendedAttributes">An enumeration of string key-value pairs that represents the metadata to include as Global Extended Attributes.</param>
/// <exception cref="ArgumentNullException"><paramref name="globalExtendedAttributes"/> is <see langword="null"/>.</exception>
public PaxGlobalExtendedAttributesTarEntry(IEnumerable<KeyValuePair<string, string>> globalExtendedAttributes)
: this(header: default, readerOfOrigin: null!)
{
ArgumentNullException.ThrowIfNull(globalExtendedAttributes);

_header._format = TarEntryFormat.Pax;
_header._extendedAttributes = new Dictionary<string, string>(globalExtendedAttributes);

_header._name = TarHeader.GlobalHeadFormatPrefix; // Does not contain the sequence number, since that depends on the archive to write
_header._mode = (int)TarHelpers.DefaultMode;
_header._typeFlag = TarEntryType.GlobalExtendedAttributes;
_header._linkName = string.Empty;
_header._magic = string.Empty;
_header._version = string.Empty;
_header._gName = string.Empty;
_header._uName = string.Empty;
}

/// <summary>
/// Returns the global extended attributes stored in this entry.
/// </summary>
public IReadOnlyDictionary<string, string> GlobalExtendedAttributes
{
get
{
_header._extendedAttributes ??= new Dictionary<string, string>();
return _readOnlyGlobalExtendedAttributes ??= _header._extendedAttributes.AsReadOnly();
}
}

// Determines if the current instance's entry type supports setting a data stream.
internal override bool IsDataStreamSetterSupported() => false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public sealed class PaxTarEntry : PosixTarEntry
internal PaxTarEntry(TarHeader header, TarReader readerOfOrigin)
: base(header, readerOfOrigin)
{
_header._extendedAttributes ??= new Dictionary<string, string>();
_readOnlyExtendedAttributes = null;
}

Expand Down Expand Up @@ -50,8 +49,9 @@ internal PaxTarEntry(TarHeader header, TarReader readerOfOrigin)
/// </list>
/// </remarks>
public PaxTarEntry(TarEntryType entryType, string entryName)
: base(entryType, entryName, TarFormat.Pax)
: base(entryType, entryName, TarEntryFormat.Pax)
{
_readOnlyExtendedAttributes = null;
}

/// <summary>
Expand Down Expand Up @@ -84,10 +84,25 @@ public PaxTarEntry(TarEntryType entryType, string entryName)
/// </list>
/// </remarks>
public PaxTarEntry(TarEntryType entryType, string entryName, IEnumerable<KeyValuePair<string, string>> extendedAttributes)
: base(entryType, entryName, TarFormat.Pax)
: base(entryType, entryName, TarEntryFormat.Pax)
{
ArgumentNullException.ThrowIfNull(extendedAttributes);
_header.ReplaceNormalAttributesWithExtended(extendedAttributes);
_header._extendedAttributes = new Dictionary<string, string>(extendedAttributes);
}

/// <summary>
/// Initializes a new <see cref="PaxTarEntry"/> instance by converting the specified <paramref name="other"/> entry into the PAX format.
/// </summary>
public PaxTarEntry(TarEntry other)
: base(other._header, other._readerOfOrigin!)
{
if (_header._typeFlag == TarEntryType.V7RegularFile)
{
_header._typeFlag = TarEntryType.RegularFile;
}
TarHelpers.VerifyEntryTypeIsSupported(_header._typeFlag, TarEntryFormat.Pax, forWriting: false);

_header._format = TarEntryFormat.Pax;
}

/// <summary>
Expand All @@ -112,7 +127,7 @@ public IReadOnlyDictionary<string, string> ExtendedAttributes
{
get
{
Debug.Assert(_header._extendedAttributes != null);
_header._extendedAttributes ??= new Dictionary<string, string>();
return _readOnlyExtendedAttributes ??= _header._extendedAttributes.AsReadOnly();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
namespace System.Formats.Tar
{
/// <summary>
/// Abstract class that represents a tar entry from an archive of a format that is based on the POSIX IEEE P1003.1 standard from 1988. This includes the formats <see cref="TarFormat.Ustar"/> (represented by the <see cref="UstarTarEntry"/> class), <see cref="TarFormat.Pax"/> (represented by the <see cref="PaxTarEntry"/> class) and <see cref="TarFormat.Gnu"/> (represented by the <see cref="GnuTarEntry"/> class).
/// Abstract class that represents a tar entry from an archive of a format that is based on the POSIX IEEE P1003.1 standard from 1988. This includes the formats <see cref="TarEntryFormat.Ustar"/> (represented by the <see cref="UstarTarEntry"/> class), <see cref="TarEntryFormat.Pax"/> (represented by the <see cref="PaxTarEntry"/> and <see cref="PaxGlobalExtendedAttributesTarEntry"/> classes) and <see cref="TarEntryFormat.Gnu"/> (represented by the <see cref="GnuTarEntry"/> class).
/// </summary>
/// <remarks>Formats that implement the POSIX IEEE P1003.1 standard from 1988, support the following header fields: <c>devmajor</c>, <c>devminor</c>, <c>gname</c> and <c>uname</c>.
/// Even though the <see cref="TarFormat.Gnu"/> format is not POSIX compatible, it implements and supports the Unix-specific fields that were defined in that POSIX standard.</remarks>
/// Even though the <see cref="TarEntryFormat.Gnu"/> format is not POSIX compatible, it implements and supports the Unix-specific fields that were defined in that POSIX standard.</remarks>
public abstract partial class PosixTarEntry : TarEntry
{
// Constructor used when reading an existing archive.
Expand All @@ -17,7 +17,7 @@ internal PosixTarEntry(TarHeader header, TarReader readerOfOrigin)
}

// Constructor called when creating a new 'TarEntry*' instance that can be passed to a TarWriter.
internal PosixTarEntry(TarEntryType entryType, string entryName, TarFormat format)
internal PosixTarEntry(TarEntryType entryType, string entryName, TarEntryFormat format)
: base(entryType, entryName, format)
{
}
Expand Down
Loading