From 74ef63ceea11b09c2d5af757cc8d50c463187e9b Mon Sep 17 00:00:00 2001 From: Jay Hemnani <193022578+jayhemnani9910@users.noreply.github.com> Date: Mon, 26 Oct 2026 01:14:21 +0530 Subject: [PATCH 1/2] extract: print only the member names with -v -xv printed an 'Extracting archive: NAME' line before the members. GNU tar prints only the member names. --- benches/bench_tar.rs | 8 +------- src/uu/tar/src/operations/extract.rs | 7 ------- src/uu/tar/src/operations/extract_tests.rs | 2 +- src/uu/tar/src/tar.rs | 4 ++-- tests/by-util/test_tar.rs | 20 ++++++++++++++++++++ 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/benches/bench_tar.rs b/benches/bench_tar.rs index 555a1f8..aae35f0 100644 --- a/benches/bench_tar.rs +++ b/benches/bench_tar.rs @@ -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(); } diff --git a/src/uu/tar/src/operations/extract.rs b/src/uu/tar/src/operations/extract.rs index cf465bf..192e04a 100644 --- a/src/uu/tar/src/operations/extract.rs +++ b/src/uu/tar/src/operations/extract.rs @@ -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 @@ -28,7 +27,6 @@ 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<()> { @@ -36,11 +34,6 @@ pub fn extract_archive( 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; diff --git a/src/uu/tar/src/operations/extract_tests.rs b/src/uu/tar/src/operations/extract_tests.rs index 898caff..9332d45 100644 --- a/src/uu/tar/src/operations/extract_tests.rs +++ b/src/uu/tar/src/operations/extract_tests.rs @@ -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!( diff --git a/src/uu/tar/src/tar.rs b/src/uu/tar/src/tar.rs index 73c8225..78e4101 100644 --- a/src/uu/tar/src/tar.rs +++ b/src/uu/tar/src/tar.rs @@ -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) }; } diff --git a/tests/by-util/test_tar.rs b/tests/by-util/test_tar.rs index afbc074..eede1f3 100644 --- a/tests/by-util/test_tar.rs +++ b/tests/by-util/test_tar.rs @@ -328,6 +328,26 @@ fn test_extract_single_file() { assert_eq!(at.read("original.txt"), "test content"); } +#[test] +fn test_extract_verbose_lists_only_members() { + // Like GNU tar, -xv prints the member names and nothing else. + let (at, mut ucmd) = at_and_ucmd!(); + at.write("file1.txt", "content1"); + at.mkdir("dir"); + at.write("dir/file2.txt", "content2"); + ucmd.args(&["-cf", "archive.tar", "file1.txt", "dir/file2.txt"]) + .succeeds(); + at.remove("file1.txt"); + at.remove("dir/file2.txt"); + + new_ucmd!() + .arg("-xvf") + .arg(at.plus("archive.tar")) + .current_dir(at.as_string()) + .succeeds() + .stdout_only("file1.txt\ndir/file2.txt\n"); +} + #[test] fn test_extract_verbose() { let (at, mut ucmd) = at_and_ucmd!(); From f3fa931119dd3b814902be255f22094df52fefee Mon Sep 17 00:00:00 2001 From: Jay Hemnani <193022578+jayhemnani9910@users.noreply.github.com> Date: Tue, 27 Oct 2026 12:29:11 +0530 Subject: [PATCH 2/2] extract: check the -v output in test_extract_verbose instead of a new test --- tests/by-util/test_tar.rs | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/tests/by-util/test_tar.rs b/tests/by-util/test_tar.rs index eede1f3..293d2fe 100644 --- a/tests/by-util/test_tar.rs +++ b/tests/by-util/test_tar.rs @@ -328,26 +328,6 @@ fn test_extract_single_file() { assert_eq!(at.read("original.txt"), "test content"); } -#[test] -fn test_extract_verbose_lists_only_members() { - // Like GNU tar, -xv prints the member names and nothing else. - let (at, mut ucmd) = at_and_ucmd!(); - at.write("file1.txt", "content1"); - at.mkdir("dir"); - at.write("dir/file2.txt", "content2"); - ucmd.args(&["-cf", "archive.tar", "file1.txt", "dir/file2.txt"]) - .succeeds(); - at.remove("file1.txt"); - at.remove("dir/file2.txt"); - - new_ucmd!() - .arg("-xvf") - .arg(at.plus("archive.tar")) - .current_dir(at.as_string()) - .succeeds() - .stdout_only("file1.txt\ndir/file2.txt\n"); -} - #[test] fn test_extract_verbose() { let (at, mut ucmd) = at_and_ucmd!(); @@ -364,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"));