Skip to content

Commit 7a9230a

Browse files
committed
feat: remove guest image file if sha256 is error
1 parent c5d2a65 commit 7a9230a

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

xtask/src/image.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,20 @@ async fn image_download(image_name: &str, output_dir: Option<String>, extract: b
329329
return Ok(());
330330
}
331331
Ok(false) => {
332-
println!("File verification failed, SHA256 does not match, will re-download");
332+
println!("File verification failed, SHA256 does not match, removing corrupted file and re-downloading");
333+
if let Err(e) = fs::remove_file(&output_path) {
334+
println!("Warning: Failed to remove corrupted file: {}", e);
335+
} else {
336+
println!("Corrupted file removed successfully");
337+
}
333338
}
334339
Err(e) => {
335-
println!("Error verifying file: {}, will re-download", e);
340+
println!("Error verifying file: {}, removing potentially corrupted file and re-downloading", e);
341+
if let Err(remove_err) = fs::remove_file(&output_path) {
342+
println!("Warning: Failed to remove potentially corrupted file: {}", remove_err);
343+
} else {
344+
println!("Potentially corrupted file removed successfully");
345+
}
336346
}
337347
}
338348
} else {
@@ -367,9 +377,21 @@ async fn image_download(image_name: &str, output_dir: Option<String>, extract: b
367377
println!("Download completed, file verification successful");
368378
}
369379
Ok(false) => {
380+
println!("SHA256 verification failed, removing corrupted file...");
381+
if let Err(e) = fs::remove_file(&output_path) {
382+
println!("Warning: Failed to remove corrupted file: {}", e);
383+
} else {
384+
println!("Corrupted file removed successfully");
385+
}
370386
return Err(anyhow!("Downloaded file SHA256 verification failed"));
371387
}
372388
Err(e) => {
389+
println!("Error verifying file, removing potentially corrupted file...");
390+
if let Err(remove_err) = fs::remove_file(&output_path) {
391+
println!("Warning: Failed to remove potentially corrupted file: {}", remove_err);
392+
} else {
393+
println!("Potentially corrupted file removed successfully");
394+
}
373395
return Err(anyhow!("Error verifying downloaded file: {}", e));
374396
}
375397
}

0 commit comments

Comments
 (0)