pub fn copy_tree<P, Q>(mut self, src: P, dest: Q) -> Result<CopyStats>
    where
        P: AsRef<Path>,
        Q: AsRef<Path>,
    {
        let src = src.as_ref();
        let dest = dest.as_ref();

        let mut stats = CopyStats::default();

        // TODO: Handle the src not being a dir: copy that single entry.
        if self.create_destination {
            if !dest.is_dir() {
                copy_dir(src, dest, &mut stats)?;
            }
        } else if !dest.is_dir() {
            return Err(Error::new(ErrorKind::DestinationDoesNotExist, dest));
        }

        let mut subdir_queue: VecDeque<PathBuf> = VecDeque::new();
        subdir_queue.push_back(PathBuf::from(""));

        while let Some(subdir) = subdir_queue.pop_front() {
            let subdir_full_path = src.join(&subdir);
            for entry in fs::read_dir(&subdir_full_path)
                .map_err(|io| Error::from_io_error(io, ErrorKind::ReadDir, &subdir_full_path))?
            {
                let dir_entry = entry.map_err(|io| {
                    Error::from_io_error(io, ErrorKind::ReadDir, &subdir_full_path)
                })?;
                let entry_subpath = subdir.join(dir_entry.file_name());
                if let Some(filter) = &mut self.filter {
                    if !filter(&entry_subpath, &dir_entry)? {
                        stats.filtered_out += 1;
                        continue;
                    }
                }
                let src_fullpath = src.join(&entry_subpath);
                let dest_fullpath = dest.join(&entry_subpath);
                let file_type = dir_entry
                    .file_type()
                    .map_err(|io| Error::from_io_error(io, ErrorKind::ReadDir, &src_fullpath))?;
                if file_type.is_file() {
                    copy_file(&src_fullpath, &dest_fullpath, &mut stats)?
                } else if file_type.is_dir() {
                    copy_dir(&src_fullpath, &dest_fullpath, &mut stats)?;
                    subdir_queue.push_back(entry_subpath.clone());
                } else if file_type.is_symlink() {
                    copy_symlink(&src_fullpath, &dest_fullpath, &mut stats)?
                } else {
                    // TODO: Include the file type.
                    return Err(Error::new(ErrorKind::UnsupportedFileType, src_fullpath));
                }
                if let Some(ref mut f) = self.after_entry_copied {
                    f(&entry_subpath, &file_type, &stats)?;
                }
            }
        }
        Ok(stats)
    }
/// Copy the tree according to the options.
///
/// Returns [CopyStats] describing how many files were copied, etc.
Copy the tree according to the options.
Returns [CopyStats] describing how many files were copied, etc.
Copy the tree according to the options . Returns [ CopyStats ] describing how many files were copied etc .
pub fn copy_tree<P, Q>(mut self, src: P, dest: Q) -> Result<CopyStats>
    where
        P: AsRef<Path>,
        Q: AsRef<Path>,
    {
        let src = src.as_ref();
        let dest = dest.as_ref();
        let mut stats = CopyStats::default();
        // TODO: Handle the src not being a dir: copy that single entry.
        if self.create_destination {
            if !dest.is_dir() {
                copy_dir(src, dest, &mut stats)?;
            }
        } else if !dest.is_dir() {
            return Err(Error::new(ErrorKind::DestinationDoesNotExist, dest));
        }
        let mut subdir_queue: VecDeque<PathBuf> = VecDeque::new();
        subdir_queue.push_back(PathBuf::from(""));
        while let Some(subdir) = subdir_queue.pop_front() {
            let subdir_full_path = src.join(&subdir);
            for entry in fs::read_dir(&subdir_full_path)
                .map_err(|io| Error::from_io_error(io, ErrorKind::ReadDir, &subdir_full_path))?
            {
                let dir_entry = entry.map_err(|io| {
                    Error::from_io_error(io, ErrorKind::ReadDir, &subdir_full_path)
                })?;
                let entry_subpath = subdir.join(dir_entry.file_name());
                if let Some(filter) = &mut self.filter {
                    if !filter(&entry_subpath, &dir_entry)? {
                        stats.filtered_out += 1;
                        continue;
                    }
                }
                let src_fullpath = src.join(&entry_subpath);
                let dest_fullpath = dest.join(&entry_subpath);
                let file_type = dir_entry
                    .file_type()
                    .map_err(|io| Error::from_io_error(io, ErrorKind::ReadDir, &src_fullpath))?;
                if file_type.is_file() {
                    copy_file(&src_fullpath, &dest_fullpath, &mut stats)?
                } else if file_type.is_dir() {
                    copy_dir(&src_fullpath, &dest_fullpath, &mut stats)?;
                    subdir_queue.push_back(entry_subpath.clone());
                } else if file_type.is_symlink() {
                    copy_symlink(&src_fullpath, &dest_fullpath, &mut stats)?
                } else {
                    // TODO: Include the file type.
                    return Err(Error::new(ErrorKind::UnsupportedFileType, src_fullpath));
                }
                if let Some(ref mut f) = self.after_entry_copied {
                    f(&entry_subpath, &file_type, &stats)?;
                }
            }
        }
        Ok(stats)
    }
