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
5 changes: 1 addition & 4 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1557,10 +1557,7 @@ fn override_remove(
};

for p in &paths {
if cfg
.settings_file
.with_mut(|s| Ok(s.remove_override(p, cfg.notify_handler.as_ref())))?
{
if cfg.settings_file.with_mut(|s| Ok(s.remove_override(p)))? {
info!("override toolchain for '{}' removed", p.display());
} else {
info!("no override toolchain for '{}'", p.display());
Expand Down
9 changes: 4 additions & 5 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ use crate::{
dist::{self, PartialToolchainDesc, Profile, TargetTriple, ToolchainDesc},
errors::RustupError,
install::UpdateStatus,
notifications::Notification,
process::{Process, terminalsource},
toolchain::{
DistributableToolchain, MaybeOfficialToolchainName, ResolvableToolchainName, Toolchain,
Expand Down Expand Up @@ -770,7 +769,7 @@ fn install_bins(process: &Process) -> Result<()> {
let this_exe_path = utils::current_exe()?;
let rustup_path = bin_path.join(format!("rustup{EXE_SUFFIX}"));

utils::ensure_dir_exists("bin", &bin_path, &|_: Notification<'_>| {})?;
utils::ensure_dir_exists("bin", &bin_path)?;
// NB: Even on Linux we can't just copy the new binary over the (running)
// old binary; we must unlink it first.
if rustup_path.exists() {
Expand Down Expand Up @@ -1004,7 +1003,7 @@ pub(crate) fn uninstall(no_prompt: bool, process: &Process) -> Result<utils::Exi
// Delete RUSTUP_HOME
let rustup_dir = home::rustup_home()?;
if rustup_dir.exists() {
utils::remove_dir("rustup_home", &rustup_dir, &|_: Notification<'_>| {})?;
utils::remove_dir("rustup_home", &rustup_dir)?;
}

info!("removing cargo home");
Expand All @@ -1026,7 +1025,7 @@ pub(crate) fn uninstall(no_prompt: bool, process: &Process) -> Result<utils::Exi
})?;
if dirent.file_name().to_str() != Some("bin") {
if dirent.path().is_dir() {
utils::remove_dir("cargo_home", &dirent.path(), &|_: Notification<'_>| {})?;
utils::remove_dir("cargo_home", &dirent.path())?;
} else {
utils::remove_file("cargo_home", &dirent.path())?;
}
Expand Down Expand Up @@ -1054,7 +1053,7 @@ pub(crate) fn uninstall(no_prompt: bool, process: &Process) -> Result<utils::Exi
let file_is_tool = name.to_str().map(|n| tools.iter().any(|t| *t == n));
if file_is_tool == Some(false) {
if dirent.path().is_dir() {
utils::remove_dir("cargo_home", &dirent.path(), &|_: Notification<'_>| {})?;
utils::remove_dir("cargo_home", &dirent.path())?;
} else {
utils::remove_file("cargo_home", &dirent.path())?;
}
Expand Down
5 changes: 2 additions & 3 deletions src/cli/self_update/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use tracing::{error, warn};

use super::install_bins;
use super::shell::{self, Posix, UnixShell};
use crate::notifications::Notification;
use crate::process::Process;
use crate::utils;

Expand Down Expand Up @@ -50,7 +49,7 @@ pub(crate) fn do_anti_sudo_check(no_prompt: bool, process: &Process) -> Result<u

pub(crate) fn delete_rustup_and_cargo_home(process: &Process) -> Result<()> {
let cargo_home = process.cargo_home()?;
utils::remove_dir("cargo_home", &cargo_home, &|_: Notification<'_>| ())
utils::remove_dir("cargo_home", &cargo_home)
}

pub(crate) fn do_remove_from_path(process: &Process) -> Result<()> {
Expand Down Expand Up @@ -98,7 +97,7 @@ pub(crate) fn do_add_to_path(process: &Process) -> Result<()> {
rc.display()
)
})?;
utils::ensure_dir_exists("rcfile dir", rc_dir, &|_: Notification<'_>| ())?;
utils::ensure_dir_exists("rcfile dir", rc_dir)?;
utils::append_file("rcfile", &rc, cmd_to_write)
.with_context(|| format!("could not amend shell profile: '{}'", rc.display()))?;
}
Expand Down
3 changes: 1 addition & 2 deletions src/cli/self_update/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use super::{InstallOpts, install_bins, report_error};
use crate::cli::{download_tracker::DownloadTracker, markdown::md};
use crate::dist::TargetTriple;
use crate::download::download_file;
use crate::notifications::Notification;
use crate::process::{Process, terminalsource::ColorableTerminal};
use crate::utils;

Expand Down Expand Up @@ -373,7 +372,7 @@ pub fn complete_windows_uninstall(process: &Process) -> Result<utils::ExitCode>

// Now that the parent has exited there are hopefully no more files open in CARGO_HOME
let cargo_home = process.cargo_home()?;
utils::remove_dir("cargo_home", &cargo_home, &|_: Notification<'_>| ())?;
utils::remove_dir("cargo_home", &cargo_home)?;

// Now, run a *system* binary to inherit the DELETE_ON_CLOSE
// handle to *this* process, then exit. The OS will delete the gc
Expand Down
28 changes: 8 additions & 20 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use anyhow::{Context, Result, anyhow, bail};
use serde::Deserialize;
use thiserror::Error as ThisError;
use tokio_stream::StreamExt;
use tracing::trace;
use tracing::{error, trace};

use crate::dist::AutoInstallMode;
use crate::{
Expand Down Expand Up @@ -247,7 +247,7 @@ impl<'a> Cfg<'a> {
// Set up the rustup home directory
let rustup_dir = process.rustup_home()?;

utils::ensure_dir_exists("home", &rustup_dir, notify_handler.as_ref())?;
utils::ensure_dir_exists("home", &rustup_dir)?;

let settings_file = SettingsFile::new(rustup_dir.join("settings.toml"));
settings_file.with(|s| {
Expand Down Expand Up @@ -290,13 +290,7 @@ impl<'a> Cfg<'a> {
};

let dist_root_server = dist_root_server(process)?;

let notify_clone = notify_handler.clone();
let tmp_cx = temp::Context::new(
rustup_dir.join("tmp"),
dist_root_server.as_str(),
Box::new(move |n| (notify_clone)(n)),
);
let tmp_cx = temp::Context::new(rustup_dir.join("tmp"), dist_root_server.as_str());
let dist_root = dist_root_server + "/dist";

let cfg = Self {
Expand Down Expand Up @@ -411,9 +405,7 @@ impl<'a> Cfg<'a> {
}

pub(crate) fn ensure_toolchains_dir(&self) -> Result<(), anyhow::Error> {
utils::ensure_dir_exists("toolchains", &self.toolchains_dir, &|n| {
(self.notify_handler)(n)
})?;
utils::ensure_dir_exists("toolchains", &self.toolchains_dir)?;
Ok(())
}

Expand All @@ -437,11 +429,7 @@ impl<'a> Cfg<'a> {
create_parent: bool,
) -> Result<PathBuf> {
if create_parent {
utils::ensure_dir_exists(
"update-hash",
&self.update_hash_dir,
self.notify_handler.as_ref(),
)?;
utils::ensure_dir_exists("update-hash", &self.update_hash_dir)?;
}

Ok(self.update_hash_dir.join(toolchain.to_string()))
Expand All @@ -468,7 +456,7 @@ impl<'a> Cfg<'a> {
let dirs = utils::read_dir("toolchains", &self.toolchains_dir)?;
for dir in dirs {
let dir = dir.context("IO Error reading toolchains")?;
utils::remove_dir("toolchain", &dir.path(), self.notify_handler.as_ref())?;
utils::remove_dir("toolchain", &dir.path())?;
}

// Also delete the update hashes
Expand Down Expand Up @@ -582,7 +570,7 @@ impl<'a> Cfg<'a> {

while let Some(d) = dir {
// First check the override database
if let Some(name) = settings.dir_override(d, notify) {
if let Some(name) = settings.dir_override(d) {
let reason = ActiveReason::OverrideDB(d.to_owned());
// Note that `rustup override set` fully resolves it's input
// before writing to settings.toml, so resolving here may not
Expand Down Expand Up @@ -945,7 +933,7 @@ impl<'a> Cfg<'a> {
.update_extra(&[], &[], profile, force_update, false)
.await;
if let Err(e) = &st {
(self.notify_handler)(Notification::NonFatalError(e));
error!("{e}");
}
(desc, st)
});
Expand Down
2 changes: 1 addition & 1 deletion src/dist/component/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl Component {
let temp = tx.temp().new_file()?;
utils::filter_file("components", &abs_path, &temp, |l| l != self.name)?;
tx.modify_file(path)?;
utils::rename("components", &temp, &abs_path, tx.notify_handler(), process)?;
utils::rename("components", &temp, &abs_path, process)?;

// TODO: If this is the last component remove the components file
// and the version file.
Expand Down
32 changes: 16 additions & 16 deletions src/dist/component/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ impl Package for DirectoryPackage {

#[derive(Debug)]
#[allow(dead_code)] // temp::Dir is held for drop.
pub(crate) struct TarPackage<'a>(DirectoryPackage, temp::Dir<'a>);
pub(crate) struct TarPackage(DirectoryPackage, temp::Dir);

impl<'a> TarPackage<'a> {
pub(crate) fn new<R: Read>(stream: R, cx: &PackageContext<'a>) -> Result<Self> {
impl TarPackage {
pub(crate) fn new<R: Read>(stream: R, cx: &PackageContext<'_>) -> Result<Self> {
let temp_dir = cx.tmp_cx.new_directory()?;
let mut archive = tar::Archive::new(stream);
// The rust-installer packages unpack to a directory called
Expand Down Expand Up @@ -528,7 +528,7 @@ fn unpack_without_first_dir<R: Read>(
Ok(())
}

impl Package for TarPackage<'_> {
impl Package for TarPackage {
fn contains(&self, component: &str, short_name: Option<&str>) -> bool {
self.0.contains(component, short_name)
}
Expand All @@ -547,16 +547,16 @@ impl Package for TarPackage<'_> {
}

#[derive(Debug)]
pub(crate) struct TarGzPackage<'a>(TarPackage<'a>);
pub(crate) struct TarGzPackage(TarPackage);

impl<'a> TarGzPackage<'a> {
pub(crate) fn new<R: Read>(stream: R, cx: &PackageContext<'a>) -> Result<Self> {
impl TarGzPackage {
pub(crate) fn new<R: Read>(stream: R, cx: &PackageContext<'_>) -> Result<Self> {
let stream = flate2::read::GzDecoder::new(stream);
Ok(TarGzPackage(TarPackage::new(stream, cx)?))
}
}

impl Package for TarGzPackage<'_> {
impl Package for TarGzPackage {
fn contains(&self, component: &str, short_name: Option<&str>) -> bool {
self.0.contains(component, short_name)
}
Expand All @@ -575,16 +575,16 @@ impl Package for TarGzPackage<'_> {
}

#[derive(Debug)]
pub(crate) struct TarXzPackage<'a>(TarPackage<'a>);
pub(crate) struct TarXzPackage(TarPackage);

impl<'a> TarXzPackage<'a> {
pub(crate) fn new<R: Read>(stream: R, cx: &PackageContext<'a>) -> Result<Self> {
impl TarXzPackage {
pub(crate) fn new<R: Read>(stream: R, cx: &PackageContext<'_>) -> Result<Self> {
let stream = xz2::read::XzDecoder::new(stream);
Ok(TarXzPackage(TarPackage::new(stream, cx)?))
}
}

impl Package for TarXzPackage<'_> {
impl Package for TarXzPackage {
fn contains(&self, component: &str, short_name: Option<&str>) -> bool {
self.0.contains(component, short_name)
}
Expand All @@ -603,16 +603,16 @@ impl Package for TarXzPackage<'_> {
}

#[derive(Debug)]
pub(crate) struct TarZStdPackage<'a>(TarPackage<'a>);
pub(crate) struct TarZStdPackage(TarPackage);

impl<'a> TarZStdPackage<'a> {
pub(crate) fn new<R: Read>(stream: R, cx: &PackageContext<'a>) -> Result<Self> {
impl TarZStdPackage {
pub(crate) fn new<R: Read>(stream: R, cx: &PackageContext<'_>) -> Result<Self> {
let stream = zstd::stream::read::Decoder::new(stream)?;
Ok(TarZStdPackage(TarPackage::new(stream, cx)?))
}
}

impl Package for TarZStdPackage<'_> {
impl Package for TarZStdPackage {
fn contains(&self, component: &str, short_name: Option<&str>) -> bool {
self.0.contains(component, short_name)
}
Expand Down
Loading
Loading