Skip to content

tar: add --backup[=CONTROL] and --suffix options#315

Draft
nnosal wants to merge 1 commit into
uutils:mainfrom
nnosal:feat/backup
Draft

tar: add --backup[=CONTROL] and --suffix options#315
nnosal wants to merge 1 commit into
uutils:mainfrom
nnosal:feat/backup

Conversation

@nnosal

@nnosal nnosal commented Jun 30, 2026

Copy link
Copy Markdown

Summary

Implements --backup[=CONTROL] and --suffix=STRING extraction options as described in issue #250.

  • --backup (no value) backs up existing files using the existing strategy (numbered if .~1~ present, otherwise simple).
  • --backup=CONTROL accepts none/off, simple/never, numbered/t, existing/nil.
  • --suffix=STRING overrides the default suffix (~) used by the simple backup strategy.

Backup logic lives in src/uu/tar/src/operations/extract.rs. The three helper functions (simple_backup_path, numbered_backup_path, backup_file) are pure and independently testable.

Test plan

  • cargo test --all passes (113 tests including 9 new backup-specific unit tests)
  • cargo fmt --all -- --check clean
  • cargo clippy --workspace --all-targets -ptarapp -D warnings clean
  • Unit tests cover all four BackupControl variants, custom suffix, no-op when no existing file, numbered increment, and existing fallback logic

Fixes #250

Back up existing files before overwriting during extraction.
CONTROL may be none/off, simple/never, numbered/t, existing/nil
(default when flag is given: existing). --suffix overrides the
simple backup suffix (default: ~).

Related to uutils#250
@codspeed-hq

codspeed-hq Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 11.61%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 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.1 µs -11.61%

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/backup (bb83a62) with main (9aa518b)

Open in CodSpeed

@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.80165% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.26%. Comparing base (791ae26) to head (bb83a62).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
src/uu/tar/src/tar.rs 75.60% 10 Missing ⚠️
src/uu/tar/src/operations/extract.rs 85.71% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #315      +/-   ##
==========================================
+ Coverage   96.84%   97.26%   +0.41%     
==========================================
  Files          11       15       +4     
  Lines        1492     1976     +484     
  Branches       29       37       +8     
==========================================
+ Hits         1445     1922     +477     
- Misses         46       53       +7     
  Partials        1        1              
Flag Coverage Δ
macos_latest 97.26% <93.80%> (+0.41%) ⬆️
ubuntu_latest 97.26% <93.80%> (+0.41%) ⬆️
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.

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 --backup[=CONTROL] / --suffix=STRING

1 participant