Add test case for corrupt partial download
@@ -25,6 +25,8 @@ use std::str::FromStr;
use std::sync::Arc;
use url::Url;
+const SHA256_HASH_LEN: usize = 64;
+
// Creates a mock dist server populated with some test data
pub fn create_mock_dist_server(
path: &Path,
@@ -1984,3 +1986,68 @@ fn checks_files_hashes_before_reuse() {
assert!(noticed_bad_checksum.get());
})
}
+
+#[test]
+fn handle_corrupt_partial_downloads() {
+ setup(None, false, &|url,
+ toolchain,
+ prefix,
+ download_cfg,
+ temp_cfg| {
+ // write a corrupt partial out
+ let path = url.to_file_path().unwrap();
+ let target_hash = utils::read_file(
+ "target hash",
+ &path.join("dist/2016-02-02/rustc-nightly-x86_64-apple-darwin.tar.gz.sha256"),
+ )
+ .unwrap()[..SHA256_HASH_LEN]
+ .to_owned();
+
+ utils::ensure_dir_exists(
+ "download dir",
+ &download_cfg.download_dir,
+ &|_: Notification<'_>| {},
+ )
+ .unwrap();
+ let partial_path = download_cfg
+ .download_dir
+ .join(format!("{}.partial", target_hash));
+ utils_raw::write_file(
+ &partial_path,
+ "file will be resumed from here and not match hash",
+ )
+ .unwrap();
+
+ let err = update_from_dist(
+ url,
+ toolchain,
+ prefix,
+ &[],
+ &[],
+ download_cfg,
+ temp_cfg,
+ false,
+ )
+ .unwrap_err();
+
+ match err.kind() {
+ ErrorKind::ComponentDownloadFailed(_) => (),
+ e => panic!("Unexpected error: {:?}", e),
+ }
+
+ update_from_dist(
+ url,
+ toolchain,
+ prefix,
+ &[],
+ &[],
+ &download_cfg,
+ temp_cfg,
+ false,
+ )
+ .unwrap();
+
+ assert!(utils::path_exists(&prefix.path().join("bin/rustc")));
+ assert!(utils::path_exists(&prefix.path().join("lib/libstd.rlib")));
+ });
+}
