From 1754da30a71c3a3efe6e3283948a729041344f81 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 9 Apr 2024 10:54:38 +0200 Subject: [PATCH] Rename temp::Cfg to Context --- src/cli/rustup_mode.rs | 2 +- src/config.rs | 10 +- src/dist/component/package.rs | 16 +-- src/dist/component/tests.rs | 100 ++++++------- src/dist/component/transaction.rs | 28 ++-- src/dist/dist.rs | 2 +- src/dist/download.rs | 6 +- src/dist/manifestation.rs | 28 ++-- src/dist/manifestation/tests.rs | 226 ++++++++++++++---------------- src/dist/temp.rs | 12 +- tests/suite/dist_install.rs | 22 +-- 11 files changed, 221 insertions(+), 231 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index ad81610a91..1e36e02534 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -1008,7 +1008,7 @@ fn update(cfg: &mut Cfg, m: &ArgMatches) -> Result { common::update_all_channels(cfg, self_update, m.get_flag("force"))?; info!("cleaning up downloads & tmp directories"); utils::delete_dir_contents_following_links(&cfg.download_dir); - cfg.temp_cfg.clean(); + cfg.tmp_cx.clean(); } if !self_update::NEVER_SELF_UPDATE && self_update_mode == SelfUpdateMode::CheckOnly { diff --git a/src/config.rs b/src/config.rs index 0ddaa0d1c1..7f01c08ab2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -179,7 +179,7 @@ pub(crate) struct Cfg { pub toolchains_dir: PathBuf, pub update_hash_dir: PathBuf, pub download_dir: PathBuf, - pub temp_cfg: temp::Cfg, + pub tmp_cx: temp::Context, pub toolchain_override: Option, pub env_override: Option, pub dist_root_url: String, @@ -241,7 +241,7 @@ impl Cfg { }; let notify_clone = notify_handler.clone(); - let temp_cfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( rustup_dir.join("tmp"), dist_root_server.as_str(), Box::new(move |n| (notify_clone)(n.into())), @@ -256,7 +256,7 @@ impl Cfg { toolchains_dir, update_hash_dir, download_dir, - temp_cfg, + tmp_cx, notify_handler, toolchain_override: None, env_override, @@ -281,7 +281,7 @@ impl Cfg { ) -> DownloadCfg<'a> { DownloadCfg { dist_root: &self.dist_root_url, - temp_cfg: &self.temp_cfg, + tmp_cx: &self.tmp_cx, download_dir: &self.download_dir, notify_handler, } @@ -961,7 +961,7 @@ impl Debug for Cfg { .field("toolchains_dir", &self.toolchains_dir) .field("update_hash_dir", &self.update_hash_dir) .field("download_dir", &self.download_dir) - .field("temp_cfg", &self.temp_cfg) + .field("tmp_cx", &self.tmp_cx) .field("toolchain_override", &self.toolchain_override) .field("env_override", &self.env_override) .field("dist_root_url", &self.dist_root_url) diff --git a/src/dist/component/package.rs b/src/dist/component/package.rs index 91453e8149..6c146d0e70 100644 --- a/src/dist/component/package.rs +++ b/src/dist/component/package.rs @@ -143,10 +143,10 @@ pub(crate) struct TarPackage<'a>(DirectoryPackage, temp::Dir<'a>); impl<'a> TarPackage<'a> { pub(crate) fn new( stream: R, - temp_cfg: &'a temp::Cfg, + tmp_cx: &'a temp::Context, notify_handler: Option<&'a dyn Fn(Notification<'_>)>, ) -> Result { - let temp_dir = temp_cfg.new_directory()?; + let temp_dir = tmp_cx.new_directory()?; let mut archive = tar::Archive::new(stream); // The rust-installer packages unpack to a directory called // $pkgname-$version-$target. Skip that directory when @@ -555,13 +555,13 @@ pub(crate) struct TarGzPackage<'a>(TarPackage<'a>); impl<'a> TarGzPackage<'a> { pub(crate) fn new( stream: R, - temp_cfg: &'a temp::Cfg, + tmp_cx: &'a temp::Context, notify_handler: Option<&'a dyn Fn(Notification<'_>)>, ) -> Result { let stream = flate2::read::GzDecoder::new(stream); Ok(TarGzPackage(TarPackage::new( stream, - temp_cfg, + tmp_cx, notify_handler, )?)) } @@ -591,13 +591,13 @@ pub(crate) struct TarXzPackage<'a>(TarPackage<'a>); impl<'a> TarXzPackage<'a> { pub(crate) fn new( stream: R, - temp_cfg: &'a temp::Cfg, + tmp_cx: &'a temp::Context, notify_handler: Option<&'a dyn Fn(Notification<'_>)>, ) -> Result { let stream = xz2::read::XzDecoder::new(stream); Ok(TarXzPackage(TarPackage::new( stream, - temp_cfg, + tmp_cx, notify_handler, )?)) } @@ -627,13 +627,13 @@ pub(crate) struct TarZStdPackage<'a>(TarPackage<'a>); impl<'a> TarZStdPackage<'a> { pub(crate) fn new( stream: R, - temp_cfg: &'a temp::Cfg, + tmp_cx: &'a temp::Context, notify_handler: Option<&'a dyn Fn(Notification<'_>)>, ) -> Result { let stream = zstd::stream::read::Decoder::new(stream)?; Ok(TarZStdPackage(TarPackage::new( stream, - temp_cfg, + tmp_cx, notify_handler, )?)) } diff --git a/src/dist/component/tests.rs b/src/dist/component/tests.rs index 1c3bf6e5fa..9f755454a5 100644 --- a/src/dist/component/tests.rs +++ b/src/dist/component/tests.rs @@ -20,14 +20,14 @@ fn add_file() { let prefix = InstallPrefix::from(prefixdir.path()); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), ); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); let mut file = tx.add_file("c", PathBuf::from("foo/bar")).unwrap(); write!(file, "test").unwrap(); @@ -48,14 +48,14 @@ fn add_file_then_rollback() { let prefix = InstallPrefix::from(prefixdir.path()); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), ); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); tx.add_file("c", PathBuf::from("foo/bar")).unwrap(); drop(tx); @@ -68,7 +68,7 @@ fn add_file_that_exists() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -77,7 +77,7 @@ fn add_file_that_exists() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix, &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix, &tmp_cx, ¬ify); fs::create_dir_all(prefixdir.path().join("foo")).unwrap(); utils::write_file("", &prefixdir.path().join("foo/bar"), "").unwrap(); @@ -99,7 +99,7 @@ fn copy_file() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -108,7 +108,7 @@ fn copy_file() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); let srcpath = srcdir.path().join("bar"); utils::write_file("", &srcpath, "").unwrap(); @@ -126,7 +126,7 @@ fn copy_file_then_rollback() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -135,7 +135,7 @@ fn copy_file_then_rollback() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); let srcpath = srcdir.path().join("bar"); utils::write_file("", &srcpath, "").unwrap(); @@ -153,7 +153,7 @@ fn copy_file_that_exists() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -162,7 +162,7 @@ fn copy_file_that_exists() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix, &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix, &tmp_cx, ¬ify); let srcpath = srcdir.path().join("bar"); utils::write_file("", &srcpath, "").unwrap(); @@ -189,7 +189,7 @@ fn copy_dir() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -198,7 +198,7 @@ fn copy_dir() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); let srcpath1 = srcdir.path().join("foo"); let srcpath2 = srcdir.path().join("bar/baz"); @@ -223,7 +223,7 @@ fn copy_dir_then_rollback() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -232,7 +232,7 @@ fn copy_dir_then_rollback() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); let srcpath1 = srcdir.path().join("foo"); let srcpath2 = srcdir.path().join("bar/baz"); @@ -257,7 +257,7 @@ fn copy_dir_that_exists() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -266,7 +266,7 @@ fn copy_dir_that_exists() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); fs::create_dir_all(prefix.path().join("a")).unwrap(); @@ -288,7 +288,7 @@ fn remove_file() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -297,7 +297,7 @@ fn remove_file() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix, &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix, &tmp_cx, ¬ify); let filepath = prefixdir.path().join("foo"); utils::write_file("", &filepath, "").unwrap(); @@ -313,7 +313,7 @@ fn remove_file_then_rollback() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -322,7 +322,7 @@ fn remove_file_then_rollback() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix, &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix, &tmp_cx, ¬ify); let filepath = prefixdir.path().join("foo"); utils::write_file("", &filepath, "").unwrap(); @@ -338,7 +338,7 @@ fn remove_file_that_not_exists() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -347,7 +347,7 @@ fn remove_file_that_not_exists() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix, &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix, &tmp_cx, ¬ify); let err = tx.remove_file("c", PathBuf::from("foo")).unwrap_err(); @@ -365,7 +365,7 @@ fn remove_dir() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -374,7 +374,7 @@ fn remove_dir() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix, &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix, &tmp_cx, ¬ify); let filepath = prefixdir.path().join("foo/bar"); fs::create_dir_all(filepath.parent().unwrap()).unwrap(); @@ -391,7 +391,7 @@ fn remove_dir_then_rollback() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -400,7 +400,7 @@ fn remove_dir_then_rollback() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix, &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix, &tmp_cx, ¬ify); let filepath = prefixdir.path().join("foo/bar"); fs::create_dir_all(filepath.parent().unwrap()).unwrap(); @@ -417,7 +417,7 @@ fn remove_dir_that_not_exists() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -426,7 +426,7 @@ fn remove_dir_that_not_exists() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix, &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix, &tmp_cx, ¬ify); let err = tx.remove_dir("c", PathBuf::from("foo")).unwrap_err(); @@ -444,7 +444,7 @@ fn write_file() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -453,7 +453,7 @@ fn write_file() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); let content = "hi".to_string(); tx.write_file("c", PathBuf::from("foo/bar"), content.clone()) @@ -471,7 +471,7 @@ fn write_file_then_rollback() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -480,7 +480,7 @@ fn write_file_then_rollback() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); let content = "hi".to_string(); tx.write_file("c", PathBuf::from("foo/bar"), content) @@ -495,7 +495,7 @@ fn write_file_that_exists() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -504,7 +504,7 @@ fn write_file_that_exists() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); let content = "hi".to_string(); utils_raw::write_file(&prefix.path().join("a"), &content).unwrap(); @@ -526,7 +526,7 @@ fn modify_file_that_not_exists() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -535,7 +535,7 @@ fn modify_file_that_not_exists() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); tx.modify_file(PathBuf::from("foo/bar")).unwrap(); tx.commit(); @@ -550,7 +550,7 @@ fn modify_file_that_exists() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -559,7 +559,7 @@ fn modify_file_that_exists() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); let path = prefix.path().join("foo"); utils_raw::write_file(&path, "wow").unwrap(); @@ -574,7 +574,7 @@ fn modify_file_that_not_exists_then_rollback() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -583,7 +583,7 @@ fn modify_file_that_not_exists_then_rollback() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); tx.modify_file(PathBuf::from("foo/bar")).unwrap(); drop(tx); @@ -596,7 +596,7 @@ fn modify_file_that_exists_then_rollback() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -605,7 +605,7 @@ fn modify_file_that_exists_then_rollback() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); let path = prefix.path().join("foo"); utils_raw::write_file(&path, "wow").unwrap(); @@ -623,7 +623,7 @@ fn modify_twice_then_rollback() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -632,7 +632,7 @@ fn modify_twice_then_rollback() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); let path = prefix.path().join("foo"); utils_raw::write_file(&path, "wow").unwrap(); @@ -650,7 +650,7 @@ fn do_multiple_op_transaction(rollback: bool) { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -659,7 +659,7 @@ fn do_multiple_op_transaction(rollback: bool) { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); // copy_file let relpath1 = PathBuf::from("bin/rustc"); @@ -751,7 +751,7 @@ fn rollback_failure_keeps_going() { let prefixdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let txdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( txdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -760,7 +760,7 @@ fn rollback_failure_keeps_going() { let prefix = InstallPrefix::from(prefixdir.path()); let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); write!(tx.add_file("", PathBuf::from("foo")).unwrap(), "").unwrap(); write!(tx.add_file("", PathBuf::from("bar")).unwrap(), "").unwrap(); diff --git a/src/dist/component/transaction.rs b/src/dist/component/transaction.rs index 2eaf969406..7243f6087f 100644 --- a/src/dist/component/transaction.rs +++ b/src/dist/component/transaction.rs @@ -36,7 +36,7 @@ use crate::utils::utils; pub struct Transaction<'a> { prefix: InstallPrefix, changes: Vec>, - temp_cfg: &'a temp::Cfg, + tmp_cx: &'a temp::Context, notify_handler: &'a dyn Fn(Notification<'_>), committed: bool, } @@ -44,13 +44,13 @@ pub struct Transaction<'a> { impl<'a> Transaction<'a> { pub fn new( prefix: InstallPrefix, - temp_cfg: &'a temp::Cfg, + tmp_cx: &'a temp::Context, notify_handler: &'a dyn Fn(Notification<'_>), ) -> Self { Transaction { prefix, changes: Vec::new(), - temp_cfg, + tmp_cx, notify_handler, committed: false, } @@ -99,7 +99,7 @@ impl<'a> Transaction<'a> { &self.prefix, component, relpath, - self.temp_cfg, + self.tmp_cx, self.notify_handler(), )?; self.change(item); @@ -114,7 +114,7 @@ impl<'a> Transaction<'a> { &self.prefix, component, relpath, - self.temp_cfg, + self.tmp_cx, self.notify_handler(), )?; self.change(item); @@ -142,7 +142,7 @@ impl<'a> Transaction<'a> { /// This is used for arbitrarily manipulating a file. pub fn modify_file(&mut self, relpath: PathBuf) -> Result<()> { assert!(relpath.is_relative()); - let item = ChangedItem::modify_file(&self.prefix, relpath, self.temp_cfg)?; + let item = ChangedItem::modify_file(&self.prefix, relpath, self.tmp_cx)?; self.change(item); Ok(()) } @@ -170,8 +170,8 @@ impl<'a> Transaction<'a> { Ok(()) } - pub(crate) fn temp(&self) -> &'a temp::Cfg { - self.temp_cfg + pub(crate) fn temp(&self) -> &'a temp::Context { + self.tmp_cx } pub(crate) fn notify_handler(&self) -> &'a dyn Fn(Notification<'_>) { self.notify_handler @@ -280,11 +280,11 @@ impl<'a> ChangedItem<'a> { prefix: &InstallPrefix, component: &str, relpath: PathBuf, - temp_cfg: &'a temp::Cfg, + tmp_cx: &'a temp::Context, notify: &'a dyn Fn(Notification<'_>), ) -> Result { let abs_path = prefix.abs_path(&relpath); - let backup = temp_cfg.new_file()?; + let backup = tmp_cx.new_file()?; if !utils::path_exists(&abs_path) { Err(RustupError::ComponentMissingFile { name: component.to_owned(), @@ -300,11 +300,11 @@ impl<'a> ChangedItem<'a> { prefix: &InstallPrefix, component: &str, relpath: PathBuf, - temp_cfg: &'a temp::Cfg, + tmp_cx: &'a temp::Context, notify: &'a dyn Fn(Notification<'_>), ) -> Result { let abs_path = prefix.abs_path(&relpath); - let backup = temp_cfg.new_directory()?; + let backup = tmp_cx.new_directory()?; if !utils::path_exists(&abs_path) { Err(RustupError::ComponentMissingDir { name: component.to_owned(), @@ -319,12 +319,12 @@ impl<'a> ChangedItem<'a> { fn modify_file( prefix: &InstallPrefix, relpath: PathBuf, - temp_cfg: &'a temp::Cfg, + tmp_cx: &'a temp::Context, ) -> Result { let abs_path = prefix.abs_path(&relpath); if utils::is_file(&abs_path) { - let backup = temp_cfg.new_file()?; + let backup = tmp_cx.new_file()?; utils::copy_file(&abs_path, &backup)?; Ok(ChangedItem::ModifiedFile(relpath, Some(backup))) } else { diff --git a/src/dist/dist.rs b/src/dist/dist.rs index 5404fb58ff..bd568fd499 100644 --- a/src/dist/dist.rs +++ b/src/dist/dist.rs @@ -1068,7 +1068,7 @@ fn try_update_from_dist_( let result = manifestation.update_v1( &manifest, update_hash, - download.temp_cfg, + download.tmp_cx, &download.notify_handler, ); // inspect, determine what context to add, then process afterwards. diff --git a/src/dist/download.rs b/src/dist/download.rs index 9cf4006a0e..8980d180df 100644 --- a/src/dist/download.rs +++ b/src/dist/download.rs @@ -16,7 +16,7 @@ const UPDATE_HASH_LEN: usize = 20; #[derive(Copy, Clone)] pub struct DownloadCfg<'a> { pub dist_root: &'a str, - pub temp_cfg: &'a temp::Cfg, + pub tmp_cx: &'a temp::Context, pub download_dir: &'a PathBuf, pub notify_handler: &'a dyn Fn(Notification<'_>), } @@ -126,7 +126,7 @@ impl<'a> DownloadCfg<'a> { fn download_hash(&self, url: &str) -> Result { let hash_url = utils::parse_url(&(url.to_owned() + ".sha256"))?; - let hash_file = self.temp_cfg.new_file()?; + let hash_file = self.tmp_cx.new_file()?; utils::download_file(&hash_url, &hash_file, None, &|n| { (self.notify_handler)(n.into()) @@ -165,7 +165,7 @@ impl<'a> DownloadCfg<'a> { } let url = utils::parse_url(url_str)?; - let file = self.temp_cfg.new_file_with_ext("", ext)?; + let file = self.tmp_cx.new_file_with_ext("", ext)?; let mut hasher = Sha256::new(); utils::download_file(&url, &file, Some(&mut hasher), &|n| { diff --git a/src/dist/manifestation.rs b/src/dist/manifestation.rs index af0def6b04..65c05be8f2 100644 --- a/src/dist/manifestation.rs +++ b/src/dist/manifestation.rs @@ -110,7 +110,7 @@ impl Manifestation { implicit_modify: bool, ) -> Result { // Some vars we're going to need a few times - let temp_cfg = download_cfg.temp_cfg; + let tmp_cx = download_cfg.tmp_cx; let prefix = self.installation.prefix(); let rel_installed_manifest_path = prefix.rel_manifest_file(DIST_MANIFEST); let installed_manifest_path = prefix.path().join(&rel_installed_manifest_path); @@ -146,7 +146,7 @@ impl Manifestation { } } - let altered = temp_cfg.dist_server != DEFAULT_DIST_SERVER; + let altered = tmp_cx.dist_server != DEFAULT_DIST_SERVER; // Download component packages and validate hashes let mut things_to_install: Vec<(Component, CompressionKind, File)> = Vec::new(); @@ -167,7 +167,7 @@ impl Manifestation { component.target.as_ref(), )); let url = if altered { - url.replace(DEFAULT_DIST_SERVER, temp_cfg.dist_server.as_str()) + url.replace(DEFAULT_DIST_SERVER, tmp_cx.dist_server.as_str()) } else { url }; @@ -202,7 +202,7 @@ impl Manifestation { } // Begin transaction - let mut tx = Transaction::new(prefix.clone(), temp_cfg, download_cfg.notify_handler); + let mut tx = Transaction::new(prefix.clone(), tmp_cx, download_cfg.notify_handler); // If the previous installation was from a v1 manifest we need // to uninstall it first. @@ -255,15 +255,15 @@ impl Manifestation { utils::FileReaderWithProgress::new_file(&installer_file, ¬ification_converter)?; let package: &dyn Package = match format { CompressionKind::GZip => { - gz = TarGzPackage::new(reader, temp_cfg, Some(¬ification_converter))?; + gz = TarGzPackage::new(reader, tmp_cx, Some(¬ification_converter))?; &gz } CompressionKind::XZ => { - xz = TarXzPackage::new(reader, temp_cfg, Some(¬ification_converter))?; + xz = TarXzPackage::new(reader, tmp_cx, Some(¬ification_converter))?; &xz } CompressionKind::ZStd => { - zst = TarZStdPackage::new(reader, temp_cfg, Some(¬ification_converter))?; + zst = TarZStdPackage::new(reader, tmp_cx, Some(¬ification_converter))?; &zst } }; @@ -307,12 +307,12 @@ impl Manifestation { pub fn uninstall( &self, manifest: &Manifest, - temp_cfg: &temp::Cfg, + tmp_cx: &temp::Context, notify_handler: &dyn Fn(Notification<'_>), ) -> Result<()> { let prefix = self.installation.prefix(); - let mut tx = Transaction::new(prefix.clone(), temp_cfg, notify_handler); + let mut tx = Transaction::new(prefix.clone(), tmp_cx, notify_handler); // Read configuration and delete it let rel_config_path = prefix.rel_manifest_file(CONFIG_FILE); @@ -385,7 +385,7 @@ impl Manifestation { &self, new_manifest: &[String], update_hash: Option<&Path>, - temp_cfg: &temp::Cfg, + tmp_cx: &temp::Context, notify_handler: &dyn Fn(Notification<'_>), ) -> Result> { // If there's already a v2 installation then something has gone wrong @@ -407,7 +407,7 @@ impl Manifestation { // Only replace once. The cost is inexpensive. let url = url .unwrap() - .replace(DEFAULT_DIST_SERVER, temp_cfg.dist_server.as_str()); + .replace(DEFAULT_DIST_SERVER, tmp_cx.dist_server.as_str()); notify_handler(Notification::DownloadingComponent( "rust", @@ -420,7 +420,7 @@ impl Manifestation { let dlcfg = DownloadCfg { dist_root: "bogus", download_dir: &dld_dir, - temp_cfg, + tmp_cx, notify_handler, }; @@ -439,7 +439,7 @@ impl Manifestation { )); // Begin transaction - let mut tx = Transaction::new(prefix, temp_cfg, notify_handler); + let mut tx = Transaction::new(prefix, tmp_cx, notify_handler); // Uninstall components let components = self.installation.list()?; @@ -454,7 +454,7 @@ impl Manifestation { let reader = utils::FileReaderWithProgress::new_file(&installer_file, ¬ification_converter)?; let package: &dyn Package = - &TarGzPackage::new(reader, temp_cfg, Some(¬ification_converter))?; + &TarGzPackage::new(reader, tmp_cx, Some(¬ification_converter))?; for component in package.components() { tx = package.install(&self.installation, &component, None, tx)?; diff --git a/src/dist/manifestation/tests.rs b/src/dist/manifestation/tests.rs index b50c19ef19..54cd010ea3 100644 --- a/src/dist/manifestation/tests.rs +++ b/src/dist/manifestation/tests.rs @@ -315,7 +315,7 @@ fn rename_component() { mock_dist_server, &url, GZOnly, - &|url, toolchain, prefix, download_cfg, temp_cfg| { + &|url, toolchain, prefix, download_cfg, tmp_cx| { let adds = [Component::new( "bonus".to_string(), Some(TargetTriple::new("x86_64-apple-darwin")), @@ -330,7 +330,7 @@ fn rename_component() { &adds, &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -344,7 +344,7 @@ fn rename_component() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -380,7 +380,7 @@ fn rename_component_new() { mock_dist_server, &url, GZOnly, - &|url, toolchain, prefix, download_cfg, temp_cfg| { + &|url, toolchain, prefix, download_cfg, tmp_cx| { let adds = [Component::new( "bobo".to_string(), Some(TargetTriple::new("x86_64-apple-darwin")), @@ -395,7 +395,7 @@ fn rename_component_new() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -412,7 +412,7 @@ fn rename_component_new() { &adds, &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -437,12 +437,12 @@ fn update_from_dist( add: &[Component], remove: &[Component], download_cfg: &DownloadCfg<'_>, - temp_cfg: &temp::Cfg, + tmp_cx: &temp::Context, force: bool, ) -> Result { // Download the dist manifest and place it into the installation prefix let manifest_url = make_manifest_url(dist_server, toolchain)?; - let manifest_file = temp_cfg.new_file()?; + let manifest_file = tmp_cx.new_file()?; utils::download_file(&manifest_url, &manifest_file, None, &|_| {})?; let manifest_str = utils::read_file("manifest", &manifest_file)?; let manifest = Manifest::parse(&manifest_str)?; @@ -483,14 +483,14 @@ fn make_manifest_url(dist_server: &Url, toolchain: &ToolchainDesc) -> Result), ) -> Result<()> { let trip = toolchain.target.clone(); let manifestation = Manifestation::open(prefix.clone(), trip)?; let manifest = manifestation.load_manifest()?.unwrap(); - manifestation.uninstall(&manifest, temp_cfg, notify_handler)?; + manifestation.uninstall(&manifest, tmp_cx, notify_handler)?; Ok(()) } @@ -516,7 +516,7 @@ impl Compressions { fn setup( edit: Option<&dyn Fn(&str, &mut MockChannel)>, comps: Compressions, - f: &dyn Fn(&Url, &ToolchainDesc, &InstallPrefix, &DownloadCfg<'_>, &temp::Cfg), + f: &dyn Fn(&Url, &ToolchainDesc, &InstallPrefix, &DownloadCfg<'_>, &temp::Context), ) { let dist_tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let mock_dist_server = create_mock_dist_server(dist_tempdir.path(), edit); @@ -528,7 +528,7 @@ fn setup_from_dist_server( server: MockDistServer, url: &Url, comps: Compressions, - f: &dyn Fn(&Url, &ToolchainDesc, &InstallPrefix, &DownloadCfg<'_>, &temp::Cfg), + f: &dyn Fn(&Url, &ToolchainDesc, &InstallPrefix, &DownloadCfg<'_>, &temp::Context), ) { server.write( &[ManifestVersion::V2], @@ -539,7 +539,7 @@ fn setup_from_dist_server( let prefix_tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); let work_tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let temp_cfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( work_tempdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), @@ -549,7 +549,7 @@ fn setup_from_dist_server( let prefix = InstallPrefix::from(prefix_tempdir.path()); let download_cfg = DownloadCfg { dist_root: "phony", - temp_cfg: &temp_cfg, + tmp_cx: &tmp_cx, download_dir: &prefix.path().to_owned().join("downloads"), notify_handler: &|event| { println!("{event}"); @@ -564,7 +564,7 @@ fn setup_from_dist_server( "", ) .into(), - || f(url, &toolchain, &prefix, &download_cfg, &temp_cfg), + || f(url, &toolchain, &prefix, &download_cfg, &tmp_cx), ); } @@ -573,7 +573,7 @@ fn initial_install(comps: Compressions) { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { update_from_dist( url, toolchain, @@ -581,7 +581,7 @@ fn initial_install(comps: Compressions) { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -612,7 +612,7 @@ fn test_uninstall() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { update_from_dist( url, toolchain, @@ -620,11 +620,11 @@ fn test_uninstall() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); - uninstall(toolchain, prefix, temp_cfg, &|_| ()).unwrap(); + uninstall(toolchain, prefix, tmp_cx, &|_| ()).unwrap(); assert!(!utils::path_exists(prefix.path().join("bin/rustc"))); assert!(!utils::path_exists(prefix.path().join("lib/libstd.rlib"))); @@ -637,7 +637,7 @@ fn uninstall_removes_config_file() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { update_from_dist( url, toolchain, @@ -645,14 +645,14 @@ fn uninstall_removes_config_file() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); assert!(utils::path_exists( prefix.manifest_file("multirust-config.toml") )); - uninstall(toolchain, prefix, temp_cfg, &|_| ()).unwrap(); + uninstall(toolchain, prefix, tmp_cx, &|_| ()).unwrap(); assert!(!utils::path_exists( prefix.manifest_file("multirust-config.toml") )); @@ -665,7 +665,7 @@ fn upgrade() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { change_channel_date(url, "nightly", "2016-02-01"); update_from_dist( url, @@ -674,7 +674,7 @@ fn upgrade() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -690,7 +690,7 @@ fn upgrade() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -736,7 +736,7 @@ fn unavailable_component() { setup( Some(edit), GZOnly, - &|url, toolchain, prefix, download_cfg, temp_cfg| { + &|url, toolchain, prefix, download_cfg, tmp_cx| { let adds = [Component::new( "bonus".to_string(), Some(TargetTriple::new("x86_64-apple-darwin")), @@ -752,7 +752,7 @@ fn unavailable_component() { &adds, &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -767,7 +767,7 @@ fn unavailable_component() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap_err(); @@ -812,7 +812,7 @@ fn unavailable_component_from_profile() { setup( Some(edit), GZOnly, - &|url, toolchain, prefix, download_cfg, temp_cfg| { + &|url, toolchain, prefix, download_cfg, tmp_cx| { change_channel_date(url, "nightly", "2016-02-01"); // Update with rustc. update_from_dist( @@ -822,7 +822,7 @@ fn unavailable_component_from_profile() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -837,7 +837,7 @@ fn unavailable_component_from_profile() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap_err(); @@ -857,17 +857,7 @@ fn unavailable_component_from_profile() { _ => panic!(), } - update_from_dist( - url, - toolchain, - prefix, - &[], - &[], - download_cfg, - temp_cfg, - true, - ) - .unwrap(); + update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, tmp_cx, true).unwrap(); }, ); } @@ -895,7 +885,7 @@ fn removed_component() { setup( Some(edit), GZOnly, - &|url, toolchain, prefix, download_cfg, temp_cfg| { + &|url, toolchain, prefix, download_cfg, tmp_cx| { let adds = [Component::new( "bonus".to_string(), Some(TargetTriple::new("x86_64-apple-darwin")), @@ -911,7 +901,7 @@ fn removed_component() { &adds, &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -926,7 +916,7 @@ fn removed_component() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap_err(); @@ -970,7 +960,7 @@ fn unavailable_components_is_target() { setup( Some(edit), GZOnly, - &|url, toolchain, prefix, download_cfg, temp_cfg| { + &|url, toolchain, prefix, download_cfg, tmp_cx| { let adds = [ Component::new( "rust-std".to_string(), @@ -993,7 +983,7 @@ fn unavailable_components_is_target() { &adds, &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1014,7 +1004,7 @@ fn unavailable_components_is_target() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap_err(); @@ -1078,7 +1068,7 @@ fn unavailable_components_with_same_target() { setup( Some(edit), GZOnly, - &|url, toolchain, prefix, download_cfg, temp_cfg| { + &|url, toolchain, prefix, download_cfg, tmp_cx| { // Update with rust-std and rustc change_channel_date(url, "nightly", "2016-02-01"); update_from_dist( @@ -1088,7 +1078,7 @@ fn unavailable_components_with_same_target() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1104,7 +1094,7 @@ fn unavailable_components_with_same_target() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap_err(); @@ -1139,7 +1129,7 @@ fn update_preserves_extensions() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { let adds = vec![ Component::new( "rust-std".to_string(), @@ -1161,7 +1151,7 @@ fn update_preserves_extensions() { &adds, &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1181,7 +1171,7 @@ fn update_preserves_extensions() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1201,7 +1191,7 @@ fn update_makes_no_changes_for_identical_manifest() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { let status = update_from_dist( url, toolchain, @@ -1209,7 +1199,7 @@ fn update_makes_no_changes_for_identical_manifest() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1221,7 +1211,7 @@ fn update_makes_no_changes_for_identical_manifest() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1235,7 +1225,7 @@ fn add_extensions_for_initial_install() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { let adds = vec![ Component::new( "rust-std".to_string(), @@ -1256,7 +1246,7 @@ fn add_extensions_for_initial_install() { &adds, &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1275,7 +1265,7 @@ fn add_extensions_for_same_manifest() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { update_from_dist( url, toolchain, @@ -1283,7 +1273,7 @@ fn add_extensions_for_same_manifest() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1308,7 +1298,7 @@ fn add_extensions_for_same_manifest() { &adds, &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1328,7 +1318,7 @@ fn add_extensions_for_upgrade() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { change_channel_date(url, "nightly", "2016-02-01"); update_from_dist( @@ -1338,7 +1328,7 @@ fn add_extensions_for_upgrade() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1365,7 +1355,7 @@ fn add_extensions_for_upgrade() { &adds, &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1386,7 +1376,7 @@ fn add_extension_not_in_manifest() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { let adds = vec![Component::new( "rust-bogus".to_string(), Some(TargetTriple::new("i686-apple-darwin")), @@ -1400,7 +1390,7 @@ fn add_extension_not_in_manifest() { &adds, &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1414,7 +1404,7 @@ fn add_extension_that_is_required_component() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { let adds = vec![Component::new( "rustc".to_string(), Some(TargetTriple::new("x86_64-apple-darwin")), @@ -1428,7 +1418,7 @@ fn add_extension_that_is_required_component() { &adds, &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1449,7 +1439,7 @@ fn add_extensions_does_not_remove_other_components() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { update_from_dist( url, toolchain, @@ -1457,7 +1447,7 @@ fn add_extensions_does_not_remove_other_components() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1475,7 +1465,7 @@ fn add_extensions_does_not_remove_other_components() { &adds, &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1492,7 +1482,7 @@ fn remove_extensions_for_initial_install() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { let removes = vec![Component::new( "rustc".to_string(), Some(TargetTriple::new("x86_64-apple-darwin")), @@ -1506,7 +1496,7 @@ fn remove_extensions_for_initial_install() { &[], &removes, download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1519,7 +1509,7 @@ fn remove_extensions_for_same_manifest() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { let adds = vec![ Component::new( "rust-std".to_string(), @@ -1540,7 +1530,7 @@ fn remove_extensions_for_same_manifest() { &adds, &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1558,7 +1548,7 @@ fn remove_extensions_for_same_manifest() { &[], &removes, download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1578,7 +1568,7 @@ fn remove_extensions_for_upgrade() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { change_channel_date(url, "nightly", "2016-02-01"); let adds = vec![ @@ -1601,7 +1591,7 @@ fn remove_extensions_for_upgrade() { &adds, &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1621,7 +1611,7 @@ fn remove_extensions_for_upgrade() { &[], &removes, download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1642,7 +1632,7 @@ fn remove_extension_not_in_manifest() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { change_channel_date(url, "nightly", "2016-02-01"); update_from_dist( @@ -1652,7 +1642,7 @@ fn remove_extension_not_in_manifest() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1672,7 +1662,7 @@ fn remove_extension_not_in_manifest() { &[], &removes, download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1702,7 +1692,7 @@ fn remove_extension_not_in_manifest_but_is_already_installed() { setup( Some(edit), GZOnly, - &|url, toolchain, prefix, download_cfg, temp_cfg| { + &|url, toolchain, prefix, download_cfg, tmp_cx| { change_channel_date(url, "nightly", "2016-02-01"); let adds = [Component::new( @@ -1717,7 +1707,7 @@ fn remove_extension_not_in_manifest_but_is_already_installed() { &adds, &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1737,7 +1727,7 @@ fn remove_extension_not_in_manifest_but_is_already_installed() { &[], &removes, download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1752,7 +1742,7 @@ fn remove_extension_that_is_required_component() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { update_from_dist( url, toolchain, @@ -1760,7 +1750,7 @@ fn remove_extension_that_is_required_component() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1778,7 +1768,7 @@ fn remove_extension_that_is_required_component() { &[], &removes, download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1792,7 +1782,7 @@ fn remove_extension_not_installed() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { update_from_dist( url, toolchain, @@ -1800,7 +1790,7 @@ fn remove_extension_not_installed() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1818,7 +1808,7 @@ fn remove_extension_not_installed() { &[], &removes, download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1835,7 +1825,7 @@ fn remove_extensions_does_not_remove_other_components() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { let adds = vec![Component::new( "rust-std".to_string(), Some(TargetTriple::new("i686-apple-darwin")), @@ -1849,7 +1839,7 @@ fn remove_extensions_does_not_remove_other_components() { &adds, &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1867,7 +1857,7 @@ fn remove_extensions_does_not_remove_other_components() { &[], &removes, download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1882,7 +1872,7 @@ fn add_and_remove_for_upgrade() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { change_channel_date(url, "nightly", "2016-02-01"); let adds = vec![Component::new( @@ -1898,7 +1888,7 @@ fn add_and_remove_for_upgrade() { &adds, &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1924,7 +1914,7 @@ fn add_and_remove_for_upgrade() { &adds, &removes, download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1944,7 +1934,7 @@ fn add_and_remove() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { let adds = vec![Component::new( "rust-std".to_string(), Some(TargetTriple::new("i686-unknown-linux-gnu")), @@ -1958,7 +1948,7 @@ fn add_and_remove() { &adds, &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -1982,7 +1972,7 @@ fn add_and_remove() { &adds, &removes, download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -2002,7 +1992,7 @@ fn add_and_remove_same_component() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { update_from_dist( url, toolchain, @@ -2010,7 +2000,7 @@ fn add_and_remove_same_component() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -2034,7 +2024,7 @@ fn add_and_remove_same_component() { &adds, &removes, download_cfg, - temp_cfg, + tmp_cx, false, ) .expect_err("can't both add and remove components"); @@ -2047,7 +2037,7 @@ fn bad_component_hash() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { let path = url.to_file_path().unwrap(); let path = path.join("dist/2016-02-02/rustc-nightly-x86_64-apple-darwin.tar.gz"); utils_raw::write_file(&path, "bogus").unwrap(); @@ -2059,7 +2049,7 @@ fn bad_component_hash() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap_err(); @@ -2077,7 +2067,7 @@ fn unable_to_download_component() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { let path = url.to_file_path().unwrap(); let path = path.join("dist/2016-02-02/rustc-nightly-x86_64-apple-darwin.tar.gz"); fs::remove_file(path).unwrap(); @@ -2089,7 +2079,7 @@ fn unable_to_download_component() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap_err(); @@ -2123,14 +2113,14 @@ fn reuse_downloaded_file() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { prevent_installation(prefix); let reuse_notification_fired = Arc::new(Cell::new(false)); let download_cfg = DownloadCfg { dist_root: download_cfg.dist_root, - temp_cfg: download_cfg.temp_cfg, + tmp_cx: download_cfg.tmp_cx, download_dir: download_cfg.download_dir, notify_handler: &|n| { if let Notification::FileAlreadyDownloaded = n { @@ -2146,7 +2136,7 @@ fn reuse_downloaded_file() { &[], &[], &download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap_err(); @@ -2161,7 +2151,7 @@ fn reuse_downloaded_file() { &[], &[], &download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -2176,7 +2166,7 @@ fn checks_files_hashes_before_reuse() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { let path = url.to_file_path().unwrap(); let target_hash = utils::read_file( "target hash", @@ -2197,7 +2187,7 @@ fn checks_files_hashes_before_reuse() { let noticed_bad_checksum = Arc::new(Cell::new(false)); let download_cfg = DownloadCfg { dist_root: download_cfg.dist_root, - temp_cfg: download_cfg.temp_cfg, + tmp_cx: download_cfg.tmp_cx, download_dir: download_cfg.download_dir, notify_handler: &|n| { if let Notification::CachedFileChecksumFailed = n { @@ -2213,7 +2203,7 @@ fn checks_files_hashes_before_reuse() { &[], &[], &download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); @@ -2228,7 +2218,7 @@ fn handle_corrupt_partial_downloads() { toolchain, prefix, download_cfg, - temp_cfg| { + tmp_cx| { // write a corrupt partial out let path = url.to_file_path().unwrap(); let target_hash = utils::read_file( @@ -2260,7 +2250,7 @@ fn handle_corrupt_partial_downloads() { &[], &[], download_cfg, - temp_cfg, + tmp_cx, false, ) .unwrap(); diff --git a/src/dist/temp.rs b/src/dist/temp.rs index ac10c1d72e..d5559685a2 100644 --- a/src/dist/temp.rs +++ b/src/dist/temp.rs @@ -4,7 +4,7 @@ use std::io; use std::ops; use std::path::{Path, PathBuf}; -pub(crate) use anyhow::{Context, Result}; +pub(crate) use anyhow::{Context as _, Result}; use thiserror::Error as ThisError; use crate::utils::notify::NotificationLevel; @@ -23,7 +23,7 @@ pub(crate) enum CreatingError { #[derive(Debug)] pub(crate) struct Dir<'a> { - cfg: &'a Cfg, + cfg: &'a Context, path: PathBuf, } @@ -49,7 +49,7 @@ impl<'a> Drop for Dir<'a> { #[derive(Debug)] pub struct File<'a> { - cfg: &'a Cfg, + cfg: &'a Context, path: PathBuf, } @@ -120,13 +120,13 @@ impl<'a> Display for Notification<'a> { } } -pub struct Cfg { +pub struct Context { root_directory: PathBuf, pub dist_server: String, notify_handler: Box)>, } -impl Cfg { +impl Context { pub fn new( root_directory: PathBuf, dist_server: &str, @@ -199,7 +199,7 @@ impl Cfg { } } -impl fmt::Debug for Cfg { +impl fmt::Debug for Context { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Cfg") .field("root_directory", &self.root_directory) diff --git a/tests/suite/dist_install.rs b/tests/suite/dist_install.rs index b6f20dfcc5..8e0f07a878 100644 --- a/tests/suite/dist_install.rs +++ b/tests/suite/dist_install.rs @@ -111,13 +111,13 @@ fn basic_install() { let prefix = InstallPrefix::from(instdir.path().to_owned()); let tmpdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( tmpdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), ); let notify = |_: Notification<'_>| (); - let tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); let components = Components::open(prefix).unwrap(); @@ -157,13 +157,13 @@ fn multiple_component_install() { let prefix = InstallPrefix::from(instdir.path().to_owned()); let tmpdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( tmpdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), ); let notify = |_: Notification<'_>| (); - let tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); let components = Components::open(prefix).unwrap(); @@ -207,13 +207,13 @@ fn uninstall() { let prefix = InstallPrefix::from(instdir.path().to_owned()); let tmpdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( tmpdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), ); let notify = |_: Notification<'_>| (); - let tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); let components = Components::open(prefix.clone()).unwrap(); @@ -225,7 +225,7 @@ fn uninstall() { // Now uninstall let notify = |_: Notification<'_>| (); - let mut tx = Transaction::new(prefix, &tmpcfg, ¬ify); + let mut tx = Transaction::new(prefix, &tmp_cx, ¬ify); for component in components.list().unwrap() { tx = component.uninstall(tx).unwrap(); } @@ -264,13 +264,13 @@ fn component_bad_version() { let prefix = InstallPrefix::from(instdir.path().to_owned()); let tmpdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( tmpdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), ); let notify = |_: Notification<'_>| (); - let tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); let components = Components::open(prefix.clone()).unwrap(); @@ -310,13 +310,13 @@ fn install_to_prefix_that_does_not_exist() { let prefix = InstallPrefix::from(does_not_exist.clone()); let tmpdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap(); - let tmpcfg = temp::Cfg::new( + let tmp_cx = temp::Context::new( tmpdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), ); let notify = |_: Notification<'_>| (); - let tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); + let tx = Transaction::new(prefix.clone(), &tmp_cx, ¬ify); let components = Components::open(prefix).unwrap();