Skip to content

Commit

Permalink
Rename temp::Cfg to TemporaryContext
Browse files Browse the repository at this point in the history
The previous name was confusing since there was another `Cfg` type
already, and `temp::Cfg` didn't really represent "configuration".

Also renames variables of this type to have consistent names.
  • Loading branch information
djc committed Apr 9, 2024
1 parent af8c9bb commit e8c9743
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 237 deletions.
2 changes: 1 addition & 1 deletion src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ fn update(cfg: &mut Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
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 {
Expand Down
10 changes: 5 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
dist::{
dist::{self, PartialToolchainDesc, Profile, ToolchainDesc},
download::DownloadCfg,
temp,
temp::TemporaryContext,
},
errors::RustupError,
fallback_settings::FallbackSettings,
Expand Down Expand Up @@ -182,7 +182,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: TemporaryContext,
pub toolchain_override: Option<ResolvableToolchainName>,
pub env_override: Option<LocalToolchainName>,
pub dist_root_url: String,
Expand Down Expand Up @@ -245,7 +245,7 @@ impl Cfg {
};

let notify_clone = notify_handler.clone();
let temp_cfg = temp::Cfg::new(
let tmp_cx = TemporaryContext::new(
rustup_dir.join("tmp"),
dist_root_server.as_str(),
Box::new(move |n| (notify_clone)(n.into())),
Expand All @@ -260,7 +260,7 @@ impl Cfg {
toolchains_dir,
update_hash_dir,
download_dir,
temp_cfg,
tmp_cx,
notify_handler,
toolchain_override: None,
env_override,
Expand All @@ -285,7 +285,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,
}
Expand Down
18 changes: 9 additions & 9 deletions src/dist/component/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::currentprocess::{filesource::StderrSource, varsource::VarSource};
use crate::diskio::{get_executor, CompletedIo, Executor, FileBuffer, Item, Kind, IO_CHUNK_SIZE};
use crate::dist::component::components::*;
use crate::dist::component::transaction::*;
use crate::dist::temp;
use crate::dist::temp::{self, TemporaryContext};
use crate::errors::*;
use crate::process;
use crate::utils::notifications::Notification;
Expand Down Expand Up @@ -143,10 +143,10 @@ pub(crate) struct TarPackage<'a>(DirectoryPackage, temp::Dir<'a>);
impl<'a> TarPackage<'a> {
pub(crate) fn new<R: Read>(
stream: R,
temp_cfg: &'a temp::Cfg,
tmp_cx: &'a TemporaryContext,
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
) -> Result<Self> {
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
Expand Down Expand Up @@ -555,13 +555,13 @@ pub(crate) struct TarGzPackage<'a>(TarPackage<'a>);
impl<'a> TarGzPackage<'a> {
pub(crate) fn new<R: Read>(
stream: R,
temp_cfg: &'a temp::Cfg,
tmp_cx: &'a TemporaryContext,
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
) -> Result<Self> {
let stream = flate2::read::GzDecoder::new(stream);
Ok(TarGzPackage(TarPackage::new(
stream,
temp_cfg,
tmp_cx,
notify_handler,
)?))
}
Expand Down Expand Up @@ -591,13 +591,13 @@ pub(crate) struct TarXzPackage<'a>(TarPackage<'a>);
impl<'a> TarXzPackage<'a> {
pub(crate) fn new<R: Read>(
stream: R,
temp_cfg: &'a temp::Cfg,
tmp_cx: &'a TemporaryContext,
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
) -> Result<Self> {
let stream = xz2::read::XzDecoder::new(stream);
Ok(TarXzPackage(TarPackage::new(
stream,
temp_cfg,
tmp_cx,
notify_handler,
)?))
}
Expand Down Expand Up @@ -627,13 +627,13 @@ pub(crate) struct TarZStdPackage<'a>(TarPackage<'a>);
impl<'a> TarZStdPackage<'a> {
pub(crate) fn new<R: Read>(
stream: R,
temp_cfg: &'a temp::Cfg,
tmp_cx: &'a TemporaryContext,
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
) -> Result<Self> {
let stream = zstd::stream::read::Decoder::new(stream)?;
Ok(TarZStdPackage(TarPackage::new(
stream,
temp_cfg,
tmp_cx,
notify_handler,
)?))
}
Expand Down
Loading

0 comments on commit e8c9743

Please sign in to comment.