pub fn install<F>(messages: &Messages, zipfile: &mut F, dir: &PathBuf) -> Result<()>
where
    F: Read + Seek,
{
    if !dir.is_dir() {
        let err = anyhow!(
            "install: Destination '{}' is not a directory",
            dir.display(),
        );

        return Err(err);
    }

    let mut zip = ZipArchive::new(zipfile).expect("new ziparchive");

    for i in 0..zip.len() {
        let mut file = zip.by_index(i)?;

        // Perform some sanitization on the filename.
        // We assume here that HashiCorp zips only ever have files at the root
        // of the zip file, this allows us to not care about their paths.
        let filename = file.name();

        // Attempt to get the basename of the filename
        let basename = Path::new(filename).file_name()
            .ok_or_else(|| {
                anyhow!("Couldn't get basename from: {}", filename)
            })?;

        // Finally get a pathbuf of the basename
        let filename = Path::new(basename).to_path_buf();

        messages.extracting_file(&filename, &dir);

        // Extract the file
        let tmpfile = extract(&mut file, &dir)?;

        // Persist the tmpfile to the real dest.
        let dest = dir.join(&filename);
        tmpfile.persist(&dest)?;

        // We can't put the attribute directly on the `if` here until
        // Rust 1.43.0.
        // To avoid raising the MSRV from 1.40.0, we use a new scope here.
        // Set the permissions on the installed file.
        #[cfg(target_family = "unix")]
        {
            if let Some(mode) = file.unix_mode() {
                fs::set_permissions(&dest, Permissions::from_mode(mode))?;
            }
        }
    }

    Ok(())
}
// Installs files from the gien `zipfile` under the directory at `dir`.
Installs files from the gien `zipfile` under the directory at `dir`.
Installs files from the gien ` zipfile ` under the directory at ` dir ` .
pub fn install<F>(messages: &Messages, zipfile: &mut F, dir: &PathBuf) -> Result<()>
where
    F: Read + Seek,
{
    if !dir.is_dir() {
        let err = anyhow!(
            "install: Destination '{}' is not a directory",
            dir.display(),
        );
        return Err(err);
    }
    let mut zip = ZipArchive::new(zipfile).expect("new ziparchive");
    for i in 0..zip.len() {
        let mut file = zip.by_index(i)?;
        // Perform some sanitization on the filename.
        // We assume here that HashiCorp zips only ever have files at the root
        // of the zip file, this allows us to not care about their paths.
        let filename = file.name();
        // Attempt to get the basename of the filename
        let basename = Path::new(filename).file_name()
            .ok_or_else(|| {
                anyhow!("Couldn't get basename from: {}", filename)
            })?;
        // Finally get a pathbuf of the basename
        let filename = Path::new(basename).to_path_buf();
        messages.extracting_file(&filename, &dir);
        // Extract the file
        let tmpfile = extract(&mut file, &dir)?;
        // Persist the tmpfile to the real dest.
        let dest = dir.join(&filename);
        tmpfile.persist(&dest)?;
        // We can't put the attribute directly on the `if` here until
        // Rust 1.43.0.
        // To avoid raising the MSRV from 1.40.0, we use a new scope here.
        // Set the permissions on the installed file.
        #[cfg(target_family = "unix")]
        {
            if let Some(mode) = file.unix_mode() {
                fs::set_permissions(&dest, Permissions::from_mode(mode))?;
            }
        }
    }
    Ok(())
}
pub fn install < F > ( messages : & Messages , zipfile : & mut F , dir : & PathBuf ) -> Result < ( ) > where F : Read + Seek , { if ! dir . is_dir ( ) { let err = anyhow ! ( " " dir display ( ) ) ; return Err ( err ) ; } let mut zip = ZipArchive :: new ( zipfile ) . expect ( " " ) ; for i in 0 .. zip . len ( ) { let mut file = zip . by_index ( i ) ? ; // Perform some sanitization on the filename. // We assume here that HashiCorp zips only ever have files at the root // of the zip file, this allows us to not care about their paths. let filename = file . name ( ) ; // Attempt to get the basename of the filename let basename = Path :: new ( filename ) . file_name ( ) . ok_or_else ( | | { anyhow ! ( " " filename ) } ) ? ; // Finally get a pathbuf of the basename let filename = Path :: new ( basename ) . to_path_buf ( ) ; messages . extracting_file ( & filename , & dir ) ; // Extract the file let tmpfile = extract ( & mut file , & dir ) ? ; // Persist the tmpfile to the real dest. let dest = dir . join ( & filename ) ; tmpfile . persist ( & dest ) ? ; // We can't put the attribute directly on the `if` here until // Rust 1.43.0. // To avoid raising the MSRV from 1.40.0, we use a new scope here. // Set the permissions on the installed file. # [ cfg ( target_family " " ) ] { if let Some ( mode ) = file . unix_mode ( ) { fs :: set_permissions ( & dest , Permissions :: from_mode ( mode ) ) ? ; } } } Ok ( ( ) ) }
Installs files from the gien `zipfile` under the directory at `dir`.
Installs files from the gien ` zipfile ` under the directory at ` dir ` .
messages
&Messages
zipfile
&mut F
dir
&PathBuf
messages
&Messages
zipfile
&mut F
dir
&PathBuf