Skip to content

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

Merged
ThomasWaldmann merged 6 commits into
borgbackup:masterfrom
ThomasWaldmann:import-tar-strip-components-6461
Sep 20, 2026
Merged

ThomasWaldmann merged 6 commits 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

@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.25%. Comparing base (6489248) to head (219d145).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

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.
📢 Have feedback on the report? Share it here.

ThomasWaldmann and others added 6 commits September 19, 2026 23:00
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
ThomasWaldmann force-pushed the import-tar-strip-components-6461 branch from a354921 to 219d145 Compare September 19, 2026 21:02
@ThomasWaldmann
ThomasWaldmann merged commit 177d09c into borgbackup:master Sep 20, 2026
61 of 63 checks passed
@ThomasWaldmann
ThomasWaldmann deleted the import-tar-strip-components-6461 branch September 20, 2026 17:38
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