pub fn start(ui: &mut UI,
             bldr_url: &str,
             additional_release_channel: &Option<ChannelIdent>,
             token: &str,
             archive_path: &Path,
             force_upload: bool,
             key_path: &Path)
             -> Result<()> {
    let mut archive = PackageArchive::new(PathBuf::from(archive_path));

    let api_client = Client::new(bldr_url, PRODUCT, VERSION, None)?;

    upload_public_key(ui, token, &api_client, &mut archive, &key_path)?;

    let tdeps = archive.tdeps()?;
    let ident = archive.ident()?;
    let target = archive.target()?;

    match api_client.show_package((&ident, target), &ChannelIdent::unstable(), Some(token)) {
        Ok(_) if !force_upload => {
            ui.status(Status::Using, format!("existing {}", &ident))?;
            Ok(())
        }
        Err(api_client::Error::APIError(StatusCode::NotFound, _)) | Ok(_) => {
            for dep in tdeps.into_iter() {
                match api_client.show_package((&dep, target),
                                              &ChannelIdent::unstable(),
                                              Some(token))
                {
                    Ok(_) => ui.status(Status::Using, format!("existing {}", &dep))?,
                    Err(api_client::Error::APIError(StatusCode::NotFound, _)) => {
                        let candidate_path = match archive_path.parent() {
                            Some(p) => PathBuf::from(p),
                            None => unreachable!(),
                        };
                        let upload = || {
                            attempt_upload_dep(ui,
                                               &api_client,
                                               token,
                                               (&dep, target),
                                               additional_release_channel,
                                               &candidate_path,
                                               key_path)
                        };
                        match retry(wait_for(RETRY_WAIT, RETRIES), upload) {
                            Ok(_) => trace!("attempt_upload_dep succeeded"),
                            Err(_) => {
                                return Err(Error::from(api_client::Error::UploadFailed(format!(
                                    "We tried {} times but could not upload {}. Giving up.",
                                    RETRIES, &dep
                                ))));
                            }
                        }
                    }
                    Err(e) => return Err(Error::from(e)),
                }
            }

            let upload = || {
                upload_into_depot(ui,
                                  &api_client,
                                  token,
                                  (&ident, target),
                                  additional_release_channel,
                                  force_upload,
                                  &mut archive)
            };
            match retry(wait_for(RETRY_WAIT, RETRIES), upload) {
                Ok(_) => trace!("upload_into_depot succeeded"),
                Err(_) => {
                    return Err(Error::from(api_client::Error::UploadFailed(format!(
                        "We tried {} times but could not upload {}. Giving up.",
                        RETRIES, &ident
                    ))));
                }
            }
            ui.end(format!("Upload of {} complete.", &ident))?;
            Ok(())
        }
        Err(e) => Err(Error::from(e)),
    }
}
/// Upload a package from the cache to a Depot. The latest version/release of the package
/// will be uploaded if not specified.
///
/// # Failures
///
/// * Fails if it cannot find a package
/// * Fails if the package doesn't have a `.hart` file in the cache
/// * Fails if it cannot upload the file
Upload a package from the cache to a Depot. The latest version/release of the package
will be uploaded if not specified.
Upload a package from the cache to a Depot . The latest version / release of the package will be uploaded if not specified .
pub fn start(ui: &mut UI,
             bldr_url: &str,
             additional_release_channel: &Option<ChannelIdent>,
             token: &str,
             archive_path: &Path,
             force_upload: bool,
             key_path: &Path)
             -> Result<()> {
    let mut archive = PackageArchive::new(PathBuf::from(archive_path));
    let api_client = Client::new(bldr_url, PRODUCT, VERSION, None)?;
    upload_public_key(ui, token, &api_client, &mut archive, &key_path)?;
    let tdeps = archive.tdeps()?;
    let ident = archive.ident()?;
    let target = archive.target()?;
    match api_client.show_package((&ident, target), &ChannelIdent::unstable(), Some(token)) {
        Ok(_) if !force_upload => {
            ui.status(Status::Using, format!("existing {}", &ident))?;
            Ok(())
        }
        Err(api_client::Error::APIError(StatusCode::NotFound, _)) | Ok(_) => {
            for dep in tdeps.into_iter() {
                match api_client.show_package((&dep, target),
                                              &ChannelIdent::unstable(),
                                              Some(token))
                {
                    Ok(_) => ui.status(Status::Using, format!("existing {}", &dep))?,
                    Err(api_client::Error::APIError(StatusCode::NotFound, _)) => {
                        let candidate_path = match archive_path.parent() {
                            Some(p) => PathBuf::from(p),
                            None => unreachable!(),
                        };
                        let upload = || {
                            attempt_upload_dep(ui,
                                               &api_client,
                                               token,
                                               (&dep, target),
                                               additional_release_channel,
                                               &candidate_path,
                                               key_path)
                        };
                        match retry(wait_for(RETRY_WAIT, RETRIES), upload) {
                            Ok(_) => trace!("attempt_upload_dep succeeded"),
                            Err(_) => {
                                return Err(Error::from(api_client::Error::UploadFailed(format!(
                                    "We tried {} times but could not upload {}. Giving up.",
                                    RETRIES, &dep
                                ))));
                            }
                        }
                    }
                    Err(e) => return Err(Error::from(e)),
                }
            }
            let upload = || {
                upload_into_depot(ui,
                                  &api_client,
                                  token,
                                  (&ident, target),
                                  additional_release_channel,
                                  force_upload,
                                  &mut archive)
            };
            match retry(wait_for(RETRY_WAIT, RETRIES), upload) {
                Ok(_) => trace!("upload_into_depot succeeded"),
                Err(_) => {
                    return Err(Error::from(api_client::Error::UploadFailed(format!(
                        "We tried {} times but could not upload {}. Giving up.",
                        RETRIES, &ident
                    ))));
                }
            }
            ui.end(format!("Upload of {} complete.", &ident))?;
            Ok(())
        }
        Err(e) => Err(Error::from(e)),
    }
}
pub fn start ( ui : & mut UI , bldr_url : & str , additional_release_channel : & Option < ChannelIdent > , token : & str , archive_path : & Path , force_upload : bool , key_path : & Path ) -> Result < ( ) > { let mut archive = PackageArchive :: new ( PathBuf :: from ( archive_path ) ) ; let api_client = Client :: new ( bldr_url , PRODUCT , VERSION , None ) ? ; upload_public_key ( ui , token , & api_client , & mut archive , & key_path ) ? ; let tdeps = archive . tdeps ( ) ? ; let ident = archive . ident ( ) ? ; let target = archive . target ( ) ? ; match api_client . show_package ( ( & ident , target ) , & ChannelIdent :: unstable ( ) , Some ( token ) ) { Ok ( _ ) if ! force_upload => { ui . status ( Status :: Using , format ! ( " " ident ) ) ? ; Ok ( ( ) ) } Err ( api_client :: Error :: APIError ( StatusCode :: NotFound , _ ) ) | Ok ( _ ) => { for dep in tdeps . into_iter ( ) { match api_client . show_package ( ( & dep , target ) , & ChannelIdent :: unstable ( ) , Some ( token ) ) { Ok ( _ ) => ui . status ( Status :: Using , format ! ( " " dep ) ) ? , Err ( api_client :: Error :: APIError ( StatusCode :: NotFound , _ ) ) => { let candidate_path = match archive_path . parent ( ) { Some ( p ) => PathBuf :: from ( p ) , None => unreachable ! ( ) , } ; let upload = | | { attempt_upload_dep ( ui , & api_client , token , ( & dep , target ) , additional_release_channel , & candidate_path , key_path ) } ; match retry ( wait_for ( RETRY_WAIT , RETRIES ) , upload ) { Ok ( _ ) => trace ! ( " " ) , Err ( _ ) => { return Err ( Error :: from ( api_client :: Error :: UploadFailed ( format ! ( " " RETRIES dep ) ) ) ) ; } } } Err ( e ) => return Err ( Error :: from ( e ) ) , } } let upload = | | { upload_into_depot ( ui , & api_client , token , ( & ident , target ) , additional_release_channel , force_upload , & mut archive ) } ; match retry ( wait_for ( RETRY_WAIT , RETRIES ) , upload ) { Ok ( _ ) => trace ! ( " " ) , Err ( _ ) => { return Err ( Error :: from ( api_client :: Error :: UploadFailed ( format ! ( " " RETRIES ident ) ) ) ) ; } } ui . end ( format ! ( " " ident ) ) ? ; Ok ( ( ) ) } Err ( e ) => Err ( Error :: from ( e ) ) , } }
Upload a package from the cache to a Depot.
Upload a package from the cache to a Depot .
ui
&mut UI
bldr_url
&str
additional_release_channel
&Option<ChannelIdent>
token
&str
archive_path
&Path
force_upload
bool
key_path
&Path
ui
&mut UI
bldr_url
&str
additional_release_channel
&Option<ChannelIdent>
token
&str
archive_path
&Path
force_upload
bool
key_path
&Path
failures
Fails if it cannot find a package
Fails if the package doesn't have a `.hart` file in the cache
Fails if it cannot upload the file
Fails if it cannot find a package Fails if the package doesn ' t have a ` . hart ` file in the cache Fails if it cannot upload the file