-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
Simplified code
fn process_file(path: &Path, dir_broken: &Path) -> Result<bool, String> {
panic::catch_unwind(|| {
let data = read_file_vec(path)?;
let ext = detect_ext_from_vec(&data).ok_or_else(|| "Failed to detect file type".to_string())?;
let metadata = load_metadata_from_vec(&data, ext)?;
let mut data_new = data.clone();
match metadata.write_to_vec(&mut data_new, ext){
Ok(()) => Ok(false),
Err(e) => {
eprintln!("File {} is broken: {}", path.display(), e);
let extension = path.extension().unwrap().to_string_lossy();
fs::copy(path, dir_broken.join(format!("{}.{extension}", random::<u128>())))
.map_err(|e| format!("Failed to copy broken file {}: {}", path.display(), e)).unwrap();
Ok(true)
}
}
}).unwrap_or_else(|e| {
Err(format!("Panic occurred while processing {}: {:?}", path.display(), e))
})
}
Project - same.zip
Usage
cargo run --release -- /path_to_gather_files /path_where_save_broken_files
Reading metadata and writing back the exact same metadata to the original file should always succeed, but this errors are reported:
failed to fill whole buffer
Broken files -Broken.zip
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels