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

        let opts;
        let src = self.resolve(from)?;
        {
            let fnode = src.read().unwrap();
            if !fnode.is_file() {
                return Err(Error::NotFile);
            }
            opts = fnode.get_opts();
        }

        let tgt = {
            match self.open_fnode(to) {
                Ok(tgt) => {
                    {
                        // if target and source is same fnode, do nothing
                        if Arc::ptr_eq(&tgt.fnode, &src) {
                            return Ok(());
                        }

                        let fnode = tgt.fnode.read().unwrap();
                        if !fnode.is_file() {
                            return Err(Error::NotFile);
                        }
                    }
                    tgt
                }
                Err(ref err) if *err == Error::NotFound => {
                    // target file doesn't exist
                    self.create_fnode(to, FileType::File, opts)?;
                    self.open_fnode(to)?
                }
                Err(err) => return Err(err),
            }
        };

        // begin and run transaction
        let tx_handle = TxMgr::begin_trans(&self.txmgr)?;
        tx_handle.run_all(|| {
            // truncate target file
            Fnode::set_len(tgt.clone(), 0, tx_handle.txid)?;

            // copy data from source to target
            let mut rdr = FnodeReader::new_current(src.clone())?;
            let mut wtr = FnodeWriter::new(tgt.clone(), tx_handle.txid);
            io::copy(&mut rdr, &mut wtr)?;
            wtr.finish()?;

            Ok(())
        })?;

        Ok(())
    }
/// Copy a regular file to another
Copy a regular file to another
Copy a regular file to another
pub fn copy(&mut self, from: &Path, to: &Path) -> Result<()> {
        if self.read_only {
            return Err(Error::ReadOnly);
        }
        let opts;
        let src = self.resolve(from)?;
        {
            let fnode = src.read().unwrap();
            if !fnode.is_file() {
                return Err(Error::NotFile);
            }
            opts = fnode.get_opts();
        }
        let tgt = {
            match self.open_fnode(to) {
                Ok(tgt) => {
                    {
                        // if target and source is same fnode, do nothing
                        if Arc::ptr_eq(&tgt.fnode, &src) {
                            return Ok(());
                        }
                        let fnode = tgt.fnode.read().unwrap();
                        if !fnode.is_file() {
                            return Err(Error::NotFile);
                        }
                    }
                    tgt
                }
                Err(ref err) if *err == Error::NotFound => {
                    // target file doesn't exist
                    self.create_fnode(to, FileType::File, opts)?;
                    self.open_fnode(to)?
                }
                Err(err) => return Err(err),
            }
        };
        // begin and run transaction
        let tx_handle = TxMgr::begin_trans(&self.txmgr)?;
        tx_handle.run_all(|| {
            // truncate target file
            Fnode::set_len(tgt.clone(), 0, tx_handle.txid)?;
            // copy data from source to target
            let mut rdr = FnodeReader::new_current(src.clone())?;
            let mut wtr = FnodeWriter::new(tgt.clone(), tx_handle.txid);
            io::copy(&mut rdr, &mut wtr)?;
            wtr.finish()?;
            Ok(())
        })?;
        Ok(())
    }
pub fn copy ( & mut self , from : & Path , to : & Path ) -> Result < ( ) > { if self . read_only { return Err ( Error :: ReadOnly ) ; } let opts ; let src = self . resolve ( from ) ? ; { let fnode = src . read ( ) . unwrap ( ) ; if ! fnode . is_file ( ) { return Err ( Error :: NotFile ) ; } opts = fnode . get_opts ( ) ; } let tgt = { match self . open_fnode ( to ) { Ok ( tgt ) => { { // if target and source is same fnode, do nothing if Arc :: ptr_eq ( & tgt . fnode , & src ) { return Ok ( ( ) ) ; } let fnode = tgt . fnode . read ( ) . unwrap ( ) ; if ! fnode . is_file ( ) { return Err ( Error :: NotFile ) ; } } tgt } Err ( ref err ) if * err == Error :: NotFound => { // target file doesn't exist self . create_fnode ( to , FileType :: File , opts ) ? ; self . open_fnode ( to ) ? } Err ( err ) => return Err ( err ) , } } ; // begin and run transaction let tx_handle = TxMgr :: begin_trans ( & self . txmgr ) ? ; tx_handle . run_all ( | | { // truncate target file Fnode :: set_len ( tgt . clone ( ) , 0 , tx_handle . txid ) ? ; // copy data from source to target let mut rdr = FnodeReader :: new_current ( src . clone ( ) ) ? ; let mut wtr = FnodeWriter :: new ( tgt . clone ( ) , tx_handle . txid ) ; io :: copy ( & mut rdr , & mut wtr ) ? ; wtr . finish ( ) ? ; Ok ( ( ) ) } ) ? ; Ok ( ( ) ) }
Copy a regular file to another
Copy a regular file to another
&mut self
from
&Path
to
&Path
&mut self
from
&Path
to
&Path