Skip to content

Commit 4b06571

Browse files
committed
dist: clarify when update_hash is available
1 parent 591ed27 commit 4b06571

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

src/dist/manifestation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl Manifestation {
361361
pub(crate) async fn update_v1(
362362
&self,
363363
new_manifest: &[String],
364-
update_hash: Option<&Path>,
364+
update_hash: &Path,
365365
dl_cfg: &DownloadCfg<'_>,
366366
) -> Result<Option<String>> {
367367
// If there's already a v2 installation then something has gone wrong
@@ -387,7 +387,7 @@ impl Manifestation {
387387

388388
let status = dl_cfg.status_for("rust");
389389
let dl = dl_cfg
390-
.download_and_check(&url, update_hash, Some(&status), ".tar.gz")
390+
.download_and_check(&url, Some(update_hash), Some(&status), ".tar.gz")
391391
.await?;
392392
if dl.is_none() {
393393
return Ok(None);

src/dist/mod.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ pub(crate) struct DistOptions<'a> {
880880
pub(crate) cfg: &'a Cfg<'a>,
881881
pub(crate) toolchain: &'a ToolchainDesc,
882882
pub(crate) profile: Profile,
883-
pub(crate) update_hash: Option<&'a Path>,
883+
pub(crate) update_hash: &'a Path,
884884
pub(crate) dl_cfg: DownloadCfg<'a>,
885885
/// --force bool is whether to force an update/install
886886
pub(crate) force: bool,
@@ -907,15 +907,13 @@ pub(crate) async fn update_from_dist(
907907
opts: &DistOptions<'_>,
908908
) -> Result<Option<String>> {
909909
let fresh_install = !prefix.path().exists();
910-
if let Some(hash) = opts.update_hash {
911-
// fresh_install means the toolchain isn't present, but hash_exists means there is a stray hash file
912-
if fresh_install && Path::exists(hash) {
913-
warn!(
914-
"removing stray hash file in order to continue: {}",
915-
hash.display()
916-
);
917-
std::fs::remove_file(hash)?;
918-
}
910+
// fresh_install means the toolchain isn't present, but hash_exists means there is a stray hash file
911+
if fresh_install && Path::exists(opts.update_hash) {
912+
warn!(
913+
"removing stray hash file in order to continue: {}",
914+
opts.update_hash.display()
915+
);
916+
std::fs::remove_file(opts.update_hash)?;
919917
}
920918

921919
let mut fetched = String::new();
@@ -1068,7 +1066,7 @@ pub(crate) async fn update_from_dist(
10681066
#[allow(clippy::too_many_arguments)]
10691067
async fn try_update_from_dist_(
10701068
download: &DownloadCfg<'_>,
1071-
update_hash: Option<&Path>,
1069+
update_hash: &Path,
10721070
toolchain: &ToolchainDesc,
10731071
profile: Option<Profile>,
10741072
prefix: &InstallPrefix,
@@ -1090,7 +1088,7 @@ async fn try_update_from_dist_(
10901088
// So if components or targets is not empty, we skip passing `update_hash` so that
10911089
// we essentially degenerate to `rustup component add` / `rustup target add`
10921090
if components.is_empty() && targets.is_empty() {
1093-
update_hash
1091+
Some(update_hash)
10941092
} else {
10951093
None
10961094
},

src/install.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,7 @@ impl InstallMethod<'_> {
107107
let maybe_new_hash = dist::update_from_dist(prefix, opts).await?;
108108

109109
if let Some(hash) = maybe_new_hash {
110-
if let Some(hash_file) = opts.update_hash {
111-
utils::write_file("update hash", hash_file, &hash)?;
112-
}
113-
110+
utils::write_file("update hash", opts.update_hash, &hash)?;
114111
Ok(true)
115112
} else {
116113
Ok(false)

src/toolchain/distributable.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[cfg(windows)]
22
use std::fs;
3-
use std::{convert::Infallible, env::consts::EXE_SUFFIX, ffi::OsStr, path::Path, process::Command};
3+
use std::{convert::Infallible, env::consts::EXE_SUFFIX, ffi::OsStr, process::Command};
44

55
#[cfg(windows)]
66
use anyhow::Context;
@@ -346,13 +346,11 @@ impl<'a> DistributableToolchain<'a> {
346346
force: bool,
347347
) -> anyhow::Result<(UpdateStatus, DistributableToolchain<'a>)> {
348348
let hash_path = cfg.get_hash_file(toolchain, true)?;
349-
let update_hash = Some(&hash_path as &Path);
350-
351349
let status = InstallMethod::Dist(DistOptions {
352350
cfg,
353351
toolchain,
354352
profile,
355-
update_hash,
353+
update_hash: &hash_path,
356354
dl_cfg: DownloadCfg::new(cfg),
357355
force,
358356
allow_downgrade: false,
@@ -404,13 +402,11 @@ impl<'a> DistributableToolchain<'a> {
404402

405403
let cfg = self.toolchain.cfg;
406404
let hash_path = cfg.get_hash_file(&self.desc, true)?;
407-
let update_hash = Some(&hash_path as &Path);
408-
409405
InstallMethod::Dist(DistOptions {
410406
cfg,
411407
toolchain: &self.desc,
412408
profile,
413-
update_hash,
409+
update_hash: &hash_path,
414410
dl_cfg: DownloadCfg::new(cfg),
415411
force,
416412
allow_downgrade,

0 commit comments

Comments
 (0)