Skip to content
Open
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
27 changes: 17 additions & 10 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ pub(crate) fn self_update_permitted(explicit: bool) -> Result<SelfUpdatePermissi
}

/// Performs all of a self-update: check policy, download, apply and exit.
pub(crate) async fn self_update(dl_cfg: &DownloadCfg<'_>) -> Result<utils::ExitCode> {
pub(crate) async fn self_update(dl_cfg: &DownloadCfg) -> Result<utils::ExitCode> {
match self_update_permitted(false)? {
SelfUpdatePermission::HardFail => {
error!("Unable to self-update. STOP");
Expand All @@ -1144,7 +1144,7 @@ pub(crate) async fn self_update(dl_cfg: &DownloadCfg<'_>) -> Result<utils::ExitC
return run_update(setup_path);
} else {
// Try again in case we emitted "tool `{}` is already installed" last time.
install_proxies(dl_cfg.process)?;
install_proxies(&dl_cfg.process)?;
}

Ok(utils::ExitCode(0))
Expand Down Expand Up @@ -1242,7 +1242,7 @@ fn parse_new_rustup_version(version: String) -> String {
String::from(matched_version)
}

pub(crate) async fn prepare_update(dl_cfg: &DownloadCfg<'_>) -> Result<Option<PathBuf>> {
pub(crate) async fn prepare_update(dl_cfg: &DownloadCfg) -> Result<Option<PathBuf>> {
let cargo_home = dl_cfg.process.cargo_home()?;
let rustup_path = cargo_home.join(format!("bin{MAIN_SEPARATOR}rustup{EXE_SUFFIX}"));
let setup_path = cargo_home.join(format!("bin{MAIN_SEPARATOR}rustup-init{EXE_SUFFIX}"));
Expand All @@ -1265,10 +1265,10 @@ pub(crate) async fn prepare_update(dl_cfg: &DownloadCfg<'_>) -> Result<Option<Pa
// If someone really wants to use another version, they still can enforce
// that using the environment variable RUSTUP_OVERRIDE_HOST_TRIPLE.
#[cfg(windows)]
let triple = TargetTriple::from_host(dl_cfg.process).unwrap_or(triple);
let triple = TargetTriple::from_host(&dl_cfg.process).unwrap_or(triple);

// Get update root.
let update_root = update_root(dl_cfg.process);
let update_root = update_root(&dl_cfg.process);

// Get current version
let current_version = env!("CARGO_PKG_VERSION");
Expand Down Expand Up @@ -1296,16 +1296,16 @@ pub(crate) async fn prepare_update(dl_cfg: &DownloadCfg<'_>) -> Result<Option<Pa

// Download new version
info!("downloading self-update (new version: {available_version})");
download_file(&download_url, &setup_path, None, None, dl_cfg.process).await?;
download_file(&download_url, &setup_path, None, None, &dl_cfg.process).await?;

// Mark as executable
utils::make_executable(&setup_path)?;

Ok(Some(setup_path))
}

async fn get_available_rustup_version(dl_cfg: &DownloadCfg<'_>) -> Result<String> {
let update_root = update_root(dl_cfg.process);
async fn get_available_rustup_version(dl_cfg: &DownloadCfg) -> Result<String> {
let update_root = update_root(&dl_cfg.process);
let tempdir = tempfile::Builder::new()
.prefix("rustup-update")
.tempdir()
Expand All @@ -1315,7 +1315,14 @@ async fn get_available_rustup_version(dl_cfg: &DownloadCfg<'_>) -> Result<String
let release_file_url = format!("{update_root}/release-stable.toml");
let release_file_url = utils::parse_url(&release_file_url)?;
let release_file = tempdir.path().join("release-stable.toml");
download_file(&release_file_url, &release_file, None, None, dl_cfg.process).await?;
download_file(
&release_file_url,
&release_file,
None,
None,
&dl_cfg.process,
)
.await?;
let release_toml_str = utils::read_file("rustup release", &release_file)?;
let release_toml = toml::from_str::<RustupManifest>(&release_toml_str)
.context("unable to parse rustup release file")?;
Expand Down Expand Up @@ -1363,7 +1370,7 @@ impl fmt::Display for SchemaVersion {
}

/// Returns whether an update was available
pub(crate) async fn check_rustup_update(dl_cfg: &DownloadCfg<'_>) -> Result<bool> {
pub(crate) async fn check_rustup_update(dl_cfg: &DownloadCfg) -> Result<bool> {
let t = dl_cfg.process.stdout();
let mut t = t.lock();
// Get current rustup version
Expand Down
2 changes: 1 addition & 1 deletion src/cli/self_update/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ pub(crate) async fn try_install_msvc(
&visual_studio,
None,
None,
dl_cfg.process,
&dl_cfg.process,
)
.await?;

Expand Down
8 changes: 6 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fmt::{self, Debug, Display};
use std::io;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::Arc;

use anyhow::{Context, Result, anyhow, bail};
use serde::Deserialize;
Expand Down Expand Up @@ -238,7 +239,7 @@ pub(crate) struct Cfg<'a> {
pub toolchains_dir: PathBuf,
update_hash_dir: PathBuf,
pub download_dir: PathBuf,
pub tmp_cx: temp::Context,
pub tmp_cx: Arc<temp::Context>,
pub toolchain_override: Option<ResolvableToolchainName>,
env_override: Option<LocalToolchainName>,
pub dist_root_url: String,
Expand Down Expand Up @@ -299,7 +300,10 @@ 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 tmp_cx = Arc::new(temp::Context::new(
rustup_dir.join("tmp"),
dist_root_server.as_str(),
));
let dist_root = dist_root_server + "/dist";

let cfg = Self {
Expand Down
18 changes: 7 additions & 11 deletions src/dist/component/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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 @@ -79,7 +79,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 @@ -96,14 +96,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 @@ -132,7 +132,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 @@ -255,11 +255,7 @@ impl Component {
}
Ok(result)
}
pub fn uninstall<'a>(
&self,
mut tx: Transaction<'a>,
process: &Process,
) -> Result<Transaction<'a>> {
pub fn uninstall(&self, mut tx: Transaction, process: &Process) -> Result<Transaction> {
// Update components file
let path = self.components.rel_components_file();
let abs_path = self.components.prefix.abs_path(&path);
Expand Down
50 changes: 25 additions & 25 deletions src/dist/component/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ pub(crate) const VERSION_FILE: &str = "rust-installer-version";

pub trait Package: fmt::Debug {
fn contains(&self, component: &str, short_name: Option<&str>) -> bool;
fn install<'a>(
fn install(
&self,
target: &Components,
component: &str,
short_name: Option<&str>,
tx: Transaction<'a>,
) -> Result<Transaction<'a>>;
tx: Transaction,
) -> Result<Transaction>;
fn components(&self) -> Vec<String>;
}

Expand Down Expand Up @@ -78,13 +78,13 @@ impl Package for DirectoryPackage {
false
}
}
fn install<'a>(
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 Expand Up @@ -139,7 +139,7 @@ impl Package for DirectoryPackage {
pub(crate) struct TarPackage(DirectoryPackage, temp::Dir);

impl TarPackage {
pub(crate) fn new<R: Read>(stream: R, dl_cfg: &DownloadCfg<'_>) -> Result<Self> {
pub(crate) fn new<R: Read>(stream: R, dl_cfg: &DownloadCfg) -> Result<Self> {
let temp_dir = dl_cfg.tmp_cx.new_directory()?;
let mut archive = tar::Archive::new(stream);
// The rust-installer packages unpack to a directory called
Expand All @@ -159,7 +159,7 @@ impl TarPackage {
fn unpack_ram(
io_chunk_size: usize,
effective_max_ram: Option<usize>,
dl_cfg: &DownloadCfg<'_>,
dl_cfg: &DownloadCfg,
) -> usize {
const RAM_ALLOWANCE_FOR_RUSTUP_AND_BUFFERS: usize = 200 * 1024 * 1024;
let minimum_ram = io_chunk_size * 2;
Expand Down Expand Up @@ -285,7 +285,7 @@ enum DirStatus {
fn unpack_without_first_dir<R: Read>(
archive: &mut tar::Archive<R>,
path: &Path,
dl_cfg: &DownloadCfg<'_>,
dl_cfg: &DownloadCfg,
) -> Result<()> {
let entries = archive.entries()?;
let effective_max_ram = match effective_limits::memory_limit() {
Expand All @@ -296,7 +296,7 @@ fn unpack_without_first_dir<R: Read>(
}
};
let unpack_ram = unpack_ram(IO_CHUNK_SIZE, effective_max_ram, dl_cfg);
let mut io_executor: Box<dyn Executor> = get_executor(unpack_ram, dl_cfg.process)?;
let mut io_executor: Box<dyn Executor> = get_executor(unpack_ram, &dl_cfg.process)?;

let mut directories: HashMap<PathBuf, DirStatus> = HashMap::new();
// Path is presumed to exist. Call it a precondition.
Expand Down Expand Up @@ -530,13 +530,13 @@ impl Package for TarPackage {
fn contains(&self, component: &str, short_name: Option<&str>) -> bool {
self.0.contains(component, short_name)
}
fn install<'b>(
fn install(
&self,
target: &Components,
component: &str,
short_name: Option<&str>,
tx: Transaction<'b>,
) -> Result<Transaction<'b>> {
tx: Transaction,
) -> Result<Transaction> {
self.0.install(target, component, short_name, tx)
}
fn components(&self) -> Vec<String> {
Expand All @@ -548,7 +548,7 @@ impl Package for TarPackage {
pub(crate) struct TarGzPackage(TarPackage);

impl TarGzPackage {
pub(crate) fn new<R: Read>(stream: R, dl_cfg: &DownloadCfg<'_>) -> Result<Self> {
pub(crate) fn new<R: Read>(stream: R, dl_cfg: &DownloadCfg) -> Result<Self> {
let stream = flate2::read::GzDecoder::new(stream);
Ok(TarGzPackage(TarPackage::new(stream, dl_cfg)?))
}
Expand All @@ -558,13 +558,13 @@ impl Package for TarGzPackage {
fn contains(&self, component: &str, short_name: Option<&str>) -> bool {
self.0.contains(component, short_name)
}
fn install<'b>(
fn install(
&self,
target: &Components,
component: &str,
short_name: Option<&str>,
tx: Transaction<'b>,
) -> Result<Transaction<'b>> {
tx: Transaction,
) -> Result<Transaction> {
self.0.install(target, component, short_name, tx)
}
fn components(&self) -> Vec<String> {
Expand All @@ -576,7 +576,7 @@ impl Package for TarGzPackage {
pub(crate) struct TarXzPackage(TarPackage);

impl TarXzPackage {
pub(crate) fn new<R: Read>(stream: R, dl_cfg: &DownloadCfg<'_>) -> Result<Self> {
pub(crate) fn new<R: Read>(stream: R, dl_cfg: &DownloadCfg) -> Result<Self> {
let stream = xz2::read::XzDecoder::new(stream);
Ok(TarXzPackage(TarPackage::new(stream, dl_cfg)?))
}
Expand All @@ -586,13 +586,13 @@ impl Package for TarXzPackage {
fn contains(&self, component: &str, short_name: Option<&str>) -> bool {
self.0.contains(component, short_name)
}
fn install<'b>(
fn install(
&self,
target: &Components,
component: &str,
short_name: Option<&str>,
tx: Transaction<'b>,
) -> Result<Transaction<'b>> {
tx: Transaction,
) -> Result<Transaction> {
self.0.install(target, component, short_name, tx)
}
fn components(&self) -> Vec<String> {
Expand All @@ -604,7 +604,7 @@ impl Package for TarXzPackage {
pub(crate) struct TarZStdPackage(TarPackage);

impl TarZStdPackage {
pub(crate) fn new<R: Read>(stream: R, dl_cfg: &DownloadCfg<'_>) -> Result<Self> {
pub(crate) fn new<R: Read>(stream: R, dl_cfg: &DownloadCfg) -> Result<Self> {
let stream = zstd::stream::read::Decoder::new(stream)?;
Ok(TarZStdPackage(TarPackage::new(stream, dl_cfg)?))
}
Expand All @@ -614,13 +614,13 @@ impl Package for TarZStdPackage {
fn contains(&self, component: &str, short_name: Option<&str>) -> bool {
self.0.contains(component, short_name)
}
fn install<'b>(
fn install(
&self,
target: &Components,
component: &str,
short_name: Option<&str>,
tx: Transaction<'b>,
) -> Result<Transaction<'b>> {
tx: Transaction,
) -> Result<Transaction> {
self.0.install(target, component, short_name, tx)
}
fn components(&self) -> Vec<String> {
Expand Down
Loading
Loading