Repository navigation
extract: add -O/--to-stdout #403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
252d371
367c2f1
41d123a
60f77fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,8 @@ use std::io::{Cursor, Read, Write}; | |
| use std::path::{self, PathBuf}; | ||
|
|
||
| use tar_rs_crate::{Archive as TarRsArchive, Builder as TarRsBuilder, Header as TarRsHeader}; | ||
| use uutests::{at_and_ucmd, new_ucmd}; | ||
| use uutests::util::TestScenario; | ||
| use uutests::{at_and_ucmd, new_ucmd, util_name}; | ||
|
|
||
| /// Size of a single tar block in bytes (per POSIX specification). | ||
| // TODO: This should be exported from the tar crate instead of being redefined here. | ||
|
|
@@ -86,6 +87,50 @@ fn test_create_dir_verbose() { | |
| .stdout_contains(file2_path); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_extract_to_stdout() { | ||
| let ts = TestScenario::new(util_name!()); | ||
| let at = &ts.fixtures; | ||
|
|
||
| at.mkdir("dir"); | ||
| 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"]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please archive
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added: it archives a directory, extracts it with -O and checks the directory isn't created. |
||
| .succeeds(); | ||
| at.remove("dir/a.txt"); | ||
| at.remove("dir/b.txt"); | ||
|
|
||
| ts.ucmd() | ||
| .args(&["-xOf", "archive.tar"]) | ||
| .succeeds() | ||
| .stdout_only("first\nsecond\n"); | ||
| // The contents went to stdout, so nothing was written to disk. | ||
| assert!(!at.file_exists("dir/a.txt")); | ||
| assert!(!at.file_exists("dir/b.txt")); | ||
|
|
||
| // With -v, the member names go to stderr so they don't mix with the contents | ||
| ts.ucmd() | ||
| .args(&["-xvf", "archive.tar", "--to-stdout"]) | ||
| .succeeds() | ||
| .stdout_is("first\nsecond\n") | ||
| .stderr_contains("dir/a.txt") | ||
| .stderr_contains("dir/b.txt"); | ||
| assert!(!at.file_exists("dir/a.txt")); | ||
|
|
||
| // A directory member has no contents, and -O doesn't create it either | ||
| at.mkdir("only"); | ||
| at.write("only/c.txt", "third\n"); | ||
| ts.ucmd().args(&["-cf", "dir.tar", "only"]).succeeds(); | ||
| at.remove("only/c.txt"); | ||
| at.rmdir("only"); | ||
| ts.ucmd() | ||
| .args(&["-xOf", "dir.tar"]) | ||
| .succeeds() | ||
| .stdout_only("third\n"); | ||
| assert!(!at.dir_exists("only")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_create_no_recursion() { | ||
| let (at, mut ucmd) = at_and_ucmd!(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we still need this?
datais already flushed after each member