-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Tar: Use indexer setter instead of Add on ExtendedAttributes dictionary #76404
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -721,17 +721,14 @@ static int CountDigits(int value) | |
| private void CollectExtendedAttributesFromStandardFieldsIfNeeded() | ||
| { | ||
| ExtendedAttributes[PaxEaName] = _name; | ||
|
|
||
| if (!ExtendedAttributes.ContainsKey(PaxEaMTime)) | ||
| { | ||
| ExtendedAttributes.Add(PaxEaMTime, TarHelpers.GetTimestampStringFromDateTimeOffset(_mTime)); | ||
| } | ||
| ExtendedAttributes[PaxEaMTime] = TarHelpers.GetTimestampStringFromDateTimeOffset(_mTime); | ||
|
|
||
| TryAddStringField(ExtendedAttributes, PaxEaGName, _gName, FieldLengths.GName); | ||
| TryAddStringField(ExtendedAttributes, PaxEaUName, _uName, FieldLengths.UName); | ||
|
|
||
| if (!string.IsNullOrEmpty(_linkName)) | ||
| { | ||
| Debug.Assert(_typeFlag is TarEntryType.SymbolicLink or TarEntryType.HardLink); | ||
|
Contributor
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. Nice. |
||
| ExtendedAttributes[PaxEaLinkName] = _linkName; | ||
| } | ||
|
|
||
|
|
@@ -740,12 +737,16 @@ private void CollectExtendedAttributesFromStandardFieldsIfNeeded() | |
| ExtendedAttributes[PaxEaSize] = _size.ToString(); | ||
| } | ||
|
Contributor
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. We could add an else here, in case the data stream gets reduced below the max allowed size, in which case, we can remove the PaxEaSize value from the dictionary entry.
Contributor
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. In my other PR which was replaced by this one, I had a fake stream implementation that simulated having 99_999_999 length. You can reuse that to test this. |
||
|
|
||
| // Adds the specified string to the dictionary if it's longer than the specified max byte length. | ||
| // Sets the specified string to the dictionary if it's longer than the specified max byte length; otherwise, remove it. | ||
| static void TryAddStringField(Dictionary<string, string> extendedAttributes, string key, string? value, int maxLength) | ||
| { | ||
| if (!string.IsNullOrEmpty(value) && GetUtf8TextLength(value) > maxLength) | ||
| if (string.IsNullOrEmpty(value) || GetUtf8TextLength(value) <= maxLength) | ||
| { | ||
| extendedAttributes.Remove(key); | ||
| } | ||
| else | ||
| { | ||
| extendedAttributes.Add(key, value); | ||
| extendedAttributes[key] = value; | ||
| } | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.