/// Read all files from the backup folder starting from the `start_height` and
/// convert them into batches.
Read all files from the backup folder starting from the `start_height` and
convert them into batches.
Read all files from the backup folder starting from the ` start_height ` and convert them into batches .
pub(super) fn heights_to_artifacts_metadata(
    backup_dir: &Path,
    start_height: Height,
) -> Result<BTreeMap<Height, HeightArtifacts>, std::io::Error> {
    let mut results = Vec::new();
    for group_dir in fs::read_dir(backup_dir)? {
        for height_dir in fs::read_dir(group_dir?.path())? {
            let path = height_dir?.path();
            let height = Height::from(
                path.file_name()
                    .unwrap_or_default()
                    .to_str()
                    .unwrap_or_default()
                    .parse::<u64>()
                    .expect("Couldn't parse the height directory name"),
            );
            // Skip all height folders below the start height,
            if height < start_height {
                continue;
            }
            let mut files = Vec::new();
            for file in fs::read_dir(&path)? {
                let file_path = file?.path();
                files.push(
                    file_path
                        .file_name()
                        .unwrap_or_default()
                        .to_str()
                        .unwrap_or_default()
                        .to_string(),
                );
            }
            let get_files = |s| {
                files
                    .iter()
                    .filter(|file| file.starts_with(s))
                    .cloned()
                    .collect::<Vec<_>>()
            };
            results.push((
                height,
                HeightArtifacts {
                    path,
                    contains_cup: !get_files("catch_up_package").is_empty(),
                    proposals: get_files("block_proposal"),
                    finalizations: get_files("finalization"),
                    notarizations: get_files("notarization"),
                },
            ));
        }
    }
    Ok(results.into_iter().collect())
}
pub ( super ) fn heights_to_artifacts_metadata ( backup_dir : & Path , start_height : Height , ) -> Result < BTreeMap < Height , HeightArtifacts > , std :: io :: Error > { let mut results = Vec :: new ( ) ; for group_dir in fs :: read_dir ( backup_dir ) ? { for height_dir in fs :: read_dir ( group_dir ? . path ( ) ) ? { let path = height_dir ? . path ( ) ; let height = Height :: from ( path . file_name ( ) . unwrap_or_default ( ) . to_str ( ) . unwrap_or_default ( ) . parse :: < u64 > ( ) . expect ( " " ) , ) ; // Skip all height folders below the start height, if height < start_height { continue ; } let mut files = Vec :: new ( ) ; for file in fs :: read_dir ( & path ) ? { let file_path = file ? . path ( ) ; files . push ( file_path . file_name ( ) . unwrap_or_default ( ) . to_str ( ) . unwrap_or_default ( ) . to_string ( ) , ) ; } let get_files = | s | { files . iter ( ) . filter ( | file | file . starts_with ( s ) ) . cloned ( ) . collect :: < Vec < _ > > ( ) } ; results . push ( ( height , HeightArtifacts { path , contains_cup : ! get_files ( " " ) . is_empty ( ) , proposals : get_files ( " " ) , finalizations : get_files ( " " ) , notarizations : get_files ( " " ) , } , ) ) ; } } Ok ( results . into_iter ( ) . collect ( ) ) }
Read all files from the backup folder starting from the `start_height` and
convert them into batches.
Read all files from the backup folder starting from the ` start_height ` and convert them into batches .
backup_dir
&Path
start_height
Height