|
| 1 | +--- |
| 2 | +title: "Breaking change: GnuTarEntry and PaxTarEntry no longer includes atime and ctime by default" |
| 3 | +description: "Learn about the breaking change in .NET 10 where GnuTarEntry and PaxTarEntry no longer automatically set access time and change time fields." |
| 4 | +ms.date: 01/30/2025 |
| 5 | +ai-usage: ai-assisted |
| 6 | +ms.custom: https://github.com/dotnet/docs/issues/46465 |
| 7 | +--- |
| 8 | +# GnuTarEntry and PaxTarEntry no longer includes atime and ctime by default |
| 9 | + |
| 10 | +Starting in .NET 10, <xref:System.Formats.Tar.GnuTarEntry> and <xref:System.Formats.Tar.PaxTarEntry> no longer automatically set access time (`atime`) and change time (`ctime`) fields when creating new entries. These fields are problematic in tar entries because not all tar readers support them. |
| 11 | + |
| 12 | +## Version introduced |
| 13 | + |
| 14 | +.NET 10 Preview 5 |
| 15 | + |
| 16 | +## Previous behavior |
| 17 | + |
| 18 | +Previously, `GnuTarEntry` and `PaxTarEntry` always added `atime` and `ctime` values when creating new entries. |
| 19 | + |
| 20 | +## New behavior |
| 21 | + |
| 22 | +Starting in .NET 10, `GnuTarEntry` and `PaxTarEntry` only set `atime` and `ctime` if: |
| 23 | + |
| 24 | +- The entry was read from a tar archive that already contained these fields |
| 25 | +- The user explicitly sets them using the appropriate properties |
| 26 | + |
| 27 | +The behavior of <xref:System.Formats.Tar.TarEntry.ModificationTime?displayProperty=nameWithType> remains unchanged. It's initialized to <xref:System.DateTime.UtcNow?displayProperty=nameWithType> for tar entries created with a constructor, and uses the file modification time for entries created from files. |
| 28 | + |
| 29 | +## Type of breaking change |
| 30 | + |
| 31 | +This is a [behavioral change](../../categories.md#behavioral-change). |
| 32 | + |
| 33 | +## Reason for change |
| 34 | + |
| 35 | +Better compatibility with other tar readers and improved round-tripping of tar files without modification. The `atime` and `ctime` fields create tar files that aren't readable by many tar clients. |
| 36 | + |
| 37 | +## Recommended action |
| 38 | + |
| 39 | +No action required for most users. If you require these fields to be set, you can do so directly: |
| 40 | + |
| 41 | +- For `GnuTarEntry`: Use <xref:System.Formats.Tar.GnuTarEntry.AccessTime?displayProperty=nameWithType> and <xref:System.Formats.Tar.GnuTarEntry.ChangeTime?displayProperty=nameWithType> properties |
| 42 | +- For `PaxTarEntry`: Use the constructor that accepts extended attributes: <xref:System.Formats.Tar.PaxTarEntry.%23ctor(System.Formats.Tar.TarEntryType,System.String,System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{System.String,System.String}})?displayProperty=nameWithType> |
| 43 | + |
| 44 | +However, be aware that setting these fields creates a tar file that might not be readable by many tar clients. |
| 45 | + |
| 46 | +## Affected APIs |
| 47 | + |
| 48 | +- <xref:System.Formats.Tar.GnuTarEntry?displayProperty=fullName> |
| 49 | +- <xref:System.Formats.Tar.PaxTarEntry?displayProperty=fullName> |
| 50 | +- <xref:System.Formats.Tar.TarReader?displayProperty=fullName> |
| 51 | +- <xref:System.Formats.Tar.TarWriter?displayProperty=fullName> |
0 commit comments