Avoid Path::with_extension because it can replace extension

This commit is contained in:
许杰友 Jieyou Xu (Joe) 2023-08-09 09:37:25 +08:00 committed by Truman Kilen
parent a8c086d2c9
commit 36628900e5

View file

@ -290,10 +290,14 @@ fn unpack(aes_key: Option<aes::Aes256>, action: ActionUnpack) -> Result<(), repa
} }
fn pack(args: ActionPack) -> Result<(), repak::Error> { fn pack(args: ActionPack) -> Result<(), repak::Error> {
let output = args let output = args.output.map(PathBuf::from).unwrap_or_else(|| {
.output let mut output = PathBuf::new();
.map(PathBuf::from) output.push(&args.input);
.unwrap_or_else(|| Path::new(&args.input).with_extension("pak")); // 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<PathBuf>, dir: &Path) -> io::Result<()> { fn collect_files(paths: &mut Vec<PathBuf>, dir: &Path) -> io::Result<()> {
for entry in fs::read_dir(dir)? { for entry in fs::read_dir(dir)? {