pub fn process(&self) -> Result<(), Error> {
        // panics when mimetypes are detected. This way you'll know which files are ignored
        // from processing

        self.init()?;
        let mut file_map: Files = Files::new(&self.result);

        let mut process_worker = |path: &Path| {
            let contents = Self::read_to_string(path).unwrap();
            let hash = Self::hasher(&contents);

            let get_name = |no_hash: bool| -> String {
                if no_hash {
                    format!(
                        "{}.{}",
                        path.file_stem().unwrap().to_str().unwrap(),
                        path.extension().unwrap().to_str().unwrap()
                    )
                } else {
                    format!(
                        "{}.{}.{}",
                        path.file_stem().unwrap().to_str().unwrap(),
                        hash,
                        path.extension().unwrap().to_str().unwrap()
                    )
                }
            };

            let no_hash_status = self.no_hash.iter().any(|no_hash| {
                match no_hash {
                    NoHashCategory::FilePaths(paths) => {
                        let no_hash_status = paths
                            .iter()
                            .any(|file_path| Path::new(&self.source).join(&file_path) == path);
                        no_hash_status
                    }
                    NoHashCategory::FileExtentions(extensions) => {
                        let mut no_hash_status = false;
                        if let Some(cur_extention) = path.extension() {
                            // .unwrap().to_str().unwrap();
                            if let Some(cur_extention) = cur_extention.to_str() {
                                no_hash_status = extensions.iter().any(|ext| &cur_extention == ext);
                            }
                        }
                        no_hash_status
                    }
                }
            });

            let new_name = get_name(no_hash_status);

            self.copy(path, &new_name);
            let (source, destination) = self.gen_map(path, &new_name);
            let _ = file_map.add(
                source.to_str().unwrap().into(),
                destination.to_str().unwrap().into(),
            );
        };

        for entry in WalkDir::new(&self.source)
            .follow_links(self.follow_links)
            .into_iter()
        {
            let entry = entry?;

            let path = entry.path();
            if !path.is_dir() {
                let path = Path::new(&path);

                match self.mime_types.as_ref() {
                    Some(mime_types) => {
                        for mime_type in mime_types.iter() {
                            let file_mime =
                                mime_guess::from_path(path).first().unwrap_or_else(|| {
                                    panic!("couldn't resolve MIME for file: {:?}", &path)
                                });
                            if &file_mime == mime_type {
                                process_worker(path);
                            }
                        }
                    }
                    None => process_worker(path),
                }
            }
        }

        file_map.to_env();
        Ok(())
    }
/// Processes files.
///
/// Panics when a weird MIME is encountered.
Processes files.
Panics when a weird MIME is encountered.
Processes files . Panics when a weird MIME is encountered .
pub fn process(&self) -> Result<(), Error> {
        // panics when mimetypes are detected. This way you'll know which files are ignored
        // from processing
        self.init()?;
        let mut file_map: Files = Files::new(&self.result);
        let mut process_worker = |path: &Path| {
            let contents = Self::read_to_string(path).unwrap();
            let hash = Self::hasher(&contents);
            let get_name = |no_hash: bool| -> String {
                if no_hash {
                    format!(
                        "{}.{}",
                        path.file_stem().unwrap().to_str().unwrap(),
                        path.extension().unwrap().to_str().unwrap()
                    )
                } else {
                    format!(
                        "{}.{}.{}",
                        path.file_stem().unwrap().to_str().unwrap(),
                        hash,
                        path.extension().unwrap().to_str().unwrap()
                    )
                }
            };
            let no_hash_status = self.no_hash.iter().any(|no_hash| {
                match no_hash {
                    NoHashCategory::FilePaths(paths) => {
                        let no_hash_status = paths
                            .iter()
                            .any(|file_path| Path::new(&self.source).join(&file_path) == path);
                        no_hash_status
                    }
                    NoHashCategory::FileExtentions(extensions) => {
                        let mut no_hash_status = false;
                        if let Some(cur_extention) = path.extension() {
                            // .unwrap().to_str().unwrap();
                            if let Some(cur_extention) = cur_extention.to_str() {
                                no_hash_status = extensions.iter().any(|ext| &cur_extention == ext);
                            }
                        }
                        no_hash_status
                    }
                }
            });
            let new_name = get_name(no_hash_status);
            self.copy(path, &new_name);
            let (source, destination) = self.gen_map(path, &new_name);
            let _ = file_map.add(
                source.to_str().unwrap().into(),
                destination.to_str().unwrap().into(),
            );
        };
        for entry in WalkDir::new(&self.source)
            .follow_links(self.follow_links)
            .into_iter()
        {
            let entry = entry?;
            let path = entry.path();
            if !path.is_dir() {
                let path = Path::new(&path);
                match self.mime_types.as_ref() {
                    Some(mime_types) => {
                        for mime_type in mime_types.iter() {
                            let file_mime =
                                mime_guess::from_path(path).first().unwrap_or_else(|| {
                                    panic!("couldn't resolve MIME for file: {:?}", &path)
                                });
                            if &file_mime == mime_type {
                                process_worker(path);
                            }
                        }
                    }
                    None => process_worker(path),
                }
            }
        }
        file_map.to_env();
        Ok(())
    }
