pfl_upg: prevent file collisions (needs more work)

This commit is contained in:
theubusu
2025-11-28 00:05:23 +01:00
parent b608888538
commit 75674ca8e2
2 changed files with 16 additions and 2 deletions
+14 -1
View File
@@ -153,7 +153,20 @@ pub fn extract_pfl_upg(mut file: &File, output_folder: &str) -> Result<(), Box<d
let data = common::read_exact(&mut data_reader, file_header.stored_size as usize)?;
let output_path = Path::new(&output_folder).join(file_header.file_name().trim_start_matches('/'));
let mut output_path = Path::new(&output_folder).join(file_header.file_name().trim_start_matches('/'));
let output_path_parent = output_path.parent().expect("Failed to get parent of the output path!");
//prevent collisions because philips is dumb
if output_path_parent.exists() && output_path_parent.is_file() {
let fixed_file_name = if let Some((a, b)) = file_header.file_name().rsplit_once('/') {
format!("{}_{}", a, b)
} else {
file_header.file_name()
};
output_path = Path::new(&output_folder).join(file_header.file_name().trim_start_matches('/'));
println!("[!] Warning: File collision detected, this file will be saved to: {}", fixed_file_name);
}
if let Some(parent) = output_path.parent() {
fs::create_dir_all(parent)?;