Skip to content

import-tar: add --strip-components - #10220

Open
ThomasWaldmann wants to merge 1 commit into
borgbackup:masterfrom
ThomasWaldmann:import-tar-strip-components-6461
Open

import-tar: add --strip-components#10220
ThomasWaldmann wants to merge 1 commit into
borgbackup:masterfrom
ThomasWaldmann:import-tar-strip-components-6461

Conversation

@ThomasWaldmann

Copy link
Copy Markdown
Member

Fixes #6461.

Add --strip-components to borg import-tar, with the same semantics as the existing option of borg 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:

  • The option definition is factored out of define_exclude_and_patterns into a shared define_strip_components helper, so all commands use the identical definition/help text (no behavior change for extract/export-tar/mount).
  • The skip decision happens in the _import_tar member loop, counting components of the normalized stored path (make_path_safe(posixpath.normpath(name))), consistent with how TarfileObjectProcessors computes item paths.
  • The path rewrite happens in TarfileObjectProcessors.create_helper, so it also covers BORG-format tars, where items are restored from the BORG.item.meta pax header and tarinfo.name is not consulted.
  • Hard link targets are stripped the same way, so LNKTYPE members keep matching the stripped paths remembered in the HardLinkManager and still reuse their target's chunks; a hard link whose target was skipped is skipped, too.
  • Symbolic link targets are left unchanged (they are content, matching GNU tar behavior).

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

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

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.29%. Comparing base (2491d56) to head (b7e5754).
⚠️ Report is 42 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/borg/archiver/tar_cmds.py 84.61% 1 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

borg import-tar / create / recreate: add --strip-components

1 participant