fn copy(from: &PathBuf, to: &PathBuf, b: &Behavior) -> Result<(), ()> {
    if from.to_string_lossy() == "/dev/null" {
        /* workaround a limitation of fs::copy
         * https://github.com/rust-lang/rust/issues/79390
         */
        if let Err(err) = File::create(to) {
            show_error!(
                "install: cannot install '{}' to '{}': {}",
                from.display(),
                to.display(),
                err
            );
            return Err(());
        }
    } else if let Err(err) = fs::copy(from, to) {
        show_error!(
            "cannot install '{}' to '{}': {}",
            from.display(),
            to.display(),
            err
        );
        return Err(());
    }

    if mode::chmod(&to, b.mode()).is_err() {
        return Err(());
    }

    if !b.owner.is_empty() {
        let meta = match fs::metadata(to) {
            Ok(meta) => meta,
            Err(f) => crash!(1, "{}", f.to_string()),
        };

        let owner_id = match usr2uid(&b.owner) {
            Ok(g) => g,
            _ => crash!(1, "no such user: {}", b.owner),
        };
        let gid = meta.gid();
        match wrap_chown(
            to.as_path(),
            &meta,
            Some(owner_id),
            Some(gid),
            false,
            Verbosity::Normal,
        ) {
            Ok(n) => {
                if !n.is_empty() {
                    show_info!("{}", n);
                }
            }
            Err(e) => show_info!("{}", e),
        }
    }

    if !b.group.is_empty() {
        let meta = match fs::metadata(to) {
            Ok(meta) => meta,
            Err(f) => crash!(1, "{}", f.to_string()),
        };

        let group_id = match grp2gid(&b.group) {
            Ok(g) => g,
            _ => crash!(1, "no such group: {}", b.group),
        };
        match wrap_chgrp(to.as_path(), &meta, group_id, false, Verbosity::Normal) {
            Ok(n) => {
                if !n.is_empty() {
                    show_info!("{}", n);
                }
            }
            Err(e) => show_info!("{}", e),
        }
    }

    if b.verbose {
        show_info!("'{}' -> '{}'", from.display(), to.display());
    }

    Ok(())
}
/// Copy one file to a new location, changing metadata.
///
/// # Parameters
///
/// _from_ must exist as a non-directory.
/// _to_ must be a non-existent file, whose parent directory exists.
///
/// # Errors
///
/// If the copy system call fails, we print a verbose error and return an empty error value.
///
Copy one file to a new location, changing metadata.
Copy one file to a new location changing metadata .
fn copy(from: &PathBuf, to: &PathBuf, b: &Behavior) -> Result<(), ()> {
    if from.to_string_lossy() == "/dev/null" {
        /* workaround a limitation of fs::copy
         * https://github.com/rust-lang/rust/issues/79390
         */
        if let Err(err) = File::create(to) {
            show_error!(
                "install: cannot install '{}' to '{}': {}",
                from.display(),
                to.display(),
                err
            );
            return Err(());
        }
    } else if let Err(err) = fs::copy(from, to) {
        show_error!(
            "cannot install '{}' to '{}': {}",
            from.display(),
            to.display(),
            err
        );
        return Err(());
    }
    if mode::chmod(&to, b.mode()).is_err() {
        return Err(());
    }
    if !b.owner.is_empty() {
        let meta = match fs::metadata(to) {
            Ok(meta) => meta,
            Err(f) => crash!(1, "{}", f.to_string()),
        };
        let owner_id = match usr2uid(&b.owner) {
            Ok(g) => g,
            _ => crash!(1, "no such user: {}", b.owner),
        };
        let gid = meta.gid();
        match wrap_chown(
            to.as_path(),
            &meta,
            Some(owner_id),
            Some(gid),
            false,
            Verbosity::Normal,
        ) {
            Ok(n) => {
                if !n.is_empty() {
                    show_info!("{}", n);
                }
            }
            Err(e) => show_info!("{}", e),
        }
    }
    if !b.group.is_empty() {
        let meta = match fs::metadata(to) {
            Ok(meta) => meta,
            Err(f) => crash!(1, "{}", f.to_string()),
        };
        let group_id = match grp2gid(&b.group) {
            Ok(g) => g,
            _ => crash!(1, "no such group: {}", b.group),
        };
        match wrap_chgrp(to.as_path(), &meta, group_id, false, Verbosity::Normal) {
            Ok(n) => {
                if !n.is_empty() {
                    show_info!("{}", n);
                }
            }
            Err(e) => show_info!("{}", e),
        }
    }
    if b.verbose {
        show_info!("'{}' -> '{}'", from.display(), to.display());
    }
    Ok(())
}
fn copy ( from : & PathBuf , to : & PathBuf , b : & Behavior ) -> Result < ( ) , ( ) > { if from . to_string_lossy ( ) == " " { /* workaround a limitation of fs::copy
         * https://github.com/rust-lang/rust/issues/79390
         */ if let Err ( err ) = File :: create ( to ) { show_error ! ( " " from display ( ) to display ( ) err ) ; return Err ( ( ) ) ; } } else if let Err ( err ) = fs :: copy ( from , to ) { show_error ! ( " " from display ( ) to display ( ) err ) ; return Err ( ( ) ) ; } if mode :: chmod ( & to , b . mode ( ) ) . is_err ( ) { return Err ( ( ) ) ; } if ! b . owner . is_empty ( ) { let meta = match fs :: metadata ( to ) { Ok ( meta ) => meta , Err ( f ) => crash ! ( 1 " " f to_string ( ) ) , } ; let owner_id = match usr2uid ( & b . owner ) { Ok ( g ) => g , _ => crash ! ( 1 " " b owner ) , } ; let gid = meta . gid ( ) ; match wrap_chown ( to . as_path ( ) , & meta , Some ( owner_id ) , Some ( gid ) , false , Verbosity :: Normal , ) { Ok ( n ) => { if ! n . is_empty ( ) { show_info ! ( " " n ) ; } } Err ( e ) => show_info ! ( " " e ) , } } if ! b . group . is_empty ( ) { let meta = match fs :: metadata ( to ) { Ok ( meta ) => meta , Err ( f ) => crash ! ( 1 " " f to_string ( ) ) , } ; let group_id = match grp2gid ( & b . group ) { Ok ( g ) => g , _ => crash ! ( 1 " " b group ) , } ; match wrap_chgrp ( to . as_path ( ) , & meta , group_id , false , Verbosity :: Normal ) { Ok ( n ) => { if ! n . is_empty ( ) { show_info ! ( " " n ) ; } } Err ( e ) => show_info ! ( " " e ) , } } if b . verbose { show_info ! ( " " from display ( ) to display ( ) ) ; } Ok ( ( ) ) }
Copy one file to a new location, changing metadata.
Copy one file to a new location changing metadata .
from
&PathBuf
to
&PathBuf
b
&Behavior
from
&PathBuf
to
&PathBuf
b
&Behavior
errors
If the copy system call fails, we print a verbose error and return an empty error value.
If the copy system call fails we print a verbose error and return an empty error value .