From a5a587f94afc229cbb800ef2f25d30ed4c7edf69 Mon Sep 17 00:00:00 2001 From: Truman Kilen Date: Tue, 31 Jan 2023 23:14:39 -0600 Subject: [PATCH] Error if pack input is not a directory --- unpak_cli/src/main.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/unpak_cli/src/main.rs b/unpak_cli/src/main.rs index 9f04c5a..e7b86f1 100644 --- a/unpak_cli/src/main.rs +++ b/unpak_cli/src/main.rs @@ -179,20 +179,21 @@ fn pack(args: ActionPack) -> Result<(), unpak::Error> { .unwrap_or_else(|| Path::new(&args.input).with_extension("pak")); fn collect_files(paths: &mut Vec, dir: &Path) -> io::Result<()> { - if dir.is_dir() { - for entry in fs::read_dir(dir)? { - let entry = entry?; - let path = entry.path(); - if path.is_dir() { - collect_files(paths, &path)?; - } else { - paths.push(entry.path()); - } + for entry in fs::read_dir(dir)? { + let entry = entry?; + let path = entry.path(); + if path.is_dir() { + collect_files(paths, &path)?; + } else { + paths.push(entry.path()); } } Ok(()) } let input_path = Path::new(&args.input); + if !input_path.is_dir() { + return Err(unpak::Error::Other("input is not a directory")); + } let mut paths = vec![]; collect_files(&mut paths, input_path)?; paths.sort();