Skip to content

Commit

Permalink
backtracking: Limit backtracking via env var
Browse files Browse the repository at this point in the history
Use RUSTUP_BACKTRACK_LIMIT (default 60) to limit the backtrack
attempts when trying to find a valid nightly to install.

Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
  • Loading branch information
kinnison committed Sep 18, 2019
1 parent 1b64788 commit 987359f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,10 @@ Command | Description
- `RUSTUP_UNPACK_RAM` *unstable* (default 400M, min 100M)
Caps the amount of RAM rustup will use for IO tasks while unpacking.

- `RUSTUP_BACKTRACK_LIMIT` *unstable* (default 60, min 1)
Caps the number of days that rustup will backtrack when looking for a nightly
which suits the user's installation.

- `RUSTUP_NO_BACKTRACE`
Disables backtraces on non-panic errors even when `RUST_BACKTRACE` is set.

Expand Down
16 changes: 16 additions & 0 deletions src/dist/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,11 @@ fn update_from_dist_<'a>(
let mut fetched = String::new();
let mut first_err = None;
let backtrack = toolchain.channel == "nightly" && toolchain.date.is_none();
let mut backtrack_attempts: i32 = env::var("RUSTUP_BACKTRACK_LIMIT")
.ok()
.unwrap_or_else(|| "60".to_string())
.parse()
.map_err(|e| format!("Bad number for RUSTUP_BACKTRACK_LIMIT: {}", e))?;
loop {
match try_update_from_dist_(
download,
Expand Down Expand Up @@ -640,6 +645,17 @@ fn update_from_dist_<'a>(
break Err(e);
}

backtrack_attempts -= 1;
if backtrack_attempts < 1 {
if let Some(e) = first_err {
break Err(e);
} else {
break Err(Error::from(ErrorKind::MissingReleaseForToolchain(
toolchain.channel,
)));
}
}

// The user asked to update their nightly, but the latest nightly does not have all
// the components that the user currently has installed. Let's try the previous
// nightlies in reverse chronological order until we find a nightly that does,
Expand Down

0 comments on commit 987359f

Please sign in to comment.