Deduplicate Tar writer/entry helpers - #131675
Open
alinpahontu2912 wants to merge 1 commit into
Open
Conversation
alinpahontu2912
commented
Jul 31, 2026
Member
- TarWriter.Unix.cs / TarWriter.Windows.cs: extract the duplicated Format switch expression that constructs a new TarEntry into a shared CreateEntryForFormat helper in TarWriter.cs.
- TarEntry.Unix.cs / TarEntry.Windows.cs: move the identical ExtractAsHardLink implementation (both just call the cross-platform File.CreateHardLink) into the shared TarEntry.cs.
- TarHelpers.cs: simplify GetCorrectTypeFlagForFormat from nested if/else to a tuple pattern-matching switch expression, same behavior.
- TarWriter.Unix.cs / TarWriter.Windows.cs: extract the duplicated Format switch expression that constructs a new TarEntry into a shared CreateEntryForFormat helper in TarWriter.cs. - TarEntry.Unix.cs / TarEntry.Windows.cs: move the identical ExtractAsHardLink implementation (both just call the cross-platform File.CreateHardLink) into the shared TarEntry.cs. - TarHelpers.cs: simplify GetCorrectTypeFlagForFormat from nested if/else to a tuple pattern-matching switch expression, same behavior. No behavior change. All 6580 System.Formats.Tar.Tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7572f80-427a-403d-aac4-e8c856f1ba08
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-formats-tar |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors System.Formats.Tar to remove duplicated platform-specific implementations by moving shared logic into common helpers, without changing observable behavior.
Changes:
- Extracts the repeated
Format-basedTarEntryconstruction switch intoTarWriter.CreateEntryForFormat. - Moves identical Unix/Windows hard-link extraction logic into shared
TarEntry.ExtractAsHardLink. - Simplifies
TarHelpers.GetCorrectTypeFlagForFormatinto an equivalent tuple switch expression.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.Windows.cs | Uses the shared CreateEntryForFormat helper instead of duplicating the Format switch. |
| src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.Unix.cs | Uses the shared CreateEntryForFormat helper instead of duplicating the Format switch. |
| src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs | Adds CreateEntryForFormat to centralize TarEntry instantiation per archive format. |
| src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHelpers.cs | Refactors GetCorrectTypeFlagForFormat to a switch expression with equivalent cases. |
| src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarEntry.Windows.cs | Removes duplicated ExtractAsHardLink implementation now shared in TarEntry.cs. |
| src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarEntry.Unix.cs | Removes duplicated ExtractAsHardLink implementation now shared in TarEntry.cs. |
| src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarEntry.cs | Adds shared ExtractAsHardLink implementation used by extraction flow. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.