pub fn validate_cache_for_commit<R, T, Tree: MerkleTreeTrait>(
    cache_path: R,
    replica_path: T,
) -> Result<()>
where
    R: AsRef<Path>,
    T: AsRef<Path>,
{
    info!("validate_cache_for_precommit:start");

    // Verify that the replica exists and is not empty.
    ensure!(
        replica_path.as_ref().exists(),
        "Missing replica: {}",
        replica_path.as_ref().to_path_buf().display()
    );

    let metadata = File::open(&replica_path)?.metadata()?;
    ensure!(
        metadata.len() > 0,
        "Replica {} exists, but is empty!",
        replica_path.as_ref().to_path_buf().display()
    );

    let cache = &cache_path.as_ref();

    // Make sure p_aux exists and is valid.
    let p_aux_path = cache.join(CacheKey::PAux.to_string());
    let p_aux_bytes = std::fs::read(&p_aux_path)
        .with_context(|| format!("could not read file p_aux={:?}", p_aux_path))?;

    let _: PersistentAux<<Tree::Hasher as Hasher>::Domain> = deserialize(&p_aux_bytes)?;
    drop(p_aux_bytes);

    // Make sure t_aux exists and is valid.
    let t_aux = {
        let t_aux_path = cache.join(CacheKey::TAux.to_string());
        let t_aux_bytes = std::fs::read(&t_aux_path)
            .with_context(|| format!("could not read file t_aux={:?}", t_aux_path))?;

        let mut res: TemporaryAux<Tree, DefaultPieceHasher> = deserialize(&t_aux_bytes)?;

        // Switch t_aux to the passed in cache_path
        res.set_cache_path(&cache_path);
        res
    };

    // Verify all stores/labels within the Labels object.
    let cache = cache_path.as_ref().to_path_buf();
    t_aux.labels.verify_stores(verify_store, &cache)?;

    // Verify each tree disk store.
    verify_store(
        &t_aux.tree_d_config,
        <DefaultBinaryTree as MerkleTreeTrait>::Arity::to_usize(),
        get_base_tree_count::<Tree>(),
    )?;
    verify_store(
        &t_aux.tree_c_config,
        <DefaultOctTree as MerkleTreeTrait>::Arity::to_usize(),
        get_base_tree_count::<Tree>(),
    )?;
    verify_level_cache_store::<DefaultOctTree>(&t_aux.tree_r_last_config)?;

    info!("validate_cache_for_precommit:finish");
    Ok(())
}
// Checks for the existence of the replica data and t_aux, which in
// turn allows us to verify the tree d, tree r, tree c, and the
// labels.
Checks for the existence of the replica data and t_aux, which in
turn allows us to verify the tree d, tree r, tree c, and the
labels.
Checks for the existence of the replica data and t_aux which in turn allows us to verify the tree d tree r tree c and the labels .
pub fn validate_cache_for_commit<R, T, Tree: MerkleTreeTrait>(
    cache_path: R,
    replica_path: T,
) -> Result<()>
where
    R: AsRef<Path>,
    T: AsRef<Path>,
{
    info!("validate_cache_for_precommit:start");
    // Verify that the replica exists and is not empty.
    ensure!(
        replica_path.as_ref().exists(),
        "Missing replica: {}",
        replica_path.as_ref().to_path_buf().display()
    );
    let metadata = File::open(&replica_path)?.metadata()?;
    ensure!(
        metadata.len() > 0,
        "Replica {} exists, but is empty!",
        replica_path.as_ref().to_path_buf().display()
    );
    let cache = &cache_path.as_ref();
    // Make sure p_aux exists and is valid.
    let p_aux_path = cache.join(CacheKey::PAux.to_string());
    let p_aux_bytes = std::fs::read(&p_aux_path)
        .with_context(|| format!("could not read file p_aux={:?}", p_aux_path))?;
    let _: PersistentAux<<Tree::Hasher as Hasher>::Domain> = deserialize(&p_aux_bytes)?;
    drop(p_aux_bytes);
    // Make sure t_aux exists and is valid.
    let t_aux = {
        let t_aux_path = cache.join(CacheKey::TAux.to_string());
        let t_aux_bytes = std::fs::read(&t_aux_path)
            .with_context(|| format!("could not read file t_aux={:?}", t_aux_path))?;
        let mut res: TemporaryAux<Tree, DefaultPieceHasher> = deserialize(&t_aux_bytes)?;
        // Switch t_aux to the passed in cache_path
        res.set_cache_path(&cache_path);
        res
    };
    // Verify all stores/labels within the Labels object.
    let cache = cache_path.as_ref().to_path_buf();
    t_aux.labels.verify_stores(verify_store, &cache)?;
    // Verify each tree disk store.
    verify_store(
        &t_aux.tree_d_config,
        <DefaultBinaryTree as MerkleTreeTrait>::Arity::to_usize(),
        get_base_tree_count::<Tree>(),
    )?;
    verify_store(
        &t_aux.tree_c_config,
        <DefaultOctTree as MerkleTreeTrait>::Arity::to_usize(),
        get_base_tree_count::<Tree>(),
    )?;
    verify_level_cache_store::<DefaultOctTree>(&t_aux.tree_r_last_config)?;
    info!("validate_cache_for_precommit:finish");
    Ok(())
}
pub fn validate_cache_for_commit < R , T , Tree : MerkleTreeTrait > ( cache_path : R , replica_path : T , ) -> Result < ( ) > where R : AsRef < Path > , T : AsRef < Path > , { info ! ( " " ) ; // Verify that the replica exists and is not empty. ensure ! ( replica_path as_ref ( ) exists ( ) " " replica_path as_ref ( ) to_path_buf ( ) display ( ) ) ; let metadata = File :: open ( & replica_path ) ? . metadata ( ) ? ; ensure ! ( metadata len ( ) 0 " " replica_path as_ref ( ) to_path_buf ( ) display ( ) ) ; let cache = & cache_path . as_ref ( ) ; // Make sure p_aux exists and is valid. let p_aux_path = cache . join ( CacheKey :: PAux . to_string ( ) ) ; let p_aux_bytes = std :: fs :: read ( & p_aux_path ) . with_context ( | | format ! ( " " p_aux_path ) ) ? ; let _ : PersistentAux < < Tree :: Hasher as Hasher > :: Domain > = deserialize ( & p_aux_bytes ) ? ; drop ( p_aux_bytes ) ; // Make sure t_aux exists and is valid. let t_aux = { let t_aux_path = cache . join ( CacheKey :: TAux . to_string ( ) ) ; let t_aux_bytes = std :: fs :: read ( & t_aux_path ) . with_context ( | | format ! ( " " t_aux_path ) ) ? ; let mut res : TemporaryAux < Tree , DefaultPieceHasher > = deserialize ( & t_aux_bytes ) ? ; // Switch t_aux to the passed in cache_path res . set_cache_path ( & cache_path ) ; res } ; // Verify all stores/labels within the Labels object. let cache = cache_path . as_ref ( ) . to_path_buf ( ) ; t_aux . labels . verify_stores ( verify_store , & cache ) ? ; // Verify each tree disk store. verify_store ( & t_aux . tree_d_config , < DefaultBinaryTree as MerkleTreeTrait > :: Arity :: to_usize ( ) , get_base_tree_count :: < Tree > ( ) , ) ? ; verify_store ( & t_aux . tree_c_config , < DefaultOctTree as MerkleTreeTrait > :: Arity :: to_usize ( ) , get_base_tree_count :: < Tree > ( ) , ) ? ; verify_level_cache_store :: < DefaultOctTree > ( & t_aux . tree_r_last_config ) ? ; info ! ( " " ) ; Ok ( ( ) ) }
Checks for the existence of the replica data and t_aux, which in
turn allows us to verify the tree d, tree r, tree c, and the
labels.
Checks for the existence of the replica data and t_aux which in turn allows us to verify the tree d tree r tree c and the labels .
cache_path
R
replica_path
T
cache_path
R
replica_path
T