Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ async fn update(

info!("cleaning up downloads & tmp directories");
utils::delete_dir_contents_following_links(&cfg.download_dir);
cfg.tmp_cx.clean();
dl_cfg.tmp_cx.clean();
}

Ok(exit_code)
Expand Down
13 changes: 6 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
cli::{common, self_update::SelfUpdateMode},
dist::{
self, AutoInstallMode, DistOptions, PartialToolchainDesc, Profile, TargetTriple,
ToolchainDesc, temp,
ToolchainDesc,
},
errors::RustupError,
fallback_settings::FallbackSettings,
Expand Down Expand Up @@ -239,9 +239,9 @@ pub(crate) struct Cfg<'a> {
pub toolchains_dir: PathBuf,
update_hash_dir: PathBuf,
pub download_dir: PathBuf,
pub tmp_cx: temp::Context,
pub toolchain_override: Option<ResolvableToolchainName>,
env_override: Option<LocalToolchainName>,
pub(crate) dist_root_server: String,
pub dist_root_url: String,
pub quiet: bool,
pub current_dir: PathBuf,
Expand Down Expand Up @@ -300,8 +300,7 @@ impl<'a> Cfg<'a> {
};

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

let cfg = Self {
profile_override: None,
Expand All @@ -311,9 +310,9 @@ impl<'a> Cfg<'a> {
toolchains_dir,
update_hash_dir,
download_dir,
tmp_cx,
toolchain_override: None,
env_override,
dist_root_server,
dist_root_url: dist_root,
quiet,
current_dir,
Expand Down Expand Up @@ -954,9 +953,9 @@ impl Debug for Cfg<'_> {
toolchains_dir,
update_hash_dir,
download_dir,
tmp_cx,
toolchain_override,
env_override,
dist_root_server,
dist_root_url,
quiet,
current_dir,
Expand All @@ -971,9 +970,9 @@ impl Debug for Cfg<'_> {
.field("toolchains_dir", toolchains_dir)
.field("update_hash_dir", update_hash_dir)
.field("download_dir", download_dir)
.field("tmp_cx", tmp_cx)
.field("toolchain_override", toolchain_override)
.field("env_override", env_override)
.field("dist_root_server", dist_root_server)
.field("dist_root_url", dist_root_url)
.field("quiet", quiet)
.field("current_dir", current_dir)
Expand Down
2 changes: 1 addition & 1 deletion src/diskio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl IncrementalFileState {
/// Trait object for performing IO. At this point the overhead
/// of trait invocation is not a bottleneck, but if it becomes
/// one we could consider an enum variant based approach instead.
pub(crate) trait Executor {
pub(crate) trait Executor: Send {
/// Perform a single operation.
/// During overload situations previously queued items may
/// need to be completed before the item is accepted:
Expand Down
14 changes: 7 additions & 7 deletions src/dist/component/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Components {
Ok(None)
}
}
fn write_version(&self, tx: &mut Transaction<'_>) -> Result<()> {
fn write_version(&self, tx: &mut Transaction) -> Result<()> {
tx.modify_file(self.prefix.rel_manifest_file(VERSION_FILE))?;
utils::write_file(
VERSION_FILE,
Expand All @@ -78,7 +78,7 @@ impl Components {
})
.collect())
}
pub(crate) fn add<'a>(&self, name: &str, tx: Transaction<'a>) -> ComponentBuilder<'a> {
pub(crate) fn add(&self, name: &str, tx: Transaction) -> ComponentBuilder {
ComponentBuilder {
components: self.clone(),
name: name.to_owned(),
Expand All @@ -95,14 +95,14 @@ impl Components {
}
}

pub(crate) struct ComponentBuilder<'a> {
pub(crate) struct ComponentBuilder {
components: Components,
name: String,
parts: Vec<ComponentPart>,
tx: Transaction<'a>,
tx: Transaction,
}

impl<'a> ComponentBuilder<'a> {
impl ComponentBuilder {
pub(crate) fn copy_file(&mut self, path: PathBuf, src: &Path) -> Result<()> {
self.parts.push(ComponentPart {
kind: ComponentPartKind::File,
Expand Down Expand Up @@ -131,7 +131,7 @@ impl<'a> ComponentBuilder<'a> {
});
self.tx.move_dir(&self.name, path, src)
}
pub(crate) fn finish(mut self) -> Result<Transaction<'a>> {
pub(crate) fn finish(mut self) -> Result<Transaction> {
// Write component manifest
let path = self.components.rel_component_manifest(&self.name);
let abs_path = self.components.prefix.abs_path(&path);
Expand Down Expand Up @@ -254,7 +254,7 @@ impl Component {
}
Ok(result)
}
pub fn uninstall<'a>(&self, mut tx: Transaction<'a>) -> Result<Transaction<'a>> {
pub fn uninstall(&self, mut tx: Transaction) -> Result<Transaction> {
// Update components file
let path = self.components.rel_components_file();
let abs_path = self.components.prefix.abs_path(&path);
Expand Down
6 changes: 3 additions & 3 deletions src/dist/component/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ impl<P: Deref<Target = Path>> DirectoryPackage<P> {
}
}

pub fn install<'a>(
pub fn install(
&self,
target: &Components,
name: &str,
short_name: Option<&str>,
tx: Transaction<'a>,
) -> Result<Transaction<'a>> {
tx: Transaction,
) -> Result<Transaction> {
let actual_name = if self.components.contains(name) {
name
} else if let Some(n) = short_name {
Expand Down
19 changes: 12 additions & 7 deletions src/dist/component/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use std::fs::File;
use std::path::{Path, PathBuf};
use std::sync::Arc;

use anyhow::{Context, Result, anyhow};
use tracing::{error, info};
Expand All @@ -33,16 +34,20 @@ use crate::utils;
///
/// All operations that create files will fail if the destination
/// already exists.
pub struct Transaction<'a> {
pub struct Transaction {
prefix: InstallPrefix,
changes: Vec<ChangedItem>,
tmp_cx: &'a temp::Context,
tmp_cx: Arc<temp::Context>,
committed: bool,
pub(super) permit_copy_rename: bool,
}

impl<'a> Transaction<'a> {
pub fn new(prefix: InstallPrefix, tmp_cx: &'a temp::Context, permit_copy_rename: bool) -> Self {
impl Transaction {
pub fn new(
prefix: InstallPrefix,
tmp_cx: Arc<temp::Context>,
permit_copy_rename: bool,
) -> Self {
Transaction {
prefix,
changes: Vec::new(),
Expand Down Expand Up @@ -189,14 +194,14 @@ impl<'a> Transaction<'a> {
Ok(())
}

pub(crate) fn temp(&self) -> &'a temp::Context {
self.tmp_cx
pub(crate) fn temp(&self) -> &temp::Context {
&self.tmp_cx
}
}

/// If a Transaction is dropped without being committed, the changes
/// are automatically rolled back.
impl Drop for Transaction<'_> {
impl Drop for Transaction {
fn drop(&mut self) {
if !self.committed {
info!("rolling back changes");
Expand Down
9 changes: 6 additions & 3 deletions src/dist/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fs;
use std::io::Read;
use std::ops;
use std::path::{Path, PathBuf};
use std::sync::Mutex;
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};

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

pub struct DownloadCfg<'a> {
pub tmp_cx: &'a temp::Context,
pub tmp_cx: Arc<temp::Context>,
pub download_dir: &'a PathBuf,
pub(super) tracker: DownloadTracker,
pub(super) permit_copy_rename: bool,
Expand All @@ -34,7 +34,10 @@ impl<'a> DownloadCfg<'a> {
/// construct a download configuration
pub(crate) fn new(cfg: &'a Cfg<'a>) -> Self {
DownloadCfg {
tmp_cx: &cfg.tmp_cx,
tmp_cx: Arc::new(temp::Context::new(
cfg.rustup_dir.join("tmp"),
cfg.dist_root_server.as_str(),
)),
download_dir: &cfg.download_dir,
tracker: DownloadTracker::new(!cfg.quiet, cfg.process),
permit_copy_rename: cfg.process.permit_copy_rename(),
Expand Down
Loading