Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions benches/bench_tar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,7 @@ fn extract_archive_20_files(bencher: divan::Bencher) {
.bench_local_values(|extract_dir| {
std::env::set_current_dir(extract_dir.path()).unwrap();
let input = File::open(&archive_path).unwrap();
operations::extract::extract_archive(
input,
&archive_path,
false,
CompressionMode::None,
)
.unwrap();
operations::extract::extract_archive(input, false, CompressionMode::None).unwrap();
});
std::env::set_current_dir(original_dir).unwrap();
}
Expand Down
7 changes: 0 additions & 7 deletions src/uu/tar/src/operations/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use uucore::error::UResult;
///
/// # Arguments
///
/// * `archive_path` - Path to the tar archive to extract
/// * `verbose` - Whether to print verbose output during extraction
///
/// # Errors
Expand All @@ -28,19 +27,13 @@ use uucore::error::UResult;
/// - Files cannot be extracted due to I/O or permission errors
pub fn extract_archive(
input: impl Read,
archive_path: &Path,
verbose: bool,
compression: CompressionMode,
) -> UResult<()> {
let reader = open_archive_reader(input, compression)?;
let mut archive = Archive::new(reader);
let mut out = BufWriter::new(io::stdout().lock());

// Extract to current directory
if verbose {
writeln!(out, "Extracting archive: {}", archive_path.display()).map_err(TarError::Io)?;
}

// Members that were refused are reported as they are met; like GNU tar, the
// remaining members are still extracted and the exit status records the failure.
let mut refused_member = false;
Expand Down
2 changes: 1 addition & 1 deletion src/uu/tar/src/operations/extract_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn test_extract_archive_with_zstd() {

let _guard = crate::operations::TestDirGuard::enter(tempdir.path());
let input = fs::File::open(&archive_path).unwrap();
let result = extract_archive(input, &archive_path, true, CompressionMode::Zstd);
let result = extract_archive(input, true, CompressionMode::Zstd);

result.unwrap();
assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions src/uu/tar/src/tar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

let compression = explicit_compression.unwrap_or(CompressionMode::Auto);
return if archive_path == Path::new("-") {
operations::extract::extract_archive(io::stdin(), archive_path, verbose, compression)
operations::extract::extract_archive(io::stdin(), verbose, compression)
} else {
let file =
File::open(archive_path).map_err(|e| TarError::from_io_error(e, archive_path))?;
operations::extract::extract_archive(file, archive_path, verbose, compression)
operations::extract::extract_archive(file, verbose, compression)
};
}

Expand Down
14 changes: 4 additions & 10 deletions tests/by-util/test_tar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,19 +344,13 @@ fn test_extract_verbose() {
at.remove("file2.txt");
at.remove("file3.txt");

// Extract with verbose
let result = new_ucmd!()
// Extract with verbose: like GNU tar, only the member names are printed
new_ucmd!()
.arg("-xvf")
.arg(at.plus("archive.tar"))
.current_dir(at.as_string())
.succeeds();

let stdout = result.stdout_str();

// Verify all files are listed in verbose output
assert!(stdout.contains("file1.txt"));
assert!(stdout.contains("file2.txt"));
assert!(stdout.contains("file3.txt"));
.succeeds()
.stdout_only("file1.txt\nfile2.txt\nfile3.txt\n");

// Verify files were extracted
assert!(at.file_exists("file1.txt"));
Expand Down
Loading