From 36628900e5ddf19b33f9f3635cecf7298de3e4aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Wed, 9 Aug 2023 09:37:25 +0800 Subject: [PATCH] Avoid Path::with_extension because it can replace extension --- repak_cli/src/main.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/repak_cli/src/main.rs b/repak_cli/src/main.rs index 9c663de..5def37e 100644 --- a/repak_cli/src/main.rs +++ b/repak_cli/src/main.rs @@ -290,10 +290,14 @@ fn unpack(aes_key: Option, action: ActionUnpack) -> Result<(), repa } fn pack(args: ActionPack) -> Result<(), repak::Error> { - let output = args - .output - .map(PathBuf::from) - .unwrap_or_else(|| Path::new(&args.input).with_extension("pak")); + let output = args.output.map(PathBuf::from).unwrap_or_else(|| { + let mut output = PathBuf::new(); + output.push(&args.input); + // NOTE: don't use `with_extension` here because it will replace e.g. the `.1` in + // `test_v1.1`. + output.push(".pak"); + output + }); fn collect_files(paths: &mut Vec, dir: &Path) -> io::Result<()> { for entry in fs::read_dir(dir)? {