fn download_package(&mut self, pkg: &PackageId, url: &Url)
                        -> CargoResult<PathBuf> {
        // TODO: should discover filename from the S3 redirect
        let filename = format!("{}-{}.crate", pkg.name(), pkg.version());
        let dst = self.cache_path.join(&filename);
        if fs::metadata(&dst).is_ok() { return Ok(dst) }
        try!(self.config.shell().status("Downloading", pkg));

        try!(fs::create_dir_all(dst.parent().unwrap()));
        let expected_hash = try!(self.hash(pkg));
        let handle = match self.handle {
            Some(ref mut handle) => handle,
            None => {
                self.handle = Some(try!(ops::http_handle(self.config)));
                self.handle.as_mut().unwrap()
            }
        };
        // TODO: don't download into memory (curl-rust doesn't expose it)
        let resp = try!(handle.get(url.to_string()).follow_redirects(true).exec());
        if resp.get_code() != 200 && resp.get_code() != 0 {
            return Err(internal(format!("failed to get 200 response from {}\n{}",
                                        url, resp)))
        }

        // Verify what we just downloaded
        let actual = {
            let mut state = Sha256::new();
            state.update(resp.get_body());
            state.finish()
        };
        if actual.to_hex() != expected_hash {
            bail!("failed to verify the checksum of `{}`", pkg)
        }

        try!(paths::write(&dst, resp.get_body()));
        Ok(dst)
    }
/// Download the given package from the given url into the local cache.
///
/// This will perform the HTTP request to fetch the package. This function
/// will only succeed if the HTTP download was successful and the file is
/// then ready for inspection.
///
/// No action is taken if the package is already downloaded.
Download the given package from the given url into the local cache.
This will perform the HTTP request to fetch the package. This function
will only succeed if the HTTP download was successful and the file is
then ready for inspection.

No action is taken if the package is already downloaded.
Download the given package from the given url into the local cache . This will perform the HTTP request to fetch the package . This function will only succeed if the HTTP download was successful and the file is then ready for inspection . No action is taken if the package is already downloaded .
fn download_package(&mut self, pkg: &PackageId, url: &Url)
                        -> CargoResult<PathBuf> {
        // TODO: should discover filename from the S3 redirect
        let filename = format!("{}-{}.crate", pkg.name(), pkg.version());
        let dst = self.cache_path.join(&filename);
        if fs::metadata(&dst).is_ok() { return Ok(dst) }
        try!(self.config.shell().status("Downloading", pkg));
        try!(fs::create_dir_all(dst.parent().unwrap()));
        let expected_hash = try!(self.hash(pkg));
        let handle = match self.handle {
            Some(ref mut handle) => handle,
            None => {
                self.handle = Some(try!(ops::http_handle(self.config)));
                self.handle.as_mut().unwrap()
            }
        };
        // TODO: don't download into memory (curl-rust doesn't expose it)
        let resp = try!(handle.get(url.to_string()).follow_redirects(true).exec());
        if resp.get_code() != 200 && resp.get_code() != 0 {
            return Err(internal(format!("failed to get 200 response from {}\n{}",
                                        url, resp)))
        }
        // Verify what we just downloaded
        let actual = {
            let mut state = Sha256::new();
            state.update(resp.get_body());
            state.finish()
        };
        if actual.to_hex() != expected_hash {
            bail!("failed to verify the checksum of `{}`", pkg)
        }
        try!(paths::write(&dst, resp.get_body()));
        Ok(dst)
    }
fn download_package ( & mut self , pkg : & PackageId , url : & Url ) -> CargoResult < PathBuf > { // TODO: should discover filename from the S3 redirect let filename = format ! ( " " pkg name ( ) pkg version ( ) ) ; let dst = self . cache_path . join ( & filename ) ; if fs :: metadata ( & dst ) . is_ok ( ) { return Ok ( dst ) } try ! ( self config shell ( ) status ( " " pkg ) ) ; try ! ( fs create_dir_all ( dst parent ( ) unwrap ( ) ) ) ; let expected_hash = try ! ( self hash ( pkg ) ) ; let handle = match self . handle { Some ( ref mut handle ) => handle , None => { self . handle = Some ( try ! ( ops http_handle ( self config ) ) ) ; self . handle . as_mut ( ) . unwrap ( ) } } ; // TODO: don't download into memory (curl-rust doesn't expose it) let resp = try ! ( handle get ( url to_string ( ) ) follow_redirects ( true ) exec ( ) ) ; if resp . get_code ( ) != 200 && resp . get_code ( ) != 0 { return Err ( internal ( format ! ( " \n " url resp ) ) ) } // Verify what we just downloaded let actual = { let mut state = Sha256 :: new ( ) ; state . update ( resp . get_body ( ) ) ; state . finish ( ) } ; if actual . to_hex ( ) != expected_hash { bail ! ( " " pkg ) } try ! ( paths write ( dst resp get_body ( ) ) ) ; Ok ( dst ) }
Download the given package from the given url into the local cache.
Download the given package from the given url into the local cache .
&mut self
pkg
&PackageId
url
&Url
&mut self
pkg
&PackageId
url
&Url