Repository navigation
extract: add -O/--to-stdout - #403
ozenyunus35 wants to merge 4 commits into
Conversation
With -O, the contents of regular members are written to standard output instead of being created on disk, like GNU tar. Other member types are skipped, and -v output goes to standard error so it doesn't mix with the contents. Closes uutils#196
Merging this PR will not alter performance
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #403 +/- ##
==========================================
+ Coverage 96.84% 97.88% +1.03%
==========================================
Files 11 15 +4
Lines 1492 1893 +401
Branches 29 42 +13
==========================================
+ Hits 1445 1853 +408
+ Misses 46 39 -7
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:
|
GNU Testsuite Comparison |
GNU Testsuite Comparison |
| Box::new(io::stdout().lock()) | ||
| }; | ||
| let mut out = BufWriter::new(status); | ||
| let mut data = BufWriter::new(io::stdout().lock()); |
There was a problem hiding this comment.
do we need to lock stdout a second time when to_stdout is false?
maybe an Option or just reuse out
There was a problem hiding this comment.
No, it's an Option now and only locked with -O.
| // Like GNU tar, only regular files have contents to write. | ||
| if entry.header().entry_type().is_file() { | ||
| out.flush().map_err(TarError::Io)?; | ||
| io::copy(&mut entry, &mut data).map_err(|e| TarError::CannotExtract { |
There was a problem hiding this comment.
could you please flush data after each member too?
with -xvOf a.tar 2>&1 all the names come out before all the contents, GNU interleaves them
There was a problem hiding this comment.
Done, data is flushed after each member.
| at.write("dir/a.txt", "first\n"); | ||
| at.write("dir/b.txt", "second\n"); | ||
| ts.ucmd() | ||
| .args(&["-cf", "archive.tar", "dir/a.txt", "dir/b.txt"]) |
There was a problem hiding this comment.
please archive dir itself too and check that it isn't created with -O
this way the "only regular files" path is tested
There was a problem hiding this comment.
Added: it archives a directory, extracts it with -O and checks the directory isn't created.
| } | ||
|
|
||
| out.flush().map_err(TarError::Io)?; | ||
| if let Some(data) = data.as_mut() { |
There was a problem hiding this comment.
do we still need this? data is already flushed after each member
GNU Testsuite Comparison |
# Conflicts: # src/uu/tar/src/tar.rs # tests/by-util/test_tar.rs
GNU Testsuite Comparison |
|
Closing this, as I can't follow up on it further. Thanks for the reviews. |
Closes #196
With
-O/--to-stdout, extract writes the contents of regular members to standard output instead of creating them, like GNU tar. Other member types (directories, links, ...) are skipped. With-v, the member names go to standard error so they don't mix with the contents.extract_archivegets ato_stdoutflag; the unit test and bench callers passfalse. Addedtest_extract_to_stdout, which checks that nothing is written to disk and the-voutput goes to stderr.I used an AI assistant to help draft parts of the code and tests; I reviewed the changes and ran the tests myself.