pub fn rename(&mut self, from: &Path, to: &Path) -> Result<()> {
        if self.read_only {
            return Err(Error::ReadOnly);
        }

        if from == to {
            return Ok(());
        }

        if to.starts_with(from) {
            return Err(Error::InvalidArgument);
        }

        let src = self.resolve(from)?;
        let tgt = match self.resolve(to) {
            Ok(tgt) => Some(tgt),
            Err(ref err) if *err == Error::NotFound => None,
            Err(err) => return Err(err),
        };

        {
            let src_fnode = src.read().unwrap();
            if src_fnode.is_root() {
                return Err(Error::IsRoot);
            }

            if let Some(ref tgt_fnode) = tgt {
                let tgt_fnode = tgt_fnode.read().unwrap();
                if tgt_fnode.is_root() {
                    return Err(Error::IsRoot);
                }
                if src_fnode.is_file() && tgt_fnode.is_dir() {
                    return Err(Error::IsDir);
                }
                if src_fnode.is_dir() {
                    if tgt_fnode.is_file() {
                        return Err(Error::NotDir);
                    }
                    if tgt_fnode.children_cnt() > 0 {
                        return Err(Error::NotEmpty);
                    }
                }
            }
        }

        let (tgt_parent, name) = self.resolve_parent(to)?;

        // begin and run transaction
        TxMgr::begin_trans(&self.txmgr)?.run_all(|| {
            // remove from source
            Fnode::remove_from_parent(&src)?;

            // remove target if it exists
            if let Some(tgt_fnode) = tgt {
                Fnode::remove_from_parent(&tgt_fnode)?;
                let mut tgt_fnode = tgt_fnode.write().unwrap();
                if tgt_fnode.is_file() {
                    tgt_fnode.make_mut()?.clear_vers()?;
                }
                tgt_fnode.make_del()?;
                self.fcache.remove(tgt_fnode.id());
            }

            // and then add to target
            Fnode::add_child(&tgt_parent, &src, &name)
        })
    }
/// Rename a file or directory to new name
Rename a file or directory to new name
Rename a file or directory to new name
pub fn rename(&mut self, from: &Path, to: &Path) -> Result<()> {
        if self.read_only {
            return Err(Error::ReadOnly);
        }
        if from == to {
            return Ok(());
        }
        if to.starts_with(from) {
            return Err(Error::InvalidArgument);
        }
        let src = self.resolve(from)?;
        let tgt = match self.resolve(to) {
            Ok(tgt) => Some(tgt),
            Err(ref err) if *err == Error::NotFound => None,
            Err(err) => return Err(err),
        };
        {
            let src_fnode = src.read().unwrap();
            if src_fnode.is_root() {
                return Err(Error::IsRoot);
            }
            if let Some(ref tgt_fnode) = tgt {
                let tgt_fnode = tgt_fnode.read().unwrap();
                if tgt_fnode.is_root() {
                    return Err(Error::IsRoot);
                }
                if src_fnode.is_file() && tgt_fnode.is_dir() {
                    return Err(Error::IsDir);
                }
                if src_fnode.is_dir() {
                    if tgt_fnode.is_file() {
                        return Err(Error::NotDir);
                    }
                    if tgt_fnode.children_cnt() > 0 {
                        return Err(Error::NotEmpty);
                    }
                }
            }
        }
        let (tgt_parent, name) = self.resolve_parent(to)?;
        // begin and run transaction
        TxMgr::begin_trans(&self.txmgr)?.run_all(|| {
            // remove from source
            Fnode::remove_from_parent(&src)?;
            // remove target if it exists
            if let Some(tgt_fnode) = tgt {
                Fnode::remove_from_parent(&tgt_fnode)?;
                let mut tgt_fnode = tgt_fnode.write().unwrap();
                if tgt_fnode.is_file() {
                    tgt_fnode.make_mut()?.clear_vers()?;
                }
                tgt_fnode.make_del()?;
                self.fcache.remove(tgt_fnode.id());
            }
            // and then add to target
            Fnode::add_child(&tgt_parent, &src, &name)
        })
    }
pub fn rename ( & mut self , from : & Path , to : & Path ) -> Result < ( ) > { if self . read_only { return Err ( Error :: ReadOnly ) ; } if from == to { return Ok ( ( ) ) ; } if to . starts_with ( from ) { return Err ( Error :: InvalidArgument ) ; } let src = self . resolve ( from ) ? ; let tgt = match self . resolve ( to ) { Ok ( tgt ) => Some ( tgt ) , Err ( ref err ) if * err == Error :: NotFound => None , Err ( err ) => return Err ( err ) , } ; { let src_fnode = src . read ( ) . unwrap ( ) ; if src_fnode . is_root ( ) { return Err ( Error :: IsRoot ) ; } if let Some ( ref tgt_fnode ) = tgt { let tgt_fnode = tgt_fnode . read ( ) . unwrap ( ) ; if tgt_fnode . is_root ( ) { return Err ( Error :: IsRoot ) ; } if src_fnode . is_file ( ) && tgt_fnode . is_dir ( ) { return Err ( Error :: IsDir ) ; } if src_fnode . is_dir ( ) { if tgt_fnode . is_file ( ) { return Err ( Error :: NotDir ) ; } if tgt_fnode . children_cnt ( ) > 0 { return Err ( Error :: NotEmpty ) ; } } } } let ( tgt_parent , name ) = self . resolve_parent ( to ) ? ; // begin and run transaction TxMgr :: begin_trans ( & self . txmgr ) ? . run_all ( | | { // remove from source Fnode :: remove_from_parent ( & src ) ? ; // remove target if it exists if let Some ( tgt_fnode ) = tgt { Fnode :: remove_from_parent ( & tgt_fnode ) ? ; let mut tgt_fnode = tgt_fnode . write ( ) . unwrap ( ) ; if tgt_fnode . is_file ( ) { tgt_fnode . make_mut ( ) ? . clear_vers ( ) ? ; } tgt_fnode . make_del ( ) ? ; self . fcache . remove ( tgt_fnode . id ( ) ) ; } // and then add to target Fnode :: add_child ( & tgt_parent , & src , & name ) } ) }
Rename a file or directory to new name
Rename a file or directory to new name
&mut self
from
&Path
to
&Path
&mut self
from
&Path
to
&Path