Fix incorrect unpack output directory default

This commit is contained in:
Truman Kilen 2023-01-31 23:13:54 -06:00
parent 898be58855
commit b1cfe4aa1f

View file

@ -137,15 +137,11 @@ fn unpack(args: ActionUnpack) -> Result<(), unpak::Error> {
BufReader::new(File::open(&args.input)?), BufReader::new(File::open(&args.input)?),
args.aes_key.map(|k| aes_key(k.as_str())).transpose()?, args.aes_key.map(|k| aes_key(k.as_str())).transpose()?,
)?; )?;
let output = args.output.as_ref().map(Path::new).unwrap_or_else(|| { let output = args
Path::new( .output
Path::new(&args.input) .map(PathBuf::from)
.file_stem() .unwrap_or_else(|| Path::new(&args.input).with_extension(""));
.and_then(|name| name.to_str()) match fs::create_dir(&output) {
.expect("could not get pak file name"),
)
});
match fs::create_dir(output) {
Ok(_) => Ok(()), Ok(_) => Ok(()),
Err(ref e) if e.kind() == std::io::ErrorKind::AlreadyExists => Ok(()), Err(ref e) if e.kind() == std::io::ErrorKind::AlreadyExists => Ok(()),
Err(e) => Err(e), Err(e) => Err(e),
@ -165,7 +161,7 @@ fn unpack(args: ActionUnpack) -> Result<(), unpak::Error> {
.strip_prefix(prefix) .strip_prefix(prefix)
.map_err(|_| unpak::Error::Other("prefix does not match"))?, .map_err(|_| unpak::Error::Other("prefix does not match"))?,
); );
if !file_path.clean().starts_with(output) { if !file_path.clean().starts_with(&output) {
return Err(unpak::Error::Other( return Err(unpak::Error::Other(
"tried to write file outside of output directory", "tried to write file outside of output directory",
)); ));