-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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 |
|---|---|---|
|
|
@@ -720,37 +720,30 @@ static int CountDigits(int value) | |
| // extended attributes. They get collected and saved in that dictionary, with no restrictions. | ||
| private void CollectExtendedAttributesFromStandardFieldsIfNeeded() | ||
| { | ||
| ExtendedAttributes.Add(PaxEaName, _name); | ||
| ExtendedAttributes[PaxEaName] = _name; | ||
|
|
||
| if (!ExtendedAttributes.ContainsKey(PaxEaMTime)) | ||
| { | ||
| ExtendedAttributes.Add(PaxEaMTime, TarHelpers.GetTimestampStringFromDateTimeOffset(_mTime)); | ||
| } | ||
|
|
||
| if (!string.IsNullOrEmpty(_gName)) | ||
| { | ||
| TryAddStringField(ExtendedAttributes, PaxEaGName, _gName, FieldLengths.GName); | ||
| } | ||
|
|
||
| if (!string.IsNullOrEmpty(_uName)) | ||
| { | ||
| TryAddStringField(ExtendedAttributes, PaxEaUName, _uName, FieldLengths.UName); | ||
| } | ||
| TryAddStringField(ExtendedAttributes, PaxEaGName, _gName, FieldLengths.GName); | ||
| TryAddStringField(ExtendedAttributes, PaxEaUName, _uName, FieldLengths.UName); | ||
|
|
||
| if (!string.IsNullOrEmpty(_linkName)) | ||
carlossanlop marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| ExtendedAttributes.Add(PaxEaLinkName, _linkName); | ||
| ExtendedAttributes[PaxEaLinkName] = _linkName; | ||
| } | ||
|
|
||
| if (_size > 99_999_999) | ||
| { | ||
| ExtendedAttributes.Add(PaxEaSize, _size.ToString()); | ||
| 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. | ||
| static void TryAddStringField(Dictionary<string, string> extendedAttributes, string key, string value, int maxLength) | ||
| static void TryAddStringField(Dictionary<string, string> extendedAttributes, string key, string? value, int maxLength) | ||
| { | ||
| if (Encoding.UTF8.GetByteCount(value) > maxLength) | ||
| if (!string.IsNullOrEmpty(value) && GetUtf8TextLength(value) > maxLength) | ||
| { | ||
| extendedAttributes.Add(key, value); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pointing out some other issues in this code:
The modification time will be neglected due to this check. @carlossanlop please advice if this is something we should address in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. We must always update the dictionary value for mtime using the value from the ModificationTime property. So the if condition should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you recall why was added in the first place?