Remove all snapshots not matching the desired hash
This commit is contained in:
@ -178,7 +178,8 @@ pub fn download_snapshot(
|
|||||||
// Remove all snapshot not matching the desired hash
|
// Remove all snapshot not matching the desired hash
|
||||||
let snapshot_packages = solana_ledger::snapshot_utils::get_snapshot_archives(ledger_path);
|
let snapshot_packages = solana_ledger::snapshot_utils::get_snapshot_archives(ledger_path);
|
||||||
for (snapshot_package, snapshot_hash) in snapshot_packages.iter() {
|
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)
|
fs::remove_file(snapshot_package)
|
||||||
.unwrap_or_else(|err| info!("Failed to remove old snapshot: {:}", err));
|
.unwrap_or_else(|err| info!("Failed to remove old snapshot: {:}", err));
|
||||||
}
|
}
|
||||||
|
@ -509,28 +509,35 @@ fn snapshot_hash_of(archive_filename: &str) -> Option<(Slot, Hash)> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_snapshot_archives<P: AsRef<Path>>(snapshot_output_dir: P) -> Vec<(PathBuf, (Slot, Hash))> {
|
pub fn get_snapshot_archives<P: AsRef<Path>>(
|
||||||
let files = fs::read_dir(&snapshot_output_dir)
|
snapshot_output_dir: P,
|
||||||
.unwrap_or_else(|err| panic!("Unable to read snapshot directory: {}", err));
|
) -> Vec<(PathBuf, (Slot, Hash))> {
|
||||||
|
match fs::read_dir(&snapshot_output_dir) {
|
||||||
let mut archives: Vec<_> = files
|
Err(err) => {
|
||||||
.filter_map(|entry| {
|
info!("Unable to read snapshot directory: {}", err);
|
||||||
if let Ok(entry) = entry {
|
vec![]
|
||||||
let path = entry.path();
|
}
|
||||||
if path.is_file() {
|
Ok(files) => {
|
||||||
if let Some(snapshot_hash) =
|
let mut archives: Vec<_> = files
|
||||||
snapshot_hash_of(path.file_name().unwrap().to_str().unwrap())
|
.filter_map(|entry| {
|
||||||
{
|
if let Ok(entry) = entry {
|
||||||
return Some((path, snapshot_hash));
|
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
|
||||||
}
|
})
|
||||||
None
|
.collect();
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
archives.sort_by(|a, b| (b.1).0.cmp(&(a.1).0)); // reverse sort by slot
|
archives.sort_by(|a, b| (b.1).0.cmp(&(a.1).0)); // reverse sort by slot
|
||||||
archives
|
archives
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_highest_snapshot_archive_path<P: AsRef<Path>>(
|
pub fn get_highest_snapshot_archive_path<P: AsRef<Path>>(
|
||||||
|
Reference in New Issue
Block a user