Skip to content

Commit 6f277b6

Browse files
committed
dist: store temp::Context in DownloadCfg
1 parent 4ae2012 commit 6f277b6

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

src/cli/rustup_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ async fn update(
10121012

10131013
info!("cleaning up downloads & tmp directories");
10141014
utils::delete_dir_contents_following_links(&cfg.download_dir);
1015-
cfg.tmp_cx.clean();
1015+
dl_cfg.tmp_cx.clean();
10161016
}
10171017

10181018
Ok(exit_code)

src/config.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
cli::{common, self_update::SelfUpdateMode},
1313
dist::{
1414
self, AutoInstallMode, DistOptions, PartialToolchainDesc, Profile, TargetTriple,
15-
ToolchainDesc, temp,
15+
ToolchainDesc,
1616
},
1717
errors::RustupError,
1818
fallback_settings::FallbackSettings,
@@ -239,9 +239,9 @@ pub(crate) struct Cfg<'a> {
239239
pub toolchains_dir: PathBuf,
240240
update_hash_dir: PathBuf,
241241
pub download_dir: PathBuf,
242-
pub tmp_cx: temp::Context,
243242
pub toolchain_override: Option<ResolvableToolchainName>,
244243
env_override: Option<LocalToolchainName>,
244+
pub(crate) dist_root_server: String,
245245
pub dist_root_url: String,
246246
pub quiet: bool,
247247
pub current_dir: PathBuf,
@@ -300,8 +300,7 @@ impl<'a> Cfg<'a> {
300300
};
301301

302302
let dist_root_server = dist_root_server(process)?;
303-
let tmp_cx = temp::Context::new(rustup_dir.join("tmp"), dist_root_server.as_str());
304-
let dist_root = dist_root_server + "/dist";
303+
let dist_root = dist_root_server.clone() + "/dist";
305304

