Skip to content

Commit

Permalink
Merge pull request #573 from brson/fallback
Browse files Browse the repository at this point in the history
Fallback to old download methods if server returns 403
  • Loading branch information
alexcrichton authored Jul 12, 2016
2 parents ee7dab8 + a0a9e59 commit e6b867b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/rustup-dist/src/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ pub fn update_from_dist<'a>(download: DownloadCfg<'a>,
}
}
Ok(None) => return Ok(None),
Err(Error(ErrorKind::Utils(::rustup_utils::ErrorKind::Download404 { .. }), _)) => {
Err(Error(ErrorKind::Utils(::rustup_utils::ErrorKind::DownloadNotExists { .. }), _)) => {
// Proceed to try v1 as a fallback
(download.notify_handler)(Notification::DownloadingLegacyManifest);
}
Expand All @@ -528,7 +528,7 @@ pub fn update_from_dist<'a>(download: DownloadCfg<'a>,
// If the v2 manifest is not found then try v1
let manifest = match dl_v1_manifest(download, toolchain) {
Ok(m) => m,
Err(Error(ErrorKind::Utils(rustup_utils::ErrorKind::Download404 { .. }), _)) => {
Err(Error(ErrorKind::Utils(rustup_utils::ErrorKind::DownloadNotExists { .. }), _)) => {
return Err(format!("no release found for '{}'", toolchain.manifest_name()).into());
}
Err(e @ Error(ErrorKind::ChecksumFailed { .. }, _)) => {
Expand All @@ -547,7 +547,7 @@ pub fn update_from_dist<'a>(download: DownloadCfg<'a>,
download.notify_handler.clone()) {
Ok(None) => Ok(None),
Ok(Some(hash)) => Ok(Some(hash)),
e @ Err(Error(ErrorKind::Utils(rustup_utils::ErrorKind::Download404 { .. }), _)) => {
e @ Err(Error(ErrorKind::Utils(rustup_utils::ErrorKind::DownloadNotExists { .. }), _)) => {
e.chain_err(|| {
format!("could not download nonexistent rust version `{}`",
toolchain_str)
Expand Down
2 changes: 1 addition & 1 deletion src/rustup-utils/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ error_chain! {
description("could not download file")
display("could not download file from '{}' to '{}", url, path.display())
}
Download404 {
DownloadNotExists {
url: Url,
path: PathBuf,
} {
Expand Down
4 changes: 3 additions & 1 deletion src/rustup-utils/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,13 @@ pub fn download_file(url: &Url,
Err(e) => {
let is404 = match e.kind() {
&ErrorKind::Download(DEK::HttpStatus(404)) => true,
// 403 is what static.rlo returns for bogus URLs as of 2016/07/11
&ErrorKind::Download(DEK::HttpStatus(403)) => true,
&ErrorKind::Download(DEK::FileNotFound) => true,
_ => false
};
Err(e).chain_err(|| if is404 {
ErrorKind::Download404 {
ErrorKind::DownloadNotExists {
url: url.clone(),
path: path.to_path_buf(),
}
Expand Down

0 comments on commit e6b867b

Please sign in to comment.