From 5745b5fad239e252a7c3b3228acdfeb1a589a63b Mon Sep 17 00:00:00 2001 From: Camille Mougey Date: Thu, 21 Dec 2023 14:55:01 +0100 Subject: [PATCH 1/3] mlar: on linear extract, add verbose output --- mlar/src/main.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mlar/src/main.rs b/mlar/src/main.rs index 240eee3..52ec3d7 100644 --- a/mlar/src/main.rs +++ b/mlar/src/main.rs @@ -454,6 +454,10 @@ struct FileWriter<'a> { /// Reference on the cache // A `Mutex` is used instead of a `RefCell` as `FileWriter` can be `Send` cache: &'a Mutex>, + /// Is verbose mode enabled + verbose: bool, + /// Filename in the archive + fname: &'a str } /// Max number of fd simultaneously opened @@ -466,6 +470,9 @@ impl<'a> Write for FileWriter<'a> { if !cache.contains(&self.path) { let file = fs::OpenOptions::new().append(true).open(&self.path)?; cache.put(self.path.clone(), file); + if self.verbose { + println!("{}", self.fname); + } } // Safe to `unwrap` here cause we ensure the element is in the cache (mono-threaded) let file = cache.get_mut(&self.path).unwrap(); @@ -603,6 +610,8 @@ fn extract(matches: &ArgMatches) -> Result<(), MlarError> { FileWriter { path, cache: &cache, + verbose, + fname }, ); } From 652670214ed627fcbd1c6aad6550349dab899a06 Mon Sep 17 00:00:00 2001 From: Camille Mougey Date: Thu, 21 Dec 2023 15:07:00 +0100 Subject: [PATCH 2/3] Test: update with mlar extract -v --- mlar/tests/integration.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mlar/tests/integration.rs b/mlar/tests/integration.rs index 9d37ddd..650b6ab 100644 --- a/mlar/tests/integration.rs +++ b/mlar/tests/integration.rs @@ -834,7 +834,7 @@ fn test_extract() { println!("{cmd:?}"); let assert = cmd.assert(); - assert.success().stdout(file_list); + assert.success().stdout(file_list.clone()); ensure_directory_content(output_dir.path(), &testfs.files); @@ -852,9 +852,13 @@ fn test_extract() { println!("{cmd:?}"); let assert = cmd.assert(); + let expected_output = format!( + "Extracting the whole archive using a linear extraction\n{}", + file_list + ); assert .success() - .stdout("Extracting the whole archive using a linear extraction\n"); + .stdout(expected_output); ensure_directory_content(output_dir.path(), &testfs.files); @@ -1317,7 +1321,7 @@ fn test_extract_lot_files() { println!("{:?}", cmd); let assert = cmd.assert(); - assert.success().stdout(file_list); + assert.success().stdout(file_list.clone()); ensure_directory_content(output_dir.path(), &testfs.files); @@ -1335,9 +1339,13 @@ fn test_extract_lot_files() { println!("{:?}", cmd); let assert = cmd.assert(); + let expected_output = format!( + "Extracting the whole archive using a linear extraction\n{}", + file_list + ); assert .success() - .stdout("Extracting the whole archive using a linear extraction\n"); + .stdout(expected_output); ensure_directory_content(output_dir.path(), &testfs.files); From 978a3c86a0591ae359bdfe9652bab8574791c05c Mon Sep 17 00:00:00 2001 From: Camille Mougey Date: Thu, 21 Dec 2023 15:07:29 +0100 Subject: [PATCH 3/3] cargo fmt --- mlar/src/main.rs | 4 ++-- mlar/tests/integration.rs | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/mlar/src/main.rs b/mlar/src/main.rs index 52ec3d7..5641c8d 100644 --- a/mlar/src/main.rs +++ b/mlar/src/main.rs @@ -457,7 +457,7 @@ struct FileWriter<'a> { /// Is verbose mode enabled verbose: bool, /// Filename in the archive - fname: &'a str + fname: &'a str, } /// Max number of fd simultaneously opened @@ -611,7 +611,7 @@ fn extract(matches: &ArgMatches) -> Result<(), MlarError> { path, cache: &cache, verbose, - fname + fname, }, ); } diff --git a/mlar/tests/integration.rs b/mlar/tests/integration.rs index 650b6ab..740ef63 100644 --- a/mlar/tests/integration.rs +++ b/mlar/tests/integration.rs @@ -856,9 +856,7 @@ fn test_extract() { "Extracting the whole archive using a linear extraction\n{}", file_list ); - assert - .success() - .stdout(expected_output); + assert.success().stdout(expected_output); ensure_directory_content(output_dir.path(), &testfs.files); @@ -1343,9 +1341,7 @@ fn test_extract_lot_files() { "Extracting the whole archive using a linear extraction\n{}", file_list ); - assert - .success() - .stdout(expected_output); + assert.success().stdout(expected_output); ensure_directory_content(output_dir.path(), &testfs.files);