pub fn download_snapshot_archive<'a, 'b>(
    rpc_addr: &SocketAddr,
    snapshot_archives_dir: &Path,
    desired_snapshot_hash: (Slot, Hash),
    snapshot_type: SnapshotType,
    maximum_full_snapshot_archives_to_retain: usize,
    maximum_incremental_snapshot_archives_to_retain: usize,
    use_progress_bar: bool,
    progress_notify_callback: &'a mut DownloadProgressCallbackOption<'b>,
) -> Result<(), String> {
    snapshot_utils::purge_old_snapshot_archives(
        snapshot_archives_dir,
        maximum_full_snapshot_archives_to_retain,
        maximum_incremental_snapshot_archives_to_retain,
    );

    for archive_format in [
        ArchiveFormat::TarZstd,
        ArchiveFormat::TarGzip,
        ArchiveFormat::TarBzip2,
        ArchiveFormat::Tar, // `solana-test-validator` creates uncompressed snapshots
    ] {
        let destination_path = match snapshot_type {
            SnapshotType::FullSnapshot => snapshot_utils::build_full_snapshot_archive_path(
                snapshot_archives_dir.to_path_buf(),
                desired_snapshot_hash.0,
                &desired_snapshot_hash.1,
                archive_format,
            ),
            SnapshotType::IncrementalSnapshot(base_slot) => {
                snapshot_utils::build_incremental_snapshot_archive_path(
                    snapshot_archives_dir.to_path_buf(),
                    base_slot,
                    desired_snapshot_hash.0,
                    &desired_snapshot_hash.1,
                    archive_format,
                )
            }
        };

        if destination_path.is_file() {
            return Ok(());
        }

        match download_file(
            &format!(
                "http://{}/{}",
                rpc_addr,
                destination_path.file_name().unwrap().to_str().unwrap()
            ),
            &destination_path,
            use_progress_bar,
            progress_notify_callback,
        ) {
            Ok(()) => return Ok(()),
            Err(err) => info!("{}", err),
        }
    }
    Err(format!(
        "Failed to download a snapshot archive for slot {} from {}",
        desired_snapshot_hash.0, rpc_addr
    ))
}
/// Download a snapshot archive from `rpc_addr`.  Use `snapshot_type` to specify downloading either
/// a full snapshot or an incremental snapshot.
Download a snapshot archive from `rpc_addr`.  Use `snapshot_type` to specify downloading either
a full snapshot or an incremental snapshot.
Download a snapshot archive from ` rpc_addr ` . Use ` snapshot_type ` to specify downloading either a full snapshot or an incremental snapshot .
pub fn download_snapshot_archive<'a, 'b>(
    rpc_addr: &SocketAddr,
    snapshot_archives_dir: &Path,
    desired_snapshot_hash: (Slot, Hash),
    snapshot_type: SnapshotType,
    maximum_full_snapshot_archives_to_retain: usize,
    maximum_incremental_snapshot_archives_to_retain: usize,
    use_progress_bar: bool,
    progress_notify_callback: &'a mut DownloadProgressCallbackOption<'b>,
) -> Result<(), String> {
    snapshot_utils::purge_old_snapshot_archives(
        snapshot_archives_dir,
        maximum_full_snapshot_archives_to_retain,
        maximum_incremental_snapshot_archives_to_retain,
    );
    for archive_format in [
        ArchiveFormat::TarZstd,
        ArchiveFormat::TarGzip,
        ArchiveFormat::TarBzip2,
        ArchiveFormat::Tar, // `solana-test-validator` creates uncompressed snapshots
    ] {
        let destination_path = match snapshot_type {
            SnapshotType::FullSnapshot => snapshot_utils::build_full_snapshot_archive_path(
                snapshot_archives_dir.to_path_buf(),
                desired_snapshot_hash.0,
                &desired_snapshot_hash.1,
                archive_format,
            ),
            SnapshotType::IncrementalSnapshot(base_slot) => {
                snapshot_utils::build_incremental_snapshot_archive_path(
                    snapshot_archives_dir.to_path_buf(),
                    base_slot,
                    desired_snapshot_hash.0,
                    &desired_snapshot_hash.1,
                    archive_format,
                )
            }
        };
        if destination_path.is_file() {
            return Ok(());
        }
        match download_file(
            &format!(
                "http://{}/{}",
                rpc_addr,
                destination_path.file_name().unwrap().to_str().unwrap()
            ),
            &destination_path,
            use_progress_bar,
            progress_notify_callback,
        ) {
            Ok(()) => return Ok(()),
            Err(err) => info!("{}", err),
        }
    }
    Err(format!(
        "Failed to download a snapshot archive for slot {} from {}",
        desired_snapshot_hash.0, rpc_addr
    ))
}
pub fn download_snapshot_archive < ' a , ' b > ( rpc_addr : & SocketAddr , snapshot_archives_dir : & Path , desired_snapshot_hash : ( Slot , Hash ) , snapshot_type : SnapshotType , maximum_full_snapshot_archives_to_retain : usize , maximum_incremental_snapshot_archives_to_retain : usize , use_progress_bar : bool , progress_notify_callback : & ' a mut DownloadProgressCallbackOption < ' b > , ) -> Result < ( ) , String > { snapshot_utils :: purge_old_snapshot_archives ( snapshot_archives_dir , maximum_full_snapshot_archives_to_retain , maximum_incremental_snapshot_archives_to_retain , ) ; for archive_format in [ ArchiveFormat :: TarZstd , ArchiveFormat :: TarGzip , ArchiveFormat :: TarBzip2 , ArchiveFormat :: Tar , // `solana-test-validator` creates uncompressed snapshots ] { let destination_path = match snapshot_type { SnapshotType :: FullSnapshot => snapshot_utils :: build_full_snapshot_archive_path ( snapshot_archives_dir . to_path_buf ( ) , desired_snapshot_hash . 0 , & desired_snapshot_hash . 1 , archive_format , ) , SnapshotType :: IncrementalSnapshot ( base_slot ) => { snapshot_utils :: build_incremental_snapshot_archive_path ( snapshot_archives_dir . to_path_buf ( ) , base_slot , desired_snapshot_hash . 0 , & desired_snapshot_hash . 1 , archive_format , ) } } ; if destination_path . is_file ( ) { return Ok ( ( ) ) ; } match download_file ( & format ! ( " " rpc_addr destination_path file_name ( ) unwrap ( ) to_str ( ) unwrap ( ) ) , & destination_path , use_progress_bar , progress_notify_callback , ) { Ok ( ( ) ) => return Ok ( ( ) ) , Err ( err ) => info ! ( " " err ) , } } Err ( format ! ( " " desired_snapshot_hash 0 rpc_addr ) ) }
Download a snapshot archive from `rpc_addr`.
Download a snapshot archive from ` rpc_addr ` .
rpc_addr
&SocketAddr
snapshot_archives_dir
&Path
desired_snapshot_hash
(Slot, Hash)
snapshot_type
SnapshotType
maximum_full_snapshot_archives_to_retain
usize
maximum_incremental_snapshot_archives_to_retain
usize
use_progress_bar
bool
progress_notify_callback
&'a mut DownloadProgressCallbackOption<'b>