Download snapshot files with a `tmp-` prefix so they'll automatically be cleaned up if interrupted

This commit is contained in:
Michael Vines 2021-03-16 23:04:05 -07:00
parent 3160549e85
commit 58b980f9cd
1 changed files with 11 additions and 2 deletions

View File

@ -34,9 +34,18 @@ pub fn download_file(
}
let download_start = Instant::now();
fs::create_dir_all(destination_file.parent().unwrap()).map_err(|err| err.to_string())?;
fs::create_dir_all(destination_file.parent().expect("parent"))
.map_err(|err| err.to_string())?;
let temp_destination_file = destination_file.with_extension("tmp");
let mut temp_destination_file = destination_file.to_path_buf();
temp_destination_file.set_file_name(format!(
"tmp-{}",
destination_file
.file_name()
.expect("file_name")
.to_str()
.expect("to_str")
));
let progress_bar = new_spinner_progress_bar();
if use_progress_bar {