306305
let cfg = Self {
307306
profile_override: None,
@@ -311,9 +310,9 @@ impl<'a> Cfg<'a> {
311310
toolchains_dir,
312311
update_hash_dir,
313312
download_dir,
314-
tmp_cx,
315313
toolchain_override: None,
316314
env_override,
315+
dist_root_server,
317316
dist_root_url: dist_root,
318317
quiet,
319318
current_dir,
@@ -954,9 +953,9 @@ impl Debug for Cfg<'_> {
954953
toolchains_dir,
955954
update_hash_dir,
956955
download_dir,
957-
tmp_cx,
958956
toolchain_override,
959957
env_override,
958+
dist_root_server,
960959
dist_root_url,
961960
quiet,
962961
current_dir,
@@ -971,9 +970,9 @@ impl Debug for Cfg<'_> {
971970
.field("toolchains_dir", toolchains_dir)
972971
.field("update_hash_dir", update_hash_dir)
973972
.field("download_dir", download_dir)
974-
.field("tmp_cx", tmp_cx)
975973
.field("toolchain_override", toolchain_override)
976974
.field("env_override", env_override)
975+
.field("dist_root_server", dist_root_server)
977976
.field("dist_root_url", dist_root_url)
978977
.field("quiet", quiet)
979978
.field("current_dir", current_dir)

src/dist/download.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fs;
33
use std::io::Read;
44
use std::ops;
55
use std::path::{Path, PathBuf};
6-
use std::sync::Mutex;
6+
use std::sync::{Arc, Mutex};
77
use std::time::{Duration, Instant};
88

99
use anyhow::{Context, Result, anyhow};
@@ -23,7 +23,7 @@ use crate::utils;
2323
const UPDATE_HASH_LEN: usize = 20;
2424

2525
pub struct DownloadCfg<'a> {
26-
pub tmp_cx: &'a temp::Context,
26+
pub tmp_cx: Arc<temp::Context>,
2727
pub download_dir: &'a PathBuf,
2828
pub(super) tracker: DownloadTracker,
2929
pub(super) permit_copy_rename: bool,
@@ -34,7 +34,10 @@ impl<'a> DownloadCfg<'a> {
3434
/// construct a download configuration
3535
pub(crate) fn new(cfg: &'a Cfg<'a>) -> Self {
3636
DownloadCfg {
37-
tmp_cx: &cfg.tmp_cx,
37+
tmp_cx: Arc::new(temp::Context::new(
38+
cfg.rustup_dir.join("tmp"),
39+
cfg.dist_root_server.as_str(),
40+
)),
3841
download_dir: &cfg.download_dir,
3942
tracker: DownloadTracker::new(!cfg.quiet, cfg.process),
4043
permit_copy_rename: cfg.process.permit_copy_rename(),

src/dist/manifestation.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ impl Manifestation {
110110
implicit_modify: bool,
111111
) -> Result<UpdateStatus> {
112112
// Some vars we're going to need a few times
113-
let tmp_cx = download_cfg.tmp_cx;
114113
let prefix = self.installation.prefix();
115114
let rel_installed_manifest_path = prefix.rel_manifest_file(DIST_MANIFEST);
116115
let installed_manifest_path = prefix.path().join(&rel_installed_manifest_path);
@@ -170,7 +169,11 @@ impl Manifestation {
170169
.unwrap_or(DEFAULT_MAX_RETRIES);
171170

172171
// Begin transaction
173-
let mut tx = Transaction::new(prefix.clone(), tmp_cx, download_cfg.permit_copy_rename);
172+
let mut tx = Transaction::new(
173+
prefix.clone(),
174+
&download_cfg.tmp_cx,
175+
download_cfg.permit_copy_rename,
176+
);
174177

175178
// If the previous installation was from a v1 manifest we need
176179
// to uninstall it first.
@@ -390,7 +393,7 @@ impl Manifestation {
390393
info!("installing component rust");
391394

392395
// Begin transaction
393-
let mut tx = Transaction::new(prefix, dl_cfg.tmp_cx, dl_cfg.permit_copy_rename);
396+
let mut tx = Transaction::new(prefix, &dl_cfg.tmp_cx, dl_cfg.permit_copy_rename);
394397

395398
// Uninstall components
396399
let components = self.installation.list()?;

src/dist/manifestation/tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ struct TestContext {
410410
prefix: InstallPrefix,
411411
download_dir: PathBuf,
412412
tp: TestProcess,
413-
tmp_cx: temp::Context,
413+
tmp_cx: Arc<temp::Context>,
414414
_tempdirs: Vec<tempfile::TempDir>,
415415
}
416416

@@ -450,10 +450,7 @@ impl TestContext {
450450
);
451451

452452
let prefix_tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
453-
454453
let work_tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
455-
let tmp_cx = temp::Context::new(work_tempdir.path().to_owned(), DEFAULT_DIST_SERVER);
456-
457454
let toolchain = ToolchainDesc::from_str("nightly-x86_64-apple-darwin").unwrap();
458455
let prefix = InstallPrefix::from(prefix_tempdir.path());
459456
let tp = TestProcess::new(env::current_dir().unwrap(), &["rustup"], env, "");
@@ -464,7 +461,10 @@ impl TestContext {
464461
download_dir: prefix.path().join("downloads"),
465462
prefix,
466463
tp,
467-
tmp_cx,
464+
tmp_cx: Arc::new(temp::Context::new(
465+
work_tempdir.path().to_owned(),
466+
DEFAULT_DIST_SERVER,
467+
)),
468468
_tempdirs: vec![prefix_tempdir, work_tempdir],
469469
}
470470
}
@@ -480,7 +480,7 @@ impl TestContext {
480480
force: bool,
481481
) -> Result<UpdateStatus> {
482482
let dl_cfg = DownloadCfg {
483-
tmp_cx: &self.tmp_cx,
483+
tmp_cx: self.tmp_cx.clone(),
484484
download_dir: &self.download_dir,
485485
tracker: DownloadTracker::new(false, &self.tp.process),
486486
permit_copy_rename: self.tp.process.permit_copy_rename(),

0 commit comments

Comments
 (0)