/// save the bin script for a command into the .bin directory
save the bin script for a command into the .bin directory
save the bin script for a command into the . bin directory
fn save<P: AsRef<Path>>(data: String, directory: P, command_name: String) -> Result<(), Error> {
    let mut dir = directory.as_ref().join(PACKAGES_DIR_NAME);
    dir.push(BIN_DIR_NAME);
    if !dir.exists() {
        fs::create_dir_all(&dir)
            .map_err(|e| Error::SaveError(command_name.clone(), e.to_string()))?;
    }
    let script_path = dir.join(command_name.clone());
    #[cfg(unix)]
    let maybe_unix_mode = {
        use std::os::unix::fs::PermissionsExt;
        script_path.metadata().map(|md| md.permissions().mode())
    };
    let mut script_file = {
        let mut oo = fs::OpenOptions::new();
        oo.create(true).truncate(true).write(true);
        #[cfg(unix)]
        let oo = {
            use std::os::unix::fs::OpenOptionsExt;
            if let Ok(unix_mode) = maybe_unix_mode {
                oo.mode(unix_mode | 0o110)
            } else {
                oo.mode(0o754)
            }
        };
        oo.open(&script_path).map_err(|e| {
            Error::FileCreationError(script_path.to_string_lossy().to_string(), e.to_string())
        })?
    };
    script_file
        .write(data.as_bytes())
        .map_err(|e| Error::SaveError(command_name.clone(), e.to_string()))?;
    Ok(())
}
fn save < P : AsRef < Path > > ( data : String , directory : P , command_name : String ) -> Result < ( ) , Error > { let mut dir = directory . as_ref ( ) . join ( PACKAGES_DIR_NAME ) ; dir . push ( BIN_DIR_NAME ) ; if ! dir . exists ( ) { fs :: create_dir_all ( & dir ) . map_err ( | e | Error :: SaveError ( command_name . clone ( ) , e . to_string ( ) ) ) ? ; } let script_path = dir . join ( command_name . clone ( ) ) ; # [ cfg ( unix ) ] let maybe_unix_mode = { use std :: os :: unix :: fs :: PermissionsExt ; script_path . metadata ( ) . map ( | md | md . permissions ( ) . mode ( ) ) } ; let mut script_file = { let mut oo = fs :: OpenOptions :: new ( ) ; oo . create ( true ) . truncate ( true ) . write ( true ) ; # [ cfg ( unix ) ] let oo = { use std :: os :: unix :: fs :: OpenOptionsExt ; if let Ok ( unix_mode ) = maybe_unix_mode { oo . mode ( unix_mode | 0o110 ) } else { oo . mode ( 0o754 ) } } ; oo . open ( & script_path ) . map_err ( | e | { Error :: FileCreationError ( script_path . to_string_lossy ( ) . to_string ( ) , e . to_string ( ) ) } ) ? } ; script_file . write ( data . as_bytes ( ) ) . map_err ( | e | Error :: SaveError ( command_name . clone ( ) , e . to_string ( ) ) ) ? ; Ok ( ( ) ) }
save the bin script for a command into the .bin directory
save the bin script for a command into the . bin directory
data
String
directory
P
command_name
String