From 3bfebf9c3172cfd0b6c5fef7d17c0a80fd37778b Mon Sep 17 00:00:00 2001 From: t-mw Date: Sun, 28 Feb 2021 23:16:04 +0100 Subject: [PATCH] Refactor for clarity --- src/update.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/update.rs b/src/update.rs index 948e712..5dbd1cc 100644 --- a/src/update.rs +++ b/src/update.rs @@ -135,7 +135,7 @@ pub trait ReleaseUpdate { // of the temporary directory by the `tempfile` crate after we move the running executable // into it during an update. We clean up any previously created temporary directories here. // Ignore errors during cleanup since this is not critical for completing the update. - let _ = cleanup_temp_directories( + let _ = cleanup_backup_temp_directories( &tmp_dir_parent, &tmp_backup_dir_prefix, &tmp_backup_filename, @@ -286,7 +286,7 @@ fn api_headers(auth_token: &Option) -> header::HeaderMap { headers } -fn cleanup_temp_directories>( +fn cleanup_backup_temp_directories>( tmp_dir_parent: P, tmp_dir_prefix: &str, expected_tmp_filename: &str, @@ -299,7 +299,10 @@ fn cleanup_temp_directories>( continue; }; - // For safety, check that temporary directory contains only expected file before removing. + // For safety, check that the temporary directory contains only the expected backup + // binary file before removing. If subdirectories or other files exist then the user + // is using the temp directory for something else. This is unlikely, but we should + // be careful with `fs::remove_dir_all`. let is_expected_tmp_file = |tmp_file_entry: std::io::Result| { tmp_file_entry .ok()