Skip to content

Deduplicate Tar writer/entry helpers - #131675

Open
alinpahontu2912 wants to merge 1 commit into
dotnet:mainfrom
alinpahontu2912:alinpahontu2912/tar-refactor-dedup
Open

Deduplicate Tar writer/entry helpers#131675
alinpahontu2912 wants to merge 1 commit into
dotnet:mainfrom
alinpahontu2912:alinpahontu2912/tar-refactor-dedup

Conversation

@alinpahontu2912

Copy link
Copy Markdown
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
@alinpahontu2912 alinpahontu2912 added this to the Future milestone Jul 31, 2026
@alinpahontu2912 alinpahontu2912 self-assigned this Jul 31, 2026
Copilot AI review requested due to automatic review settings July 31, 2026 20:46
@azure-pipelines

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-formats-tar
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-based TarEntry construction switch into TarWriter.CreateEntryForFormat.
  • Moves identical Unix/Windows hard-link extraction logic into shared TarEntry.ExtractAsHardLink.
  • Simplifies TarHelpers.GetCorrectTypeFlagForFormat into 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants