-
Notifications
You must be signed in to change notification settings - Fork 5k
System.Formats.Tar: default to no ctime/atime. #115778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tmds
wants to merge
5
commits into
dotnet:main
Choose a base branch
from
tmds:tar_no_atime_ctime
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+209
−281
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2cd6e15
System.Formats.Tar: default to no ctime/atime.
tmds 925092b
Add back attribute lists in the XML docs.
tmds 2b4f6c3
Copy atime/ctime.
tmds 48e6830
Move atime/ctime copy back to GnuTarEntry ctor.
tmds d4accde
Test conversion with atime/ctime set.
tmds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ internal PaxTarEntry(TarHeader header, TarReader readerOfOrigin) | |
} | ||
|
||
/// <summary> | ||
/// Initializes a new <see cref="PaxTarEntry"/> instance with the specified entry type, entry name, and the default extended attributes. | ||
/// Initializes a new <see cref="PaxTarEntry"/> instance with the specified entry type and entry name. | ||
/// </summary> | ||
/// <param name="entryType">The type of the entry.</param> | ||
/// <param name="entryName">A string with the path and file name of this entry.</param> | ||
|
@@ -30,20 +30,7 @@ internal PaxTarEntry(TarHeader header, TarReader readerOfOrigin) | |
/// <item>In all platforms: <see cref="TarEntryType.Directory"/>, <see cref="TarEntryType.HardLink"/>, <see cref="TarEntryType.SymbolicLink"/>, <see cref="TarEntryType.RegularFile"/>.</item> | ||
/// <item>In Unix platforms only: <see cref="TarEntryType.BlockDevice"/>, <see cref="TarEntryType.CharacterDevice"/> and <see cref="TarEntryType.Fifo"/>.</item> | ||
/// </list> | ||
/// <para>Use the <see cref="PaxTarEntry(TarEntryType, string, IEnumerable{KeyValuePair{string, string}})"/> constructor to include additional extended attributes when creating the entry.</para> | ||
/// <para>The following entries are always found in the Extended Attributes dictionary of any PAX entry:</para> | ||
/// <list type="bullet"> | ||
/// <item>Modification time, under the name <c>mtime</c>, as a <see cref="double"/> number.</item> | ||
/// <item>Access time, under the name <c>atime</c>, as a <see cref="double"/> number.</item> | ||
/// <item>Change time, under the name <c>ctime</c>, as a <see cref="double"/> number.</item> | ||
/// <item>Path, under the name <c>path</c>, as a string.</item> | ||
/// </list> | ||
/// <para>The following entries are only found in the Extended Attributes dictionary of a PAX entry if certain conditions are met:</para> | ||
/// <list type="bullet"> | ||
/// <item>Group name, under the name <c>gname</c>, as a string, if it is larger than 32 bytes.</item> | ||
/// <item>User name, under the name <c>uname</c>, as a string, if it is larger than 32 bytes.</item> | ||
/// <item>File length, under the name <c>size</c>, as an <see cref="int"/>, if the string representation of the number is larger than 12 bytes.</item> | ||
/// </list> | ||
/// <para>Use the <see cref="PaxTarEntry(TarEntryType, string, IEnumerable{KeyValuePair{string, string}})"/> constructor to include extended attributes when creating the entry.</para> | ||
/// </remarks> | ||
/// <exception cref="ArgumentNullException"><paramref name="entryName"/> is <see langword="null"/>.</exception> | ||
/// <exception cref="ArgumentException"><para><paramref name="entryName"/> is empty.</para> | ||
|
@@ -53,13 +40,10 @@ public PaxTarEntry(TarEntryType entryType, string entryName) | |
: base(entryType, entryName, TarEntryFormat.Pax, isGea: false) | ||
{ | ||
_header._prefix = string.Empty; | ||
|
||
Debug.Assert(_header._mTime != default); | ||
AddNewAccessAndChangeTimestampsIfNotExist(useMTime: true); | ||
tmds marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/// <summary> | ||
/// Initializes a new <see cref="PaxTarEntry"/> instance with the specified entry type, entry name and Extended Attributes enumeration. | ||
/// Initializes a new <see cref="PaxTarEntry"/> instance with the specified entry type, entry name and extended attributes. | ||
/// </summary> | ||
/// <param name="entryType">The type of the entry.</param> | ||
/// <param name="entryName">A string with the path and file name of this entry.</param> | ||
|
@@ -69,19 +53,11 @@ public PaxTarEntry(TarEntryType entryType, string entryName) | |
/// <item>In all platforms: <see cref="TarEntryType.Directory"/>, <see cref="TarEntryType.HardLink"/>, <see cref="TarEntryType.SymbolicLink"/>, <see cref="TarEntryType.RegularFile"/>.</item> | ||
/// <item>In Unix platforms only: <see cref="TarEntryType.BlockDevice"/>, <see cref="TarEntryType.CharacterDevice"/> and <see cref="TarEntryType.Fifo"/>.</item> | ||
/// </list> | ||
/// The specified <paramref name="extendedAttributes"/> get appended to the default attributes, unless the specified enumeration overrides any of them. | ||
/// <para>The following entries are always found in the Extended Attributes dictionary of any PAX entry:</para> | ||
/// The specified <paramref name="extendedAttributes"/> are additional attributes to be used for the entry. | ||
/// <para>It may include PAX attributes like:</para> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've updated this list to the things I think a user may want to set. |
||
/// <list type="bullet"> | ||
/// <item>Modification time, under the name <c>mtime</c>, as a <see cref="double"/> number.</item> | ||
/// <item>Access time, under the name <c>atime</c>, as a <see cref="double"/> number.</item> | ||
/// <item>Change time, under the name <c>ctime</c>, as a <see cref="double"/> number.</item> | ||
/// <item>Path, under the name <c>path</c>, as a string.</item> | ||
/// </list> | ||
/// <para>The following entries are only found in the Extended Attributes dictionary of a PAX entry if certain conditions are met:</para> | ||
/// <list type="bullet"> | ||
/// <item>Group name, under the name <c>gname</c>, as a string, if it is larger than 32 bytes.</item> | ||
/// <item>User name, under the name <c>uname</c>, as a string, if it is larger than 32 bytes.</item> | ||
/// <item>File length, under the name <c>size</c>, as an <see cref="int"/>, if the string representation of the number is larger than 12 bytes.</item> | ||
/// </list> | ||
/// </remarks> | ||
/// <exception cref="ArgumentNullException"><paramref name="extendedAttributes"/> or <paramref name="entryName"/> is <see langword="null"/>.</exception> | ||
|
@@ -94,10 +70,7 @@ public PaxTarEntry(TarEntryType entryType, string entryName, IEnumerable<KeyValu | |
ArgumentNullException.ThrowIfNull(extendedAttributes); | ||
|
||
_header._prefix = string.Empty; | ||
_header.InitializeExtendedAttributesWithExisting(extendedAttributes); | ||
|
||
Debug.Assert(_header._mTime != default); | ||
AddNewAccessAndChangeTimestampsIfNotExist(useMTime: true); | ||
_header.AddExtendedAttributes(extendedAttributes); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -119,72 +92,39 @@ public PaxTarEntry(TarEntry other) | |
|
||
if (other is PaxTarEntry paxOther) | ||
{ | ||
_header.InitializeExtendedAttributesWithExisting(paxOther.ExtendedAttributes); | ||
_header.AddExtendedAttributes(paxOther.ExtendedAttributes); | ||
} | ||
else | ||
else if (other is GnuTarEntry gnuOther) | ||
{ | ||
if (other is GnuTarEntry gnuOther) | ||
if (gnuOther.AccessTime != default) | ||
{ | ||
_header.ExtendedAttributes[TarHeader.PaxEaATime] = TarHelpers.GetTimestampStringFromDateTimeOffset(gnuOther.AccessTime); | ||
} | ||
if (gnuOther.ChangeTime != default) | ||
{ | ||
if (gnuOther.AccessTime != default) | ||
{ | ||
_header.ExtendedAttributes[TarHeader.PaxEaATime] = TarHelpers.GetTimestampStringFromDateTimeOffset(gnuOther.AccessTime); | ||
} | ||
if (gnuOther.ChangeTime != default) | ||
{ | ||
_header.ExtendedAttributes[TarHeader.PaxEaCTime] = TarHelpers.GetTimestampStringFromDateTimeOffset(gnuOther.ChangeTime); | ||
} | ||
_header.ExtendedAttributes[TarHeader.PaxEaCTime] = TarHelpers.GetTimestampStringFromDateTimeOffset(gnuOther.ChangeTime); | ||
} | ||
} | ||
|
||
AddNewAccessAndChangeTimestampsIfNotExist(useMTime: false); | ||
} | ||
|
||
/// <summary> | ||
/// Returns the extended attributes for this entry. | ||
/// </summary> | ||
/// <remarks>The extended attributes are specified when constructing an entry. Use <see cref="PaxTarEntry(TarEntryType, string, IEnumerable{KeyValuePair{string, string}})"/> to append your own enumeration of extended attributes to the current entry on top of the default ones. Use <see cref="PaxTarEntry(TarEntryType, string)"/> to only use the default extended attributes. | ||
/// <para>The following entries are always found in the Extended Attributes dictionary of any PAX entry:</para> | ||
/// <remarks>The extended attributes are specified when constructing an entry and updated with additional attributes when the entry is written. Use <see cref="PaxTarEntry(TarEntryType, string, IEnumerable{KeyValuePair{string, string}})"/> to append custom extended attributes. | ||
/// <para>The following common PAX attributes may be included:</para> | ||
/// <list type="bullet"> | ||
/// <item>Modification time, under the name <c>mtime</c>, as a <see cref="double"/> number.</item> | ||
/// <item>Access time, under the name <c>atime</c>, as a <see cref="double"/> number.</item> | ||
/// <item>Change time, under the name <c>ctime</c>, as a <see cref="double"/> number.</item> | ||
/// <item>Path, under the name <c>path</c>, as a string.</item> | ||
/// </list> | ||
/// <para>The following entries are only found in the Extended Attributes dictionary of a PAX entry if certain conditions are met:</para> | ||
/// <list type="bullet"> | ||
/// <item>Group name, under the name <c>gname</c>, as a string, if it is larger than 32 bytes.</item> | ||
/// <item>User name, under the name <c>uname</c>, as a string, if it is larger than 32 bytes.</item> | ||
/// <item>File length, under the name <c>size</c>, as an <see cref="int"/>, if the string representation of the number is larger than 12 bytes.</item> | ||
/// <item>Group name, under the name <c>gname</c>, as a string.</item> | ||
/// <item>User name, under the name <c>uname</c>, as a string.</item> | ||
/// <item>File length, under the name <c>size</c>, as an <see cref="int"/>.</item> | ||
/// </list> | ||
/// </remarks> | ||
public IReadOnlyDictionary<string, string> ExtendedAttributes => _readOnlyExtendedAttributes ??= _header.ExtendedAttributes.AsReadOnly(); | ||
|
||
// Determines if the current instance's entry type supports setting a data stream. | ||
internal override bool IsDataStreamSetterSupported() => EntryType == TarEntryType.RegularFile; | ||
|
||
// Checks if the extended attributes dictionary contains 'atime' and 'ctime'. | ||
// If any of them is not found, it is added with the value of either the current entry's 'mtime', | ||
// or 'DateTimeOffset.UtcNow', depending on the value of 'useMTime'. | ||
private void AddNewAccessAndChangeTimestampsIfNotExist(bool useMTime) | ||
{ | ||
Debug.Assert(!useMTime || (useMTime && _header._mTime != default)); | ||
bool containsATime = _header.ExtendedAttributes.ContainsKey(TarHeader.PaxEaATime); | ||
bool containsCTime = _header.ExtendedAttributes.ContainsKey(TarHeader.PaxEaCTime); | ||
|
||
if (!containsATime || !containsCTime) | ||
{ | ||
string secondsFromEpochString = TarHelpers.GetTimestampStringFromDateTimeOffset(useMTime ? _header._mTime : DateTimeOffset.UtcNow); | ||
|
||
if (!containsATime) | ||
{ | ||
_header.ExtendedAttributes[TarHeader.PaxEaATime] = secondsFromEpochString; | ||
} | ||
|
||
if (!containsCTime) | ||
{ | ||
_header.ExtendedAttributes[TarHeader.PaxEaCTime] = secondsFromEpochString; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.