From fc8ce5506dbc939ef0e7ee316af3388902c3631e Mon Sep 17 00:00:00 2001 From: brooks Date: Tue, 27 Jun 2023 11:57:06 -0400 Subject: [PATCH 1/2] Cleanup impl for remove_tmp_snapshot_archives() --- runtime/src/snapshot_utils.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index ee3ad07e4959d9..9fc36f0bac4cfc 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -623,11 +623,9 @@ fn is_bank_snapshot_complete(bank_snapshot_dir: impl AsRef) -> bool { pub fn remove_tmp_snapshot_archives(snapshot_archives_dir: impl AsRef) { if let Ok(entries) = std::fs::read_dir(snapshot_archives_dir) { for entry in entries.flatten() { - let file_name = entry - .file_name() - .into_string() - .unwrap_or_else(|_| String::new()); - if file_name.starts_with(TMP_SNAPSHOT_ARCHIVE_PREFIX) { + if entry.file_name().to_str().map_or(false, |file_name| { + file_name.starts_with(TMP_SNAPSHOT_ARCHIVE_PREFIX) + }) { let path = entry.path(); let result = if path.is_dir() { fs_err::remove_dir_all(path) From 06f9fa74d2b82c8316c88841345d83fc247175f7 Mon Sep 17 00:00:00 2001 From: brooks Date: Tue, 27 Jun 2023 15:01:07 -0400 Subject: [PATCH 2/2] pr: unwrap --- runtime/src/snapshot_utils.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index 9fc36f0bac4cfc..0a83d60a1f2e10 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -623,9 +623,12 @@ fn is_bank_snapshot_complete(bank_snapshot_dir: impl AsRef) -> bool { pub fn remove_tmp_snapshot_archives(snapshot_archives_dir: impl AsRef) { if let Ok(entries) = std::fs::read_dir(snapshot_archives_dir) { for entry in entries.flatten() { - if entry.file_name().to_str().map_or(false, |file_name| { - file_name.starts_with(TMP_SNAPSHOT_ARCHIVE_PREFIX) - }) { + if entry + .file_name() + .to_str() + .map(|file_name| file_name.starts_with(TMP_SNAPSHOT_ARCHIVE_PREFIX)) + .unwrap_or(false) + { let path = entry.path(); let result = if path.is_dir() { fs_err::remove_dir_all(path)