25 Commits

Author SHA1 Message Date
Jeff Bailey 8d4fef7aba tar: refuse to write archive to terminal, lock stdout, and buffer output 2026-06-07 12:18:30 +01:00
Jeff Bailey 3be98e9e5c tar: support -f - for stdin/stdout archives
When the archive path is "-", read archives from stdin for list and
extract, and write archive data to stdout for create.

Route create status output to stderr when writing the archive to
stdout so verbose output does not corrupt the stream. Add CLI tests
for create-to-stdout, list-from-stdin, extract-from-stdin, and the
stderr routing cases.
2026-06-07 11:19:50 +01:00
Valentin 4986a8460c Absolute Paths Support for Archives Creation (#291)
Added support for -P and --absolute-names flags to preserve absolute
paths when creating archives, matching GNU tar behavior.

* CLI: Added -P / --absolute-names options to uu_app.
* Operations: Configured tar::Builder to preserve absolute paths
  based on the new flag.
* Normalization: Updated normalize_path to skip stripping root
  and prefix components when absolute paths are allowed.
* Tests: Added integration tests for path preservation and trimming
  during archive creation and extraction.
2026-06-01 20:53:03 +01:00
oech3 42f9d3722f remove 1 unsafe (#284)
Co-authored-by: Jeff Bailey <jbailey@raspberryginger.com>
2026-05-17 08:53:39 +01:00
Daniel Hofstetter 60918b50b1 tests.rs: adapt to ctor change 2026-05-07 09:38:09 +02:00
Jeff Bailey 06042058f9 tar: add -t/--list operation
Implement the list operation. Non-verbose (-t) prints one entry path
per line. Verbose (-tv) prints permissions, owner/group, size,
modification time, and path — matching GNU tar's ls-l style output.

Adds conflict group so -c, -x, and -t are mutually exclusive.

Pulls in chrono for timestamp formatting in verbose output. chrono is
already in the workspace dependency set and will also be needed for
date parsing when --newer=DATE is implemented.

Point uucore/uutests at the coreutils git repo while we're iterating
quickly on basic functionality.
2026-04-03 10:13:30 +02:00
Jeff Bailey 42a1c34222 Add POSIX keystring parsing and argv pre-expansion (#114)
Support traditional key syntax (for example `tar cvf archive.tar file`)
by rewriting a leading key operand into clap-compatible short options
before argument parsing.

- detect valid keystrings in argv[1]
- expand key letters into `-<opt>` arguments
- consume operands for `f` and `b` in key order
- forward `-b` (currently unsupported) so key/dash forms fail consistently
- update usage text to document key syntax
- add unit tests for key detection/expansion
- add integration tests for create/extract parity and `-b` failure parity

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-03-25 18:22:14 +01:00
Jeff Bailey 3dfb724997 Add test documentation and expand CLI test coverage (#46)
* Add test documentation and expand CLI test coverage

Document testing philosophy and expand test suite with better CLI-focused
tests and improved error verification.

Changes:
- Add tests/README.md documenting testing philosophy separating application
  (CLI interface) from library (archive format) testing concerns
- Update README.md with Testing section linking to test documentation
- Add 23 new CLI-focused tests covering:
  * Basic CLI: conflicting operations, missing operation specification
  * Create operations: directory archiving, verbose output, empty archive
    handling, nonexistent file errors
  * Extract operations: verbose output, directory structure preservation
  * Round-trip tests: single/multiple files, directories, empty files,
    special characters in filenames
  * Error handling: permission denied, corrupted archives, dash-prefixed
    filenames with -- separator
  * Verbose output: format verification for create/extract operations
  * CLI parsing: mixed short/long options, option order variations,
    default overwrite behavior
  * Edge cases: filenames with spaces, large file counts (100 files)
- Improve all 8 existing tests with better error verification:
  * Add exit code checks and stderr pattern matching
  * Add no_stderr() assertions for successful operations
  * Add sanity checks for archive file sizes
  * Add TODO comments noting exit code mismatches (usage errors currently
    return 1 instead of documented 64)
- Reorganize tests with clear section headers:
  1. Basic CLI Tests
  2. Create Operation Tests
  3. Extract Operation Tests
  4. Round-trip Tests
  5. Error Handling and Exit Code Tests
  6. Verbose Output Format Tests
  7. CLI Argument Handling Tests
  8. Edge Case Tests

All 31 tests pass. Test suite now has clear documentation explaining what
should be tested at the application level vs library level.

* Align exit codes with GNU tar and modernize tests

- Refactor `uumain` to manually handle `clap` errors, ensuring exit code 64 for command-line syntax errors and exit code 2 for semantic/fatal errors.
- Add mutual exclusion between `--create` and `--extract` operations.
- Update `README.md` and `tests/README.md` with corrected exit code documentation and clarified testing philosophy.
- Modernize `tests/by-util/test_tar.rs`:
    - Define `TAR_BLOCK_SIZE` constant (512 bytes).
    - Use `uutests` convenience methods (`at.touch()`, `at.rmdir()`, etc.).
    - Improve `test_verbose` to use `PathBuf`.
    - Replace `.no_stderr()` with `.no_output()`.
    - Implement a root-user check in `test_create_permission_denied`.
    - Remove redundant or outdated roundtrip and verbose format tests.

* Add missing [test] annotation.

---------

Co-authored-by: Sylvestre Ledru <sylvestre.ledru@gmail.com>
2026-03-08 21:36:45 +01:00
Valentin 17d5195710 Remove leading slash from file name if path is absolute (#53) 2026-02-14 22:18:40 +01:00
Valentin 9566b2e3f8 Add output of files to be included to archive if verbose flag passed (#62)
* Add output of files to be included to archive if verbose flag passed

* Add test for verbose output

* Fix test

* Fix style
2025-12-16 11:21:39 +01:00
Jeff Bailey aa5fb1a952 Implement minimal create and extract operations (#35)
* Implement minimal create and extract operations

Adds basic tar archive functionality using tar-rs library with proper
error handling infrastructure.

Core Implementation:
- TarError enum implementing UError for uucore integration
- Extract operation (-x) for unpacking tar archives
- Create operation (-c) for creating tar archives from files/directories
- Verbose mode (-v) for both operations
- Proper CLI argument parsing with -f flag for archive file

Error Handling:
- Comprehensive error types (IoError, InvalidArchive, FileNotFound, etc.)
- Proper error conversion from io::Error
- UError trait implementation for exit code handling

This provides the minimal foundation for tar functionality. Both create
and extract are included together since they depend on each other for
testing purposes.

Includes 18 tests total:
- 8 integration tests (CLI basics, create/extract operations, error handling)
- 10 unit tests (CLI flag parsing, error type handling)
- Unit tests organized in src/uu/tar/tests/ separate from implementation

Note: Run `cargo test --workspace` to execute all tests including unit tests.

* Re-add cognitive complexity warning suppression for uu_app function

* Sort out tar/tarapp conflict

Rename package from "tar" to "tarapp" in Cargo.toml and update
dependencies to use workspace for tar.

* fix(errors): improve error handling and exit codes for tar operations

- Updated error messages for file not found and permission denied cases.
- Fix exit codes for various TarError types to conform to standard.
- Refactored extract_archive to use new error handling.
- Adjusted tests to reflect updated exit codes.

* Update for error changes (fixes cargo test --all)

* Use arg! macro and comment out rather than remove the unimplemented items.

* fix(create): Remove duplicate message for missing files in create_archive

---------

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2025-11-22 09:54:00 +01:00
Sylvestre Ledru 5f5f94f6a5 fix various items 2025-09-24 20:53:22 +02:00
Sylvestre Ledru fb21ec44f4 tests: move to uutests 2025-04-04 09:37:44 +02:00
Diomidis Spinellis 4a29612ec1 Move unit tests to the respective source code file
This is best practice and avoids unneeded pub modifiers.
2025-03-20 18:56:16 +02:00
Diomidis Spinellis 952594bf91 Handle script and file arguments
Their handling differs from the XBD 12.2 Utility Syntax Guidelines,
because the order of presentation of the -e and -f options is significant.
2025-03-19 21:17:46 +02:00
Daniel Hofstetter 5240ffd593 Enable ignored test 2025-03-06 10:28:21 +01:00
Daniel Hofstetter c6d375eb3d Rename multi-call binary from sed to sedapp 2025-03-06 10:28:03 +01:00
Daniel Hofstetter a4dc314c49 Ignore failing test 2025-03-05 15:32:09 +01:00
Diomidis Spinellis 6178c89e59 Improve arg handling to match sed requirements 2025-03-04 10:42:00 +02:00
Diomidis Spinellis a9395f56be Test required script argument 2025-03-03 17:01:54 +02:00
Diomidis Spinellis f60c885d18 Substitute procps for sed 2025-03-03 12:28:04 +02:00
Daniel Hofstetter 782e4bd94e tests: adapt to rand API changes 2025-02-25 09:47:52 +01:00
Daniel Hofstetter 4b36e2b551 Fix warnings in test 2025-02-24 16:02:40 +01:00
Daniel Hofstetter c0387ed7eb tests: fix warnings in testing framework 2025-02-24 16:00:59 +01:00
Sylvestre Ledru 495de53f0d empty sed for reimplementation 2025-02-01 18:07:27 +01:00