diff --git a/download-utils/src/lib.rs b/download-utils/src/lib.rs index d94966808..1100a593c 100644 --- a/download-utils/src/lib.rs +++ b/download-utils/src/lib.rs @@ -178,7 +178,8 @@ pub fn download_snapshot( // Remove all snapshot not matching the desired hash let snapshot_packages = solana_ledger::snapshot_utils::get_snapshot_archives(ledger_path); for (snapshot_package, snapshot_hash) in snapshot_packages.iter() { - if snapshot_hash != desired_snapshot_hash { + if *snapshot_hash != desired_snapshot_hash { + info!("Removing old snapshot: {:?}", snapshot_package); fs::remove_file(snapshot_package) .unwrap_or_else(|err| info!("Failed to remove old snapshot: {:}", err)); } diff --git a/ledger/src/snapshot_utils.rs b/ledger/src/snapshot_utils.rs index 6f4b19fb6..146c1559a 100644 --- a/ledger/src/snapshot_utils.rs +++ b/ledger/src/snapshot_utils.rs @@ -509,28 +509,35 @@ fn snapshot_hash_of(archive_filename: &str) -> Option<(Slot, Hash)> { None } -fn get_snapshot_archives>(snapshot_output_dir: P) -> Vec<(PathBuf, (Slot, Hash))> { - let files = fs::read_dir(&snapshot_output_dir) - .unwrap_or_else(|err| panic!("Unable to read snapshot directory: {}", err)); - - let mut archives: Vec<_> = files - .filter_map(|entry| { - if let Ok(entry) = entry { - let path = entry.path(); - if path.is_file() { - if let Some(snapshot_hash) = - snapshot_hash_of(path.file_name().unwrap().to_str().unwrap()) - { - return Some((path, snapshot_hash)); +pub fn get_snapshot_archives>( + snapshot_output_dir: P, +) -> Vec<(PathBuf, (Slot, Hash))> { + match fs::read_dir(&snapshot_output_dir) { + Err(err) => { + info!("Unable to read snapshot directory: {}", err); + vec![] + } + Ok(files) => { + let mut archives: Vec<_> = files + .filter_map(|entry| { + if let Ok(entry) = entry { + let path = entry.path(); + if path.is_file() { + if let Some(snapshot_hash) = + snapshot_hash_of(path.file_name().unwrap().to_str().unwrap()) + { + return Some((path, snapshot_hash)); + } + } } - } - } - None - }) - .collect(); + None + }) + .collect(); - archives.sort_by(|a, b| (b.1).0.cmp(&(a.1).0)); // reverse sort by slot - archives + archives.sort_by(|a, b| (b.1).0.cmp(&(a.1).0)); // reverse sort by slot + archives + } + } } pub fn get_highest_snapshot_archive_path>(