import-tar: add --strip-components - #10220
Merged
ThomasWaldmann merged 6 commits intoSep 20, 2026
Merged
ThomasWaldmann merged 6 commits into
ThomasWaldmann merged 6 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #10220 +/- ##
==========================================
+ Coverage 88.23% 88.25% +0.01%
==========================================
Files 103 103
Lines 18876 18898 +22
Branches 2933 2938 +5
==========================================
+ Hits 16656 16678 +22
Misses 1544 1544
Partials 676 676 ☔ View full report in Codecov by Harness. |
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>
The path elements are counted on the normalized member name, so a leading "./" is not a path element. GNU tar and bsdtar count it, so the same tarball needs a count that is higher by one there. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…atus output Regular files were listed with their stripped path, all other member types with the unstripped tar member name. Show the stripped path for all of them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… member Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… test The BORG tar format transfers the hlid in the BORG.item.meta pax header, so hard links do not become separate files there. Keep them in the test input, so the test also covers hard links plus stripping for the pax header path. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Regular files were listed with the path stored in the archive, all other member types with the raw tar member name, e.g. "./dir" instead of "dir". Show the stored path for all of them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
ThomasWaldmann
force-pushed
the
import-tar-strip-components-6461
branch
from
September 19, 2026 21:02
a354921 to
219d145
Compare
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