Skip to content

Commit 94859c7

Browse files
committed
notifications: log directly when removing directories
1 parent a4c1ef3 commit 94859c7

File tree

10 files changed

+17
-32
lines changed

10 files changed

+17
-32
lines changed

src/cli/self_update.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ use crate::{
6161
dist::{self, PartialToolchainDesc, Profile, TargetTriple, ToolchainDesc},
6262
errors::RustupError,
6363
install::UpdateStatus,
64-
notifications::Notification,
6564
process::{Process, terminalsource},
6665
toolchain::{
6766
DistributableToolchain, MaybeOfficialToolchainName, ResolvableToolchainName, Toolchain,
@@ -1004,7 +1003,7 @@ pub(crate) fn uninstall(no_prompt: bool, process: &Process) -> Result<utils::Exi
10041003
// Delete RUSTUP_HOME
10051004
let rustup_dir = home::rustup_home()?;
10061005
if rustup_dir.exists() {
1007-
utils::remove_dir("rustup_home", &rustup_dir, &|_: Notification<'_>| {})?;
1006+
utils::remove_dir("rustup_home", &rustup_dir)?;
10081007
}
10091008

10101009
info!("removing cargo home");
@@ -1026,7 +1025,7 @@ pub(crate) fn uninstall(no_prompt: bool, process: &Process) -> Result<utils::Exi
10261025
})?;
10271026
if dirent.file_name().to_str() != Some("bin") {
10281027
if dirent.path().is_dir() {
1029-
utils::remove_dir("cargo_home", &dirent.path(), &|_: Notification<'_>| {})?;
1028+
utils::remove_dir("cargo_home", &dirent.path())?;
10301029
} else {
10311030
utils::remove_file("cargo_home", &dirent.path())?;
10321031
}
@@ -1054,7 +1053,7 @@ pub(crate) fn uninstall(no_prompt: bool, process: &Process) -> Result<utils::Exi
10541053
let file_is_tool = name.to_str().map(|n| tools.iter().any(|t| *t == n));
10551054
if file_is_tool == Some(false) {
10561055
if dirent.path().is_dir() {
1057-
utils::remove_dir("cargo_home", &dirent.path(), &|_: Notification<'_>| {})?;
1056+
utils::remove_dir("cargo_home", &dirent.path())?;
10581057
} else {
10591058
utils::remove_file("cargo_home", &dirent.path())?;
10601059
}

src/cli/self_update/unix.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use tracing::{error, warn};
66

77
use super::install_bins;
88
use super::shell::{self, Posix, UnixShell};
9-
use crate::notifications::Notification;
109
use crate::process::Process;
1110
use crate::utils;
1211

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

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

5655
pub(crate) fn do_remove_from_path(process: &Process) -> Result<()> {

src/cli/self_update/windows.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use super::{InstallOpts, install_bins, report_error};
2323
use crate::cli::{download_tracker::DownloadTracker, markdown::md};
2424
use crate::dist::TargetTriple;
2525
use crate::download::download_file;
26-
use crate::notifications::Notification;
2726
use crate::process::{Process, terminalsource::ColorableTerminal};
2827
use crate::utils;
2928

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

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

378377
// Now, run a *system* binary to inherit the DELETE_ON_CLOSE
379378
// handle to *this* process, then exit. The OS will delete the gc

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl<'a> Cfg<'a> {
462462
let dirs = utils::read_dir("toolchains", &self.toolchains_dir)?;
463463
for dir in dirs {
464464
let dir = dir.context("IO Error reading toolchains")?;
465-
utils::remove_dir("toolchain", &dir.path(), self.notify_handler.as_ref())?;
465+
utils::remove_dir("toolchain", &dir.path())?;
466466
}
467467

468468
// Also delete the update hashes

src/dist/component/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl<'a> ChangedItem<'a> {
239239
use self::ChangedItem::*;
240240
match self {
241241
AddedFile(path) => utils::remove_file("component", &prefix.abs_path(path))?,
242-
AddedDir(path) => utils::remove_dir("component", &prefix.abs_path(path), notify)?,
242+
AddedDir(path) => utils::remove_dir("component", &prefix.abs_path(path))?,
243243
RemovedFile(path, tmp) | ModifiedFile(path, Some(tmp)) => {
244244
utils::rename("component", tmp, &prefix.abs_path(path), notify, process)?
245245
}

src/dist/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ pub(crate) async fn update_from_dist(
10501050
// Don't leave behind an empty / broken installation directory
10511051
if res.is_err() && fresh_install {
10521052
// FIXME Ignoring cascading errors
1053-
let _ = utils::remove_dir("toolchain", prefix.path(), opts.dl_cfg.notify_handler);
1053+
let _ = utils::remove_dir("toolchain", prefix.path());
10541054
}
10551055

10561056
res

src/install.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl InstallMethod<'_> {
5656
}
5757

5858
nh(Notification::ToolchainDirectory(&self.dest_path()));
59-
let updated = self.run(&self.dest_path(), &|n| nh(n)).await?;
59+
let updated = self.run(&self.dest_path()).await?;
6060

6161
let status = match updated {
6262
false => {
@@ -84,13 +84,13 @@ impl InstallMethod<'_> {
8484
}
8585
}
8686

87-
async fn run(&self, path: &Path, notify_handler: &dyn Fn(Notification<'_>)) -> Result<bool> {
87+
async fn run(&self, path: &Path) -> Result<bool> {
8888
if path.exists() {
8989
// Don't uninstall first for Dist method
9090
match self {
9191
InstallMethod::Dist { .. } => {}
9292
_ => {
93-
uninstall(path, notify_handler)?;
93+
uninstall(path)?;
9494
}
9595
}
9696
}
@@ -156,6 +156,6 @@ impl InstallMethod<'_> {
156156
}
157157
}
158158

159-
pub(crate) fn uninstall(path: &Path, notify_handler: &dyn Fn(Notification<'_>)) -> Result<()> {
160-
utils::remove_dir("install", path, notify_handler)
159+
pub(crate) fn uninstall(path: &Path) -> Result<()> {
160+
utils::remove_dir("install", path)
161161
}

src/notifications.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ pub enum Notification<'a> {
3737
StrayHash(&'a Path),
3838
SignatureInvalid(&'a str),
3939
RetryingDownload(&'a str),
40-
RemovingDirectory(&'a str, &'a Path),
4140
DownloadingFile(&'a Url, &'a Path),
4241
/// Received the Content-Length of the to-be downloaded data with
4342
/// the respective URL of the download (for tracking concurrent downloads).
@@ -120,8 +119,7 @@ impl Notification<'_> {
120119
NonFatalError(_) => NotificationLevel::Error,
121120
SignatureInvalid(_) => NotificationLevel::Warn,
122121
SetDefaultBufferSize(_) => NotificationLevel::Trace,
123-
RemovingDirectory(_, _)
124-
| DownloadingFile(_, _)
122+
DownloadingFile(_, _)
125123
| DownloadContentLengthReceived(_, _)
126124
| DownloadDataReceived(_, _)
127125
| DownloadFinished(_)
@@ -254,9 +252,6 @@ impl Display for Notification<'_> {
254252
SignatureInvalid(url) => write!(f, "Signature verification failed for '{url}'"),
255253
RetryingDownload(url) => write!(f, "retrying download for '{url}'"),
256254
Error(e) => write!(f, "error: '{e}'"),
257-
RemovingDirectory(name, path) => {
258-
write!(f, "removing {} directory: '{}'", name, path.display())
259-
}
260255
RenameInUse(src, dest) => write!(
261256
f,
262257
"retrying renaming '{}' to '{}'",

src/toolchain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ impl<'a> Toolchain<'a> {
555555
utils::ensure_file_removed(name, &path)?
556556
}
557557
InstalledPath::Dir { path } => {
558-
install::uninstall(path, &|n| (cfg.notify_handler)(n))?
558+
install::uninstall(path)?
559559
}
560560
}
561561
}

src/utils/mod.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,8 @@ pub(crate) fn copy_file(src: &Path, dest: &Path) -> Result<()> {
248248
}
249249
}
250250

251-
pub(crate) fn remove_dir<'a, N>(
252-
name: &'static str,
253-
path: &'a Path,
254-
notify_handler: &dyn Fn(N),
255-
) -> Result<()>
256-
where
257-
N: From<Notification<'a>>,
258-
{
259-
notify_handler(Notification::RemovingDirectory(name, path).into());
251+
pub(crate) fn remove_dir(name: &'static str, path: &Path) -> Result<()> {
252+
debug!(name, path = %path.display(), "removing directory");
260253
raw::remove_dir(path).with_context(|| RustupError::RemovingDirectory {
261254
name,
262255
path: PathBuf::from(path),

0 commit comments

Comments
 (0)