Skip to content

Commit

Permalink
Merge pull request #185 from ANSSI-FR/verbose-linear-extract
Browse files Browse the repository at this point in the history
Homogeneise `mlar extract -v` output
  • Loading branch information
commial committed Jan 8, 2024
2 parents ed49793 + 978a3c8 commit 5342417
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
9 changes: 9 additions & 0 deletions mlar/src/main.rs
Expand Up @@ -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<LruCache<PathBuf, File>>,
/// Is verbose mode enabled
verbose: bool,
/// Filename in the archive
fname: &'a str,
}

/// Max number of fd simultaneously opened
Expand All @@ -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();
Expand Down Expand Up @@ -603,6 +610,8 @@ fn extract(matches: &ArgMatches) -> Result<(), MlarError> {
FileWriter {
path,
cache: &cache,
verbose,
fname,
},
);
}
Expand Down
20 changes: 12 additions & 8 deletions mlar/tests/integration.rs
Expand Up @@ -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);

Expand All @@ -852,9 +852,11 @@ fn test_extract() {

println!("{cmd:?}");
let assert = cmd.assert();
assert
.success()
.stdout("Extracting the whole archive using a linear extraction\n");
let expected_output = format!(
"Extracting the whole archive using a linear extraction\n{}",
file_list
);
assert.success().stdout(expected_output);

ensure_directory_content(output_dir.path(), &testfs.files);

Expand Down Expand Up @@ -1317,7 +1319,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);

Expand All @@ -1335,9 +1337,11 @@ fn test_extract_lot_files() {

println!("{:?}", cmd);
let assert = cmd.assert();
assert
.success()
.stdout("Extracting the whole archive using a linear extraction\n");
let expected_output = format!(
"Extracting the whole archive using a linear extraction\n{}",
file_list
);
assert.success().stdout(expected_output);

ensure_directory_content(output_dir.path(), &testfs.files);

Expand Down

0 comments on commit 5342417

Please sign in to comment.