Skip to content

tar: add --wildcards and --strip-components flags#313

Open
nnosal wants to merge 4 commits into
uutils:mainfrom
nnosal:feat/wildcards-strip
Open

tar: add --wildcards and --strip-components flags#313
nnosal wants to merge 4 commits into
uutils:mainfrom
nnosal:feat/wildcards-strip

Conversation

@nnosal

@nnosal nnosal commented Jun 30, 2026

Copy link
Copy Markdown

Add --wildcards and --strip-components=N flags to extract (-x) and
list (-t) operations.

With --wildcards, positional file arguments are treated as glob patterns
(* and ?) rather than exact names. Pattern matching converts glob syntax
to a regex via the already-present regex crate, so no new dependency is
needed.

With --strip-components=N, the first N path components are removed from
each entry name before extraction or display. Entries with fewer than N
components are skipped silently, matching GNU tar behaviour.

New helpers wildcard_match, entry_matches, and strip_leading_components
live in operations/mod.rs and are shared between extract.rs and list.rs.
Unit tests cover all three helpers; integration tests verify filtering,
glob patterns, stripping, and combined use of both flags.

Closes #186, closes #195.

Implements two GNU tar compatibility flags for extract and list modes:

- --wildcards: treat positional file arguments as glob patterns when
  filtering archive entries (* matches any string, ? matches any char)
- --strip-components=N: strip N leading path components from entry
  paths; entries that become empty after stripping are silently skipped

Shared helpers are added in operations/mod.rs:
  strip_leading_components(), wildcard_match(), entry_matches()

Closes uutils#186, closes uutils#195
@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.67675% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.07%. Comparing base (791ae26) to head (090abe1).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
src/uu/tar/src/operations/extract.rs 80.55% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #313      +/-   ##
==========================================
+ Coverage   96.84%   98.07%   +1.22%     
==========================================
  Files          11       15       +4     
  Lines        1492     2235     +743     
  Branches       29       50      +21     
==========================================
+ Hits         1445     2192     +747     
+ Misses         46       42       -4     
  Partials        1        1              
Flag Coverage Δ
macos_latest 98.07% <98.67%> (+1.22%) ⬆️
ubuntu_latest 98.07% <98.67%> (+1.22%) ⬆️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…natures

list_archive and extract_archive now take three additional arguments
(file_patterns, wildcards, strip_components). Pass neutral defaults
(&[], false, 0) at the benchmark call sites so the benchmarks compile
and measure the same workload as before.
@codspeed-hq

codspeed-hq Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 11.48%

❌ 1 regressed benchmark
✅ 6 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
build_cli_command 44.3 µs 50 µs -11.48%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing nnosal:feat/wildcards-strip (090abe1) with main (9aa518b)

Open in CodSpeed

nnosal added 2 commits June 30, 2026 13:07
…sal safety

Cover the three uncovered code paths in extract_archive:
- verbose output when strip_components > 0 (lines 76-78)
- create_dir_all for non-empty parent after stripping (line 82)
- path-traversal rejection for entries with ".." after strip (lines 68-74)
- Reformat two long list_archive calls in bench_tar.rs to satisfy rustfmt
- Replace make_plain_tar (which the tar crate rejects for paths with "..") with
  make_raw_traversal_tar that writes POSIX tar bytes directly, enabling tests
  for malicious archives with path-traversal components
@nnosal nnosal marked this pull request as ready for review July 3, 2026 06:37
@nnosal nnosal requested a review from kaladron as a code owner July 3, 2026 06:37
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.

GNU tar compatibility: Add --strip-components=NUMBER GNU tar compatibility: Add --wildcards / --no-wildcards

1 participant