[feat] add panic hook and normal exit cleanup for .last_model file handling

This commit is contained in:
2025-08-11 02:14:59 +02:00
parent 8c9fac80db
commit cd25b526c6

View File

@@ -254,6 +254,17 @@ fn run() -> Result<()> {
path: last_model_path.clone(), path: last_model_path.clone(),
}; };
// Also ensure cleanup on panic: install a panic hook that removes .last_model, then chains
{
let last_for_panic = last_model_path.clone();
let prev_hook = std::panic::take_hook();
std::panic::set_hook(Box::new(move |info| {
let _ = std::fs::remove_file(&last_for_panic);
// chain to default/previous hook for normal panic reporting
prev_hook(info);
}));
}
// Select backend // Select backend
let requested = match args.gpu_backend { let requested = match args.gpu_backend {
GpuBackendCli::Auto => BackendKind::Auto, GpuBackendCli::Auto => BackendKind::Auto,
@@ -740,6 +751,8 @@ fn run() -> Result<()> {
} }
} }
// Final best-effort cleanup of .last_model on normal exit
let _ = std::fs::remove_file(&last_model_path);
Ok(()) Ok(())
} }