/// Convert a file path to an inode number.
Convert a file path to an inode number.
Convert a file path to an inode number .
pub fn ino_from_path(&self, f: &Path) -> Result<u64> {
        if f == Path::new("/") {
            return Ok(ROOT_ID);
        }
        if !f.starts_with("/") {
            return Err(einval!());
        }
        let mut parent = self.get_inode(ROOT_ID, self.validate_digest)?;
        let entries = f
            .components()
            .filter(|comp| *comp != Component::RootDir)
            .map(|comp| match comp {
                Component::Normal(name) => Some(name),
                Component::ParentDir => Some(OsStr::from_bytes(DOTDOT.as_bytes())),
                Component::CurDir => Some(OsStr::from_bytes(DOT.as_bytes())),
                _ => None,
            })
            .collect::<Vec<_>>();
        if entries.is_empty() {
            warn!("Path can't be parsed {:?}", f);
            return Err(enoent!());
        }
        for p in entries {
            if p.is_none() {
                error!("Illegal specified path {:?}", f);
                return Err(einval!());
            }
            // Safe because it already checks if p is None above.
            match parent.get_child_by_name(p.unwrap()) {
                Ok(p) => parent = p,
                Err(_) => {
                    warn!("File {:?} not in rafs", p.unwrap());
                    return Err(enoent!());
                }
            }
        }
        Ok(parent.ino())
    }
pub fn ino_from_path ( & self , f : & Path ) -> Result < u64 > { if f == Path :: new ( " " ) { return Ok ( ROOT_ID ) ; } if ! f . starts_with ( " " ) { return Err ( einval ! ( ) ) ; } let mut parent = self . get_inode ( ROOT_ID , self . validate_digest ) ? ; let entries = f . components ( ) . filter ( | comp | * comp != Component :: RootDir ) . map ( | comp | match comp { Component :: Normal ( name ) => Some ( name ) , Component :: ParentDir => Some ( OsStr :: from_bytes ( DOTDOT . as_bytes ( ) ) ) , Component :: CurDir => Some ( OsStr :: from_bytes ( DOT . as_bytes ( ) ) ) , _ => None , } ) . collect :: < Vec < _ > > ( ) ; if entries . is_empty ( ) { warn ! ( " " f ) ; return Err ( enoent ! ( ) ) ; } for p in entries { if p . is_none ( ) { error ! ( " " f ) ; return Err ( einval ! ( ) ) ; } // Safe because it already checks if p is None above. match parent . get_child_by_name ( p . unwrap ( ) ) { Ok ( p ) => parent = p , Err ( _ ) => { warn ! ( " " p unwrap ( ) ) ; return Err ( enoent ! ( ) ) ; } } } Ok ( parent . ino ( ) ) }
Convert a file path to an inode number.
Convert a file path to an inode number .
&self
f
&Path