fix(dtmt): Fix extracting files with non-flattened file names

Fixes #51.
This commit is contained in:
Lucas Schwiderski 2023-03-06 09:20:57 +01:00
parent bdc77e70a4
commit fb88388acf
Signed by: lucas
GPG key ID: AA12679AAA6DF4D8
2 changed files with 35 additions and 24 deletions

View file

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

View file

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