Merge pull request 'Fix extracting files with non-flattened file names' (#52) from issue/51 into master

Reviewed-on: #52
This commit is contained in:
Lucas Schwiderski 2023-03-06 09:28:17 +01:00
commit 37bf9deb08
2 changed files with 35 additions and 24 deletions

View file

@ -10,6 +10,7 @@
=== Fixed === Fixed
- all: force unix path separators for engine values - all: force unix path separators for engine values
- dtmt: fix extracing files with non-flattened file names
== 2023-03-01 == 2023-03-01

View file

@ -3,7 +3,7 @@ use std::sync::Arc;
use clap::{value_parser, Arg, ArgAction, ArgMatches, Command}; use clap::{value_parser, Arg, ArgAction, ArgMatches, Command};
use color_eyre::eyre::{self, Context, Result}; use color_eyre::eyre::{self, Context, Result};
use color_eyre::{Help, Report, SectionExt}; use color_eyre::{Help, Report};
use futures::future::try_join_all; use futures::future::try_join_all;
use futures::StreamExt; use futures::StreamExt;
use glob::Pattern; use glob::Pattern;
@ -311,14 +311,25 @@ where
path.push(name); path.push(name);
if options.dry_run { if options.dry_run {
tracing::info!(path = %path.display(), "Writing file"); tracing::info!("Dry Run: Writing file '{}'", path.display());
} else { } else {
tracing::debug!(path = %path.display(), "Writing file"); tracing::info!("Writing file '{}'", path.display());
tasks.push(tokio::spawn(async move { tasks.push(tokio::spawn(async move {
fs::write(&path, file.data()) if let Some(parent) = path.parent() {
.await fs::create_dir_all(&parent).await.wrap_err_with(|| {
.wrap_err("failed to write extracted file to disc") format!(
.with_section(|| path.display().to_string().header("Path")) "failed to create parent directories '{}'",
parent.display()
)
})?;
}
fs::write(&path, file.data()).await.wrap_err_with(|| {
format!(
"failed to write extracted file to disc: '{}'",
path.display()
)
})
})); }));
} }
} }
@ -342,9 +353,9 @@ where
path.push(name); path.push(name);
if options.dry_run { if options.dry_run {
tracing::info!(path = %path.display(), "Writing file"); tracing::info!("Dry Run: Writing file '{}'", path.display());
} else { } else {
tracing::debug!(path = %path.display(), "Writing file"); tracing::info!("Writing file '{}'", path.display());
tasks.push(tokio::spawn(async move { tasks.push(tokio::spawn(async move {
let parent = match path.parent() { let parent = match path.parent() {
Some(parent) => parent, Some(parent) => parent,
@ -356,17 +367,19 @@ where
} }
}; };
fs::create_dir_all(parent) fs::create_dir_all(parent).await.wrap_err_with(|| {
.await format!(
.wrap_err("failed to create parent directory") "failed to create parent directory: '{}'",
.with_section(|| { parent.display()
parent.display().to_string().header("Path") )
})?; })?;
fs::write(&path, file.data()) fs::write(&path, file.data()).await.wrap_err_with(|| {
.await format!(
.wrap_err("failed to write extracted file to disc") "failed to write extracted file to disc: '{}'",
.with_section(|| path.display().to_string().header("Path")) path.display()
)
})
})); }));
} }
} }
@ -374,10 +387,7 @@ where
} }
} }
Err(err) => { Err(err) => {
let err = err let err = err.wrap_err(format!("Failed to decompile file {}", name));
.wrap_err("Failed to decompile")
.with_section(|| name.header("File"));
tracing::error!("{:?}", err); tracing::error!("{:?}", err);
} }
}; };