diff --git a/src/download/src/lib.rs b/src/download/src/lib.rs index 25a27ac2eb..01855f4277 100644 --- a/src/download/src/lib.rs +++ b/src/download/src/lib.rs @@ -76,7 +76,7 @@ pub fn download_to_path_with_backend( if let Some(cb) = callback { try!(cb(Event::ResumingPartialDownload)); - let mut buf = vec![0; 1024*1024*10]; + let mut buf = vec![0; 32768]; let mut downloaded_so_far = 0; loop { let n = try!(partial.read(&mut buf)); @@ -102,7 +102,7 @@ pub fn download_to_path_with_backend( .create(true) .open(&path) .chain_err(|| "error opening file for download")); - + try!(possible_partial.seek(SeekFrom::End(0))); (possible_partial, downloaded_so_far) diff --git a/src/rustup-dist/src/dist.rs b/src/rustup-dist/src/dist.rs index 48236bf582..31520f8017 100644 --- a/src/rustup-dist/src/dist.rs +++ b/src/rustup-dist/src/dist.rs @@ -502,6 +502,23 @@ impl ops::Deref for File { } } +fn file_hash(path: &Path) -> Result { + let mut hasher = Sha256::new(); + use std::io::Read; + let mut downloaded = try!(fs::File::open(&path).chain_err(|| "opening already downloaded file")); + let mut buf = vec![0; 32768]; + loop { + if let Ok(n) = downloaded.read(&mut buf) { + if n == 0 { break; } + hasher.input(&buf[..n]); + } else { + break; + } + } + + Ok(hasher.result_str()) +} + impl<'a> DownloadCfg<'a> { pub fn download(&self, url: &Url, hash: &str, notify_handler: &'a Fn(Notification)) -> Result { @@ -510,19 +527,7 @@ impl<'a> DownloadCfg<'a> { let target_file = self.download_dir.join(Path::new(hash)); if target_file.exists() { - let mut hasher = Sha256::new(); - use std::io::Read; - let mut downloaded = try!(fs::File::open(&target_file).chain_err(|| "opening already downloaded file")); - let mut buf = [0; 1024]; - loop { - if let Ok(n) = downloaded.read(&mut buf) { - if n == 0 { break; } - hasher.input(&buf[..n]); - } else { - break; - } - } - let cached_result = hasher.result_str(); + let cached_result = try!(file_hash(&target_file)); if hash == cached_result { notify_handler(Notification::FileAlreadyDownloaded); notify_handler(Notification::ChecksumValid(&url.to_string())); @@ -543,7 +548,7 @@ impl<'a> DownloadCfg<'a> { + ".partial"); let mut hasher = Sha256::new(); - + try!(utils::download_file_with_resume(&url, &partial_file_path, Some(&mut hasher),