// Some fields that have a reserved spot in the header, may not fit in such field anymore, but they can fit in the // extended attributes. They get collected and saved in that dictionary, with no restrictions. private void CollectExtendedAttributesFromStandardFieldsIfNeeded() { ExtendedAttributes.Add(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); } if (!string.IsNullOrEmpty(_linkName)) { ExtendedAttributes.Add(PaxEaLinkName, _linkName); } if (_size > 99_999_999) { ExtendedAttributes.Add(PaxEaSize, _size.ToString()); }
// 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; } } }
/// <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, TarEntryFormat.Pax) { if (other._header._format is TarEntryFormat.Ustar or TarEntryFormat.Pax) { _header._prefix = other._header._prefix; } if (other is PaxTarEntry paxOther) { _header.InitializeExtendedAttributesWithExisting(paxOther.ExtendedAttributes); } else { if (other is GnuTarEntry gnuOther) { _header.ExtendedAttributes[TarHeader.PaxEaATime] = TarHelpers.GetTimestampStringFromDateTimeOffset(gnuOther.AccessTime); _header.ExtendedAttributes[TarHeader.PaxEaCTime] = TarHelpers.GetTimestampStringFromDateTimeOffset(gnuOther.ChangeTime); } } AddNewAccessAndChangeTimestampsIfNotExist(useMTime: false); }