pub fn download(config: &DownloadConfig) -> Result<()> {
    // Build image location.  Ideally the parser would use conflicts_with
    // (and an ArgGroup for streams), but that doesn't play well with
    // default arguments, so we manually prioritize modes.
    let location: Box<dyn ImageLocation> = if let Some(ref image_url) = config.image_url {
        Box::new(UrlLocation::new(image_url, config.fetch_retries))
    } else {
        Box::new(StreamLocation::new(
            &config.stream,
            config.architecture.as_str(),
            &config.platform,
            &config.format,
            config.stream_base_url.as_ref(),
            config.fetch_retries,
        )?)
    };
    eprintln!("{}", location);

    // walk sources
    let mut sources = location.sources()?;
    if sources.is_empty() {
        bail!("no artifacts found");
    }
    for mut source in sources.iter_mut() {
        // set up image source
        if source.signature.is_none() {
            if config.insecure {
                eprintln!("Signature not found; skipping verification as requested");
            } else {
                bail!("--insecure not specified and signature not found");
            }
        }

        // calculate paths
        let (decompress, filename) = should_decompress(config.decompress, &source.filename);
        let mut path = PathBuf::new();
        path.push(&config.directory);
        path.push(filename);
        let sig_path = path.with_file_name(format!("{}.sig", filename));

        // check existing image and signature; don't redownload if OK
        // If we decompressed last time, the call will fail because we can't
        // check the old signature.  If we didn't decompress last time but are
        // decompressing this time, we're not smart enough to decompress the
        // existing file.
        if !decompress
            && check_image_and_sig(source, &path, &sig_path, VerifyKeys::Production).is_ok()
        {
            // report the output file path and keep going
            println!("{}", path.display());
            continue;
        }

        // Write the image and signature.  Only write the signature if we
        // weren't asked to decompress, regardless of whether we actually
        // did.
        if let Err(err) = write_image_and_sig(
            &mut source,
            &path,
            &sig_path,
            decompress,
            !config.decompress,
            VerifyKeys::Production,
        ) {
            // delete output files, which may not have been created yet
            let _ = remove_file(&path);
            let _ = remove_file(&sig_path);

            // fail
            return Err(err);
        }

        // report the output file path
        println!("{}", path.display());
    }

    Ok(())
}
// Download all artifacts for an image and verify their signatures.
Download all artifacts for an image and verify their signatures.
Download all artifacts for an image and verify their signatures .
pub fn download(config: &DownloadConfig) -> Result<()> {
    // Build image location.  Ideally the parser would use conflicts_with
    // (and an ArgGroup for streams), but that doesn't play well with
    // default arguments, so we manually prioritize modes.
    let location: Box<dyn ImageLocation> = if let Some(ref image_url) = config.image_url {
        Box::new(UrlLocation::new(image_url, config.fetch_retries))
    } else {
        Box::new(StreamLocation::new(
            &config.stream,
            config.architecture.as_str(),
            &config.platform,
            &config.format,
            config.stream_base_url.as_ref(),
            config.fetch_retries,
        )?)
    };
    eprintln!("{}", location);
    // walk sources
    let mut sources = location.sources()?;
    if sources.is_empty() {
        bail!("no artifacts found");
    }
    for mut source in sources.iter_mut() {
        // set up image source
        if source.signature.is_none() {
            if config.insecure {
                eprintln!("Signature not found; skipping verification as requested");
            } else {
                bail!("--insecure not specified and signature not found");
            }
        }
        // calculate paths
        let (decompress, filename) = should_decompress(config.decompress, &source.filename);
        let mut path = PathBuf::new();
        path.push(&config.directory);
        path.push(filename);
        let sig_path = path.with_file_name(format!("{}.sig", filename));
        // check existing image and signature; don't redownload if OK
        // If we decompressed last time, the call will fail because we can't
        // check the old signature.  If we didn't decompress last time but are
        // decompressing this time, we're not smart enough to decompress the
        // existing file.
        if !decompress
            && check_image_and_sig(source, &path, &sig_path, VerifyKeys::Production).is_ok()
        {
            // report the output file path and keep going
            println!("{}", path.display());
            continue;
        }
        // Write the image and signature.  Only write the signature if we
        // weren't asked to decompress, regardless of whether we actually
        // did.
        if let Err(err) = write_image_and_sig(
            &mut source,
            &path,
            &sig_path,
            decompress,
            !config.decompress,
            VerifyKeys::Production,
        ) {
            // delete output files, which may not have been created yet
            let _ = remove_file(&path);
            let _ = remove_file(&sig_path);
            // fail
            return Err(err);
        }
        // report the output file path
        println!("{}", path.display());
    }
    Ok(())
}
pub fn download ( config : & DownloadConfig ) -> Result < ( ) > { // Build image location.  Ideally the parser would use conflicts_with // (and an ArgGroup for streams), but that doesn't play well with // default arguments, so we manually prioritize modes. let location : Box < dyn ImageLocation > = if let Some ( ref image_url ) = config . image_url { Box :: new ( UrlLocation :: new ( image_url , config . fetch_retries ) ) } else { Box :: new ( StreamLocation :: new ( & config . stream , config . architecture . as_str ( ) , & config . platform , & config . format , config . stream_base_url . as_ref ( ) , config . fetch_retries , ) ? ) } ; eprintln ! ( " " location ) ; // walk sources let mut sources = location . sources ( ) ? ; if sources . is_empty ( ) { bail ! ( " " ) ; } for mut source in sources . iter_mut ( ) { // set up image source if source . signature . is_none ( ) { if config . insecure { eprintln ! ( " " ) ; } else { bail ! ( " " ) ; } } // calculate paths let ( decompress , filename ) = should_decompress ( config . decompress , & source . filename ) ; let mut path = PathBuf :: new ( ) ; path . push ( & config . directory ) ; path . push ( filename ) ; let sig_path = path . with_file_name ( format ! ( " " filename ) ) ; // check existing image and signature; don't redownload if OK // If we decompressed last time, the call will fail because we can't // check the old signature.  If we didn't decompress last time but are // decompressing this time, we're not smart enough to decompress the // existing file. if ! decompress && check_image_and_sig ( source , & path , & sig_path , VerifyKeys :: Production ) . is_ok ( ) { // report the output file path and keep going println ! ( " " path display ( ) ) ; continue ; } // Write the image and signature.  Only write the signature if we // weren't asked to decompress, regardless of whether we actually // did. if let Err ( err ) = write_image_and_sig ( & mut source , & path , & sig_path , decompress , ! config . decompress , VerifyKeys :: Production , ) { // delete output files, which may not have been created yet let _ = remove_file ( & path ) ; let _ = remove_file ( & sig_path ) ; // fail return Err ( err ) ; } // report the output file path println ! ( " " path display ( ) ) ; } Ok ( ( ) ) }
Download all artifacts for an image and verify their signatures.
Download all artifacts for an image and verify their signatures .
config
&DownloadConfig
config
&DownloadConfig