pub fn download_and_extract(&self, label: String, cipd_pkg: String) -> Result<PathBuf> {
        let mut executor = LocalExecutor::new().unwrap();
        executor.run_singlethreaded(async move {
            let root_path = match read_env_path("FEMU_DOWNLOAD_DIR") {
                Ok(path) => path,
                _ => {
                    let default_path = get_sdk_data_dir()?.join("femu");
                    if !default_path.exists() {
                        create_dir_all(&default_path)?;
                    }
                    default_path
                }
            };
            let arch = match env::consts::OS {
                "macos" => "mac-amd64",
                _ => "linux-amd64",
            };
            let url = format!(
                "https://chrome-infra-packages.appspot.com/dl/fuchsia/{}/{}/+/{}",
                cipd_pkg, arch, label
            )
            .parse::<Uri>()?;
            let name = cipd_pkg
                .split('/')
                .last()
                .ok_or(anyhow!("Cannot identify filename from {}", cipd_pkg))?;
            let cipd_zip = root_path.join(format!("{}-{}.zip", name, label.replace(":", "-")));
            let unzipped_root = root_path.join(format!("{}-{}", name, label.replace(":", "-")));

            match label.as_str() {
                // "latest" and "integration" labels always point to the newest release.
                // We cannot assume that the binary is the same as last fetched. Therefore
                // we will always re-download and unzip when used.
                //
                // TODO(yuanzhi) When using fuchsia/third_party/android/aemu/release/...
                // we no longer add "integration" ref to any cipd instances. Keeping the "integration" check
                // for now for any backward compatibility we may have to support.
                "latest" | "integration" => {
                    if cipd_zip.exists() {
                        remove_file(&cipd_zip)?;
                    }
                    if unzipped_root.exists() {
                        remove_dir_all(&unzipped_root)?;
                    }
                }
                _ => {
                    if unzipped_root.exists() {
                        return Ok(unzipped_root);
                    }
                }
            };
            let status = cipd::download(url.clone(), &cipd_zip).await?;
            if status == StatusCode::OK {
                cipd::extract_zip(&cipd_zip, &unzipped_root, false /* debug */)?;
                Ok(unzipped_root)
            } else {
                Err(format_err!(
                    "Cannot download file from cipd path {}. Got status code {}",
                    url,
                    status.as_str(),
                ))
            }
        })
    }
/// Downloads & extract aemu.zip from CIPD, and returns the path containing the emulator executable.
///
/// # Arguments
///
/// * `label` - cipd label that specified a particular aemu version
/// * `cipd_pkg` - this is appended to cipd url https://chrome-infra-packages.appspot.com/dl/fuchsia/third_party/.
Downloads & extract aemu.zip from CIPD, and returns the path containing the emulator executable.
Downloads & extract aemu . zip from CIPD and returns the path containing the emulator executable .
pub fn download_and_extract(&self, label: String, cipd_pkg: String) -> Result<PathBuf> {
        let mut executor = LocalExecutor::new().unwrap();
        executor.run_singlethreaded(async move {
            let root_path = match read_env_path("FEMU_DOWNLOAD_DIR") {
                Ok(path) => path,
                _ => {
                    let default_path = get_sdk_data_dir()?.join("femu");
                    if !default_path.exists() {
                        create_dir_all(&default_path)?;
                    }
                    default_path
                }
            };
            let arch = match env::consts::OS {
                "macos" => "mac-amd64",
                _ => "linux-amd64",
            };
            let url = format!(
                "https://chrome-infra-packages.appspot.com/dl/fuchsia/{}/{}/+/{}",
                cipd_pkg, arch, label
            )
            .parse::<Uri>()?;
            let name = cipd_pkg
                .split('/')
                .last()
                .ok_or(anyhow!("Cannot identify filename from {}", cipd_pkg))?;
            let cipd_zip = root_path.join(format!("{}-{}.zip", name, label.replace(":", "-")));
            let unzipped_root = root_path.join(format!("{}-{}", name, label.replace(":", "-")));
            match label.as_str() {
                // "latest" and "integration" labels always point to the newest release.
                // We cannot assume that the binary is the same as last fetched. Therefore
                // we will always re-download and unzip when used.
                //
                // TODO(yuanzhi) When using fuchsia/third_party/android/aemu/release/...
                // we no longer add "integration" ref to any cipd instances. Keeping the "integration" check
                // for now for any backward compatibility we may have to support.
                "latest" | "integration" => {
                    if cipd_zip.exists() {
                        remove_file(&cipd_zip)?;
                    }
                    if unzipped_root.exists() {
                        remove_dir_all(&unzipped_root)?;
                    }
                }
                _ => {
                    if unzipped_root.exists() {
                        return Ok(unzipped_root);
                    }
                }
            };
            let status = cipd::download(url.clone(), &cipd_zip).await?;
            if status == StatusCode::OK {
                cipd::extract_zip(&cipd_zip, &unzipped_root, false /* debug */)?;
                Ok(unzipped_root)
            } else {
                Err(format_err!(
                    "Cannot download file from cipd path {}. Got status code {}",
                    url,
                    status.as_str(),
                ))
            }
        })
    }
pub fn download_and_extract ( & self , label : String , cipd_pkg : String ) -> Result < PathBuf > { let mut executor = LocalExecutor :: new ( ) . unwrap ( ) ; executor . run_singlethreaded ( async move { let root_path = match read_env_path ( " " ) { Ok ( path ) => path , _ => { let default_path = get_sdk_data_dir ( ) ? . join ( " " ) ; if ! default_path . exists ( ) { create_dir_all ( & default_path ) ? ; } default_path } } ; let arch = match env :: consts :: OS { " " => " " , _ => " " , } ; let url = format ! ( " " cipd_pkg arch label ) . parse :: < Uri > ( ) ? ; let name = cipd_pkg . split ( '/' ) . last ( ) . ok_or ( anyhow ! ( " " cipd_pkg ) ) ? ; let cipd_zip = root_path . join ( format ! ( " " name label replace ( " " " " ) ) ) ; let unzipped_root = root_path . join ( format ! ( " " name label replace ( " " " " ) ) ) ; match label . as_str ( ) { // "latest" and "integration" labels always point to the newest release. // We cannot assume that the binary is the same as last fetched. Therefore // we will always re-download and unzip when used. // // TODO(yuanzhi) When using fuchsia/third_party/android/aemu/release/... // we no longer add "integration" ref to any cipd instances. Keeping the "integration" check // for now for any backward compatibility we may have to support. " " | " " => { if cipd_zip . exists ( ) { remove_file ( & cipd_zip ) ? ; } if unzipped_root . exists ( ) { remove_dir_all ( & unzipped_root ) ? ; } } _ => { if unzipped_root . exists ( ) { return Ok ( unzipped_root ) ; } } } ; let status = cipd :: download ( url . clone ( ) , & cipd_zip ) . await ? ; if status == StatusCode :: OK { cipd :: extract_zip ( & cipd_zip , & unzipped_root , false /* debug */ ) ? ; Ok ( unzipped_root ) } else { Err ( format_err ! ( " " url status as_str ( ) ) ) } } ) }
Downloads & extract aemu.zip from CIPD, and returns the path containing the emulator executable.
Downloads & extract aemu . zip from CIPD and returns the path containing the emulator executable .
&self
label
String
cipd_pkg
String
&self
label
String
cipd_pkg
String