-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Breaking change docs: TarWriter now emits HardLink entries for hard-linked files (.NET 11) #52854
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
Copilot
wants to merge
4
commits into
main
Choose a base branch
from
copilot/breaking-change-use-hardlink-entries
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.
+92
−0
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
89 changes: 89 additions & 0 deletions
89
docs/core/compatibility/core-libraries/11/tarwriter-hardlink-entries.md
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 |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| --- | ||
| title: "Breaking change: TarWriter uses HardLink entries for hard-linked files" | ||
| description: "Learn about the breaking change in .NET 11 where TarWriter writes HardLink entries for files that share the same inode instead of duplicating the file content." | ||
| ms.date: 04/03/2026 | ||
| ai-usage: ai-assisted | ||
| --- | ||
|
|
||
| # TarWriter uses HardLink entries for hard-linked files | ||
|
|
||
| <xref:System.Formats.Tar.TarWriter> now detects when multiple files are hard-linked to the same inode. It writes a `HardLink` entry for subsequent files instead of duplicating the file content. | ||
|
|
||
| ## Version introduced | ||
|
|
||
| .NET 11 Preview 3 | ||
|
|
||
| ## Previous behavior | ||
|
|
||
| Previously, when creating a tar archive with `TarWriter`, files that were hard-linked to the same inode were treated as separate, independent files. The full file content was duplicated in the archive for each hard-linked file. | ||
|
|
||
| ```csharp | ||
| using System.Formats.Tar; | ||
| using System.IO; | ||
|
|
||
| string filePath1 = "file1.txt"; | ||
| string filePath2 = "file2.txt"; | ||
|
|
||
| // Create two hard-linked files. | ||
| File.WriteAllText(filePath1, "Hello, world!"); | ||
| File.CreateHardLink(filePath2, filePath1); | ||
|
|
||
| using (var stream = File.Create("archive.tar")) | ||
| using (var writer = new TarWriter(stream, TarEntryFormat.Pax, leaveOpen: false)) | ||
| { | ||
| writer.WriteEntry(filePath1, "file1.txt"); | ||
| writer.WriteEntry(filePath2, "file2.txt"); | ||
| } | ||
| ``` | ||
|
|
||
| In the resulting `archive.tar`, both `file1.txt` and `file2.txt` had separate file entries, each containing the full file content. | ||
|
|
||
| ## New behavior | ||
|
|
||
| Starting in .NET 11, <xref:System.Formats.Tar.TarWriter> detects when multiple files are hard-linked to the same inode and writes a <xref:System.Formats.Tar.TarEntryType.HardLink> entry for subsequent files instead of duplicating the file content. | ||
|
|
||
| Using the same code as shown in the [Previous behavior](#previous-behavior) section, the resulting `archive.tar` now contains a full file entry for `file1.txt`, while `file2.txt` has a `HardLink` entry pointing to `file1.txt`. | ||
|
|
||
| ## Type of breaking change | ||
|
|
||
| This change is a [behavioral change](../../categories.md#behavioral-change). | ||
|
|
||
| ## Reason for change | ||
|
|
||
| This change improves the efficiency of tar archives created by the <xref:System.Formats.Tar> library. By using <System.Formats.Tar.TarEntryType.HardLink> entries for files that share the same inode, the size of the resulting archive is reduced and the hard-link relationships between files are preserved. This behavior is consistent with GNU tar and other widely used tar implementations. | ||
|
|
||
| ## Recommended action | ||
|
|
||
| If your application depends on duplicating file content for hard-linked files, you can restore the previous behavior. Set the <xref:System.Formats.Tar.TarWriterOptions.HardLinkMode> property to <xref:System.Formats.Tar.TarHardLinkMode.CopyContents?displayProperty=nameWithType> in a new <xref:System.Formats.Tar.TarWriterOptions> instance: | ||
|
|
||
| ```csharp | ||
| using System.Formats.Tar; | ||
| using System.IO; | ||
|
|
||
| string filePath1 = "file1.txt"; | ||
| string filePath2 = "file2.txt"; | ||
|
|
||
| // Create two hard-linked files. | ||
| File.WriteAllText(filePath1, "Hello, world!"); | ||
| File.CreateHardLink(filePath2, filePath1); | ||
|
|
||
| var options = new TarWriterOptions | ||
| { | ||
| HardLinkMode = TarHardLinkMode.CopyContents | ||
| }; | ||
|
|
||
| using (var stream = File.Create("archive.tar")) | ||
| using (var writer = new TarWriter(stream, options, leaveOpen: false)) | ||
| { | ||
| writer.WriteEntry(filePath1, "file1.txt"); | ||
| writer.WriteEntry(filePath2, "file2.txt"); | ||
| } | ||
| ``` | ||
|
|
||
| Extracting a tar archive that contains `HardLink` entries to a file system without hard link support throws an <xref:System.IO.IOException>. Use the new <xref:System.Formats.Tar.TarExtractOptions> class to specify whether to extract hard links as hard links or copy them as separate files. This enables extraction to file systems without hard link support. | ||
|
|
||
| ## Affected APIs | ||
|
|
||
| - <xref:System.Formats.Tar.TarWriter?displayProperty=fullName> | ||
| - <xref:System.Formats.Tar.TarWriter.WriteEntry(System.String,System.String)?displayProperty=fullName> | ||
| - <xref:System.Formats.Tar.TarWriter.WriteEntryAsync(System.String,System.String,System.Threading.CancellationToken)?displayProperty=fullName> | ||
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.