import-tar: add --strip-components - #10220
Open
ThomasWaldmann wants to merge 1 commit into
Open
Conversation
Remove the given number of leading path elements from the tar member names when creating the archive items; members whose path has fewer or equally many elements are silently skipped (same semantics as extract / export-tar). Hard link targets are stripped accordingly so they keep referencing their target's chunks; symbolic link targets are content and are left unchanged. Also works for BORG format tars, where the items are restored from pax headers. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #10220 +/- ##
==========================================
+ Coverage 87.20% 87.29% +0.09%
==========================================
Files 102 102
Lines 18394 18470 +76
Branches 2829 2839 +10
==========================================
+ Hits 16040 16124 +84
+ Misses 1644 1639 -5
+ Partials 710 707 -3 ☔ View full report in Codecov by Harness. |
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.
Fixes #6461.
Add
--strip-componentstoborg import-tar, with the same semantics as the existing option ofborg extract/borg export-tar: remove the given number of leading path elements from the tar member names when creating the archive items; members whose path has fewer or equally many elements are silently skipped.Details:
define_exclude_and_patternsinto a shareddefine_strip_componentshelper, so all commands use the identical definition/help text (no behavior change for extract/export-tar/mount)._import_tarmember loop, counting components of the normalized stored path (make_path_safe(posixpath.normpath(name))), consistent with howTarfileObjectProcessorscomputes item paths.TarfileObjectProcessors.create_helper, so it also covers BORG-format tars, where items are restored from theBORG.item.metapax header andtarinfo.nameis not consulted.HardLinkManagerand still reuse their target's chunks; a hard link whose target was skipped is skipped, too.Tests: basic stripping incl.
./-prefixed member names and the strip-everything → empty archive case, hardlink/symlink behavior, and a BORG-format round-trip exercising the pax fast path.🤖 Generated with Claude Code