pub fn copy_tree < P , Q > ( mut self , src : P , dest : Q ) -> Result < CopyStats > where P : AsRef < Path > , Q : AsRef < Path > , { let src = src . as_ref ( ) ; let dest = dest . as_ref ( ) ; let mut stats = CopyStats :: default ( ) ; // TODO: Handle the src not being a dir: copy that single entry. if self . create_destination { if ! dest . is_dir ( ) { copy_dir ( src , dest , & mut stats ) ? ; } } else if ! dest . is_dir ( ) { return Err ( Error :: new ( ErrorKind :: DestinationDoesNotExist , dest ) ) ; } let mut subdir_queue : VecDeque < PathBuf > = VecDeque :: new ( ) ; subdir_queue . push_back ( PathBuf :: from ( " " ) ) ; while let Some ( subdir ) = subdir_queue . pop_front ( ) { let subdir_full_path = src . join ( & subdir ) ; for entry in fs :: read_dir ( & subdir_full_path ) . map_err ( | io | Error :: from_io_error ( io , ErrorKind :: ReadDir , & subdir_full_path ) ) ? { let dir_entry = entry . map_err ( | io | { Error :: from_io_error ( io , ErrorKind :: ReadDir , & subdir_full_path ) } ) ? ; let entry_subpath = subdir . join ( dir_entry . file_name ( ) ) ; if let Some ( filter ) = & mut self . filter { if ! filter ( & entry_subpath , & dir_entry ) ? { stats . filtered_out += 1 ; continue ; } } let src_fullpath = src . join ( & entry_subpath ) ; let dest_fullpath = dest . join ( & entry_subpath ) ; let file_type = dir_entry . file_type ( ) . map_err ( | io | Error :: from_io_error ( io , ErrorKind :: ReadDir , & src_fullpath ) ) ? ; if file_type . is_file ( ) { copy_file ( & src_fullpath , & dest_fullpath , & mut stats ) ? } else if file_type . is_dir ( ) { copy_dir ( & src_fullpath , & dest_fullpath , & mut stats ) ? ; subdir_queue . push_back ( entry_subpath . clone ( ) ) ; } else if file_type . is_symlink ( ) { copy_symlink ( & src_fullpath , & dest_fullpath , & mut stats ) ? } else { // TODO: Include the file type. return Err ( Error :: new ( ErrorKind :: UnsupportedFileType , src_fullpath ) ) ; } if let Some ( ref mut f ) = self . after_entry_copied { f ( & entry_subpath , & file_type , & stats ) ? ; } } } Ok ( stats ) }
Copy the tree according to the options.
Copy the tree according to the options .
mut self
src
P
dest
Q
mut self
src
P
dest
Q