From a6b7cc202ae7eeab22f550d0a33c34dee60d6234 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Tue, 16 Mar 2021 23:04:05 -0700 Subject: [PATCH] Download snapshot files with a `tmp-` prefix so they'll automatically be cleaned up if interrupted (cherry picked from commit 58b980f9cdb395769545e025367801f5522f7a2f) --- download-utils/src/lib.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/download-utils/src/lib.rs b/download-utils/src/lib.rs index c7645af29c..ec4b3747f7 100644 --- a/download-utils/src/lib.rs +++ b/download-utils/src/lib.rs @@ -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 {