pub fn process ( & self ) -> Result < ( ) , Error > { // panics when mimetypes are detected. This way you'll know which files are ignored // from processing self . init ( ) ? ; let mut file_map : Files = Files :: new ( & self . result ) ; let mut process_worker = | path : & Path | { let contents = Self :: read_to_string ( path ) . unwrap ( ) ; let hash = Self :: hasher ( & contents ) ; let get_name = | no_hash : bool | -> String { if no_hash { format ! ( " " path file_stem ( ) unwrap ( ) to_str ( ) unwrap ( ) path extension ( ) unwrap ( ) to_str ( ) unwrap ( ) ) } else { format ! ( " " path file_stem ( ) unwrap ( ) to_str ( ) unwrap ( ) hash path extension ( ) unwrap ( ) to_str ( ) unwrap ( ) ) } } ; let no_hash_status = self . no_hash . iter ( ) . any ( | no_hash | { match no_hash { NoHashCategory :: FilePaths ( paths ) => { let no_hash_status = paths . iter ( ) . any ( | file_path | Path :: new ( & self . source ) . join ( & file_path ) == path ) ; no_hash_status } NoHashCategory :: FileExtentions ( extensions ) => { let mut no_hash_status = false ; if let Some ( cur_extention ) = path . extension ( ) { // .unwrap().to_str().unwrap(); if let Some ( cur_extention ) = cur_extention . to_str ( ) { no_hash_status = extensions . iter ( ) . any ( | ext | & cur_extention == ext ) ; } } no_hash_status } } } ) ; let new_name = get_name ( no_hash_status ) ; self . copy ( path , & new_name ) ; let ( source , destination ) = self . gen_map ( path , & new_name ) ; let _ = file_map . add ( source . to_str ( ) . unwrap ( ) . into ( ) , destination . to_str ( ) . unwrap ( ) . into ( ) , ) ; } ; for entry in WalkDir :: new ( & self . source ) . follow_links ( self . follow_links ) . into_iter ( ) { let entry = entry ? ; let path = entry . path ( ) ; if ! path . is_dir ( ) { let path = Path :: new ( & path ) ; match self . mime_types . as_ref ( ) { Some ( mime_types ) => { for mime_type in mime_types . iter ( ) { let file_mime = mime_guess :: from_path ( path ) . first ( ) . unwrap_or_else ( | | { panic ! ( " " path ) } ) ; if & file_mime == mime_type { process_worker ( path ) ; } } } None => process_worker ( path ) , } } } file_map . to_env ( ) ; Ok ( ( ) ) }
Processes files.
Processes files .
&self
&self