/// Validate child, chunk and symlink digest on inode tree.
/// The chunk data digest for regular file will only validate on fs read.
Validate child, chunk and symlink digest on inode tree.
The chunk data digest for regular file will only validate on fs read.
Validate child chunk and symlink digest on inode tree . The chunk data digest for regular file will only validate on fs read .
fn digest_validate(
        &self,
        inode: Arc<dyn RafsInode>,
        recursive: bool,
        digester: digest::Algorithm,
    ) -> Result<bool> {
        let child_count = inode.get_child_count();
        let expected_digest = inode.get_digest();
        let mut hasher = RafsDigest::hasher(digester);
        if inode.is_symlink() {
            hasher.digest_update(inode.get_symlink()?.as_os_str().as_bytes());
        } else {
            for idx in 0..child_count {
                if inode.is_dir() {
                    let child = inode.get_child_by_index(idx as u64)?;
                    if (child.is_reg() || child.is_symlink() || (recursive && child.is_dir()))
                        && !self.digest_validate(child.clone(), recursive, digester)?
                    {
                        return Ok(false);
                    }
                    let child_digest = child.get_digest();
                    let child_digest = child_digest.as_ref().as_ref();
                    hasher.digest_update(child_digest);
                } else {
                    let chunk = inode.get_chunk_info(idx as u32)?;
                    let chunk_digest = chunk.block_id();
                    let chunk_digest = chunk_digest.as_ref().as_ref();
                    hasher.digest_update(chunk_digest);
                }
            }
        }
        let digest = hasher.digest_finalize();
        let result = expected_digest == digest;
        if !result {
            error!(
                "invalid inode digest {}, expected {}, ino: {} name: {:?}",
                digest,
                expected_digest,
                inode.ino(),
                inode.name()?
            );
        }
        Ok(result)
    }
fn digest_validate ( & self , inode : Arc < dyn RafsInode > , recursive : bool , digester : digest :: Algorithm , ) -> Result < bool > { let child_count = inode . get_child_count ( ) ; let expected_digest = inode . get_digest ( ) ; let mut hasher = RafsDigest :: hasher ( digester ) ; if inode . is_symlink ( ) { hasher . digest_update ( inode . get_symlink ( ) ? . as_os_str ( ) . as_bytes ( ) ) ; } else { for idx in 0 .. child_count { if inode . is_dir ( ) { let child = inode . get_child_by_index ( idx as u64 ) ? ; if ( child . is_reg ( ) || child . is_symlink ( ) || ( recursive && child . is_dir ( ) ) ) && ! self . digest_validate ( child . clone ( ) , recursive , digester ) ? { return Ok ( false ) ; } let child_digest = child . get_digest ( ) ; let child_digest = child_digest . as_ref ( ) . as_ref ( ) ; hasher . digest_update ( child_digest ) ; } else { let chunk = inode . get_chunk_info ( idx as u32 ) ? ; let chunk_digest = chunk . block_id ( ) ; let chunk_digest = chunk_digest . as_ref ( ) . as_ref ( ) ; hasher . digest_update ( chunk_digest ) ; } } } let digest = hasher . digest_finalize ( ) ; let result = expected_digest == digest ; if ! result { error ! ( " " digest expected_digest inode ino ( ) inode name ( ) ) ; } Ok ( result ) }
Validate child, chunk and symlink digest on inode tree.
Validate child chunk and symlink digest on inode tree .
&self
inode
Arc<dyn RafsInode>
recursive
bool
digester
digest::Algorithm