pub fn copy_file_if_needed(src: &Path, dest: &PathBuf, hard_link: bool) -> Result<()> {
    if let Some(parent_directory) = dest.parent() {
        create_dir_all(parent_directory).map_err(|e| {
            Error::chain(format!("Was not able to create folder {}", parent_directory.display()), e)
        })?;
    }

    if hard_link {
        std::fs::hard_link(src, dest)?
    } else {
        let src_metadata = metadata(src)?;
        let src_mtime = FileTime::from_last_modification_time(&src_metadata);
        if Path::new(&dest).is_file() {
            let target_metadata = metadata(&dest)?;
            let target_mtime = FileTime::from_last_modification_time(&target_metadata);
            if !(src_mtime == target_mtime && src_metadata.len() == target_metadata.len()) {
                copy(src, &dest).map_err(|e| {
                    Error::chain(
                        format!(
                            "Was not able to copy file {} to {}",
                            src.display(),
                            dest.display()
                        ),
                        e,
                    )
                })?;
                set_file_mtime(&dest, src_mtime)?;
            }
        } else {
            copy(src, &dest).map_err(|e| {
                Error::chain(
                    format!("Was not able to copy file {} to {}", src.display(), dest.display()),
                    e,
                )
            })?;
            set_file_mtime(&dest, src_mtime)?;
        }
    }
    Ok(())
}
/// No copy occurs if all of the following conditions are satisfied:
/// 1. A file with the same name already exists in the dest path.
/// 2. Its modification timestamp is identical to that of the src file.
/// 3. Its filesize is identical to that of the src file.
No copy occurs if all of the following conditions are satisfied:
1. A file with the same name already exists in the dest path.
2. Its modification timestamp is identical to that of the src file.
3. Its filesize is identical to that of the src file.
No copy occurs if all of the following conditions are satisfied : 1 . A file with the same name already exists in the dest path . 2 . Its modification timestamp is identical to that of the src file . 3 . Its filesize is identical to that of the src file .
pub fn copy_file_if_needed(src: &Path, dest: &PathBuf, hard_link: bool) -> Result<()> {
    if let Some(parent_directory) = dest.parent() {
        create_dir_all(parent_directory).map_err(|e| {
            Error::chain(format!("Was not able to create folder {}", parent_directory.display()), e)
        })?;
    }
    if hard_link {
        std::fs::hard_link(src, dest)?
    } else {
        let src_metadata = metadata(src)?;
        let src_mtime = FileTime::from_last_modification_time(&src_metadata);
        if Path::new(&dest).is_file() {
            let target_metadata = metadata(&dest)?;
            let target_mtime = FileTime::from_last_modification_time(&target_metadata);
            if !(src_mtime == target_mtime && src_metadata.len() == target_metadata.len()) {
                copy(src, &dest).map_err(|e| {
                    Error::chain(
                        format!(
                            "Was not able to copy file {} to {}",
                            src.display(),
                            dest.display()
                        ),
                        e,
                    )
                })?;
                set_file_mtime(&dest, src_mtime)?;
            }
        } else {
            copy(src, &dest).map_err(|e| {
                Error::chain(
                    format!("Was not able to copy file {} to {}", src.display(), dest.display()),
                    e,
                )
            })?;
            set_file_mtime(&dest, src_mtime)?;
        }
    }
    Ok(())
}
pub fn copy_file_if_needed ( src : & Path , dest : & PathBuf , hard_link : bool ) -> Result < ( ) > { if let Some ( parent_directory ) = dest . parent ( ) { create_dir_all ( parent_directory ) . map_err ( | e | { Error :: chain ( format ! ( " " parent_directory display ( ) ) , e ) } ) ? ; } if hard_link { std :: fs :: hard_link ( src , dest ) ? } else { let src_metadata = metadata ( src ) ? ; let src_mtime = FileTime :: from_last_modification_time ( & src_metadata ) ; if Path :: new ( & dest ) . is_file ( ) { let target_metadata = metadata ( & dest ) ? ; let target_mtime = FileTime :: from_last_modification_time ( & target_metadata ) ; if ! ( src_mtime == target_mtime && src_metadata . len ( ) == target_metadata . len ( ) ) { copy ( src , & dest ) . map_err ( | e | { Error :: chain ( format ! ( " " src display ( ) dest display ( ) ) , e , ) } ) ? ; set_file_mtime ( & dest , src_mtime ) ? ; } } else { copy ( src , & dest ) . map_err ( | e | { Error :: chain ( format ! ( " " src display ( ) dest display ( ) ) , e , ) } ) ? ; set_file_mtime ( & dest , src_mtime ) ? ; } } Ok ( ( ) ) }
No copy occurs if all of the following conditions are satisfied:
1.
No copy occurs if all of the following conditions are satisfied : 1 .
src
&Path
dest
&PathBuf
hard_link
bool
src
&Path
dest
&PathBuf
hard_link
bool