tar: add --wildcards and --strip-components flags#313
Open
nnosal wants to merge 4 commits into
Open
Conversation
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 Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…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.
Contributor
Merging this PR will degrade performance by 11.48%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
…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
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.
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.