Skip to content

Commit e2d0949

Browse files
committed
notifications: log directly when creating directories
1 parent 60d6afb commit e2d0949

File tree

9 files changed

+17
-42
lines changed

9 files changed

+17
-42
lines changed

src/cli/self_update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ fn install_bins(process: &Process) -> Result<()> {
770770
let this_exe_path = utils::current_exe()?;
771771
let rustup_path = bin_path.join(format!("rustup{EXE_SUFFIX}"));
772772

773-
utils::ensure_dir_exists("bin", &bin_path, &|_: Notification<'_>| {})?;
773+
utils::ensure_dir_exists("bin", &bin_path)?;
774774
// NB: Even on Linux we can't just copy the new binary over the (running)
775775
// old binary; we must unlink it first.
776776
if rustup_path.exists() {

src/cli/self_update/unix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub(crate) fn do_add_to_path(process: &Process) -> Result<()> {
9898
rc.display()
9999
)
100100
})?;
101-
utils::ensure_dir_exists("rcfile dir", rc_dir, &|_: Notification<'_>| ())?;
101+
utils::ensure_dir_exists("rcfile dir", rc_dir)?;
102102
utils::append_file("rcfile", &rc, cmd_to_write)
103103
.with_context(|| format!("could not amend shell profile: '{}'", rc.display()))?;
104104
}

src/config.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl<'a> Cfg<'a> {
247247
// Set up the rustup home directory
248248
let rustup_dir = process.rustup_home()?;
249249

250-
utils::ensure_dir_exists("home", &rustup_dir, notify_handler.as_ref())?;
250+
utils::ensure_dir_exists("home", &rustup_dir)?;
251251

252252
let settings_file = SettingsFile::new(rustup_dir.join("settings.toml"));
253253
settings_file.with(|s| {
@@ -411,9 +411,7 @@ impl<'a> Cfg<'a> {
411411
}
412412

413413
pub(crate) fn ensure_toolchains_dir(&self) -> Result<(), anyhow::Error> {
414-
utils::ensure_dir_exists("toolchains", &self.toolchains_dir, &|n| {
415-
(self.notify_handler)(n)
416-
})?;
414+
utils::ensure_dir_exists("toolchains", &self.toolchains_dir)?;
417415
Ok(())
418416
}
419417

@@ -437,11 +435,7 @@ impl<'a> Cfg<'a> {
437435
create_parent: bool,
438436
) -> Result<PathBuf> {
439437
if create_parent {
440-
utils::ensure_dir_exists(
441-
"update-hash",
442-
&self.update_hash_dir,
443-
self.notify_handler.as_ref(),
444-
)?;
438+
utils::ensure_dir_exists("update-hash", &self.update_hash_dir)?;
445439
}
446440

447441
Ok(self.update_hash_dir.join(toolchain.to_string()))

src/dist/component/transaction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl<'a> ChangedItem<'a> {
268268
}))
269269
} else {
270270
if let Some(p) = abs_path.parent() {
271-
utils::ensure_dir_exists("component", p, &|_: Notification<'_>| ())?;
271+
utils::ensure_dir_exists("component", p)?;
272272
}
273273
Ok(abs_path)
274274
}
@@ -354,7 +354,7 @@ impl<'a> ChangedItem<'a> {
354354
Ok(ChangedItem::ModifiedFile(relpath, Some(backup)))
355355
} else {
356356
if let Some(p) = abs_path.parent() {
357-
utils::ensure_dir_exists("component", p, &|_: Notification<'_>| {})?;
357+
utils::ensure_dir_exists("component", p)?;
358358
}
359359
Ok(ChangedItem::ModifiedFile(relpath, None))
360360
}

src/dist/download.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@ impl<'a> DownloadCfg<'a> {
4343
/// target file already exists, then the hash is checked and it is returned
4444
/// immediately without re-downloading.
4545
pub(crate) async fn download(&self, url: &Url, hash: &str) -> Result<File> {
46-
utils::ensure_dir_exists(
47-
"Download Directory",
48-
self.download_dir,
49-
&self.notify_handler,
50-
)?;
46+
utils::ensure_dir_exists("Download Directory", self.download_dir)?;
5147
let target_file = self.download_dir.join(Path::new(hash));
5248

5349
if target_file.exists() {

src/dist/manifestation/tests.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,12 +1471,7 @@ async fn unable_to_download_component() {
14711471
}
14721472

14731473
fn prevent_installation(prefix: &InstallPrefix) {
1474-
utils::ensure_dir_exists(
1475-
"installation path",
1476-
&prefix.path().join("lib"),
1477-
&|_: Notification<'_>| {},
1478-
)
1479-
.unwrap();
1474+
utils::ensure_dir_exists("installation path", &prefix.path().join("lib")).unwrap();
14801475
let install_blocker = prefix.path().join("lib").join("rustlib");
14811476
utils::write_file("install-blocker", &install_blocker, "fail-installation").unwrap();
14821477
}
@@ -1526,7 +1521,7 @@ async fn checks_files_hashes_before_reuse() {
15261521
.unwrap()[..64]
15271522
.to_owned();
15281523
let prev_download = cx.download_dir.join(target_hash);
1529-
utils::ensure_dir_exists("download dir", &cx.download_dir, &|_: Notification<'_>| {}).unwrap();
1524+
utils::ensure_dir_exists("download dir", &cx.download_dir).unwrap();
15301525
utils::write_file("bad previous download", &prev_download, "bad content").unwrap();
15311526
println!("wrote previous download to {}", prev_download.display());
15321527

@@ -1560,7 +1555,7 @@ async fn handle_corrupt_partial_downloads() {
15601555
.unwrap()[..SHA256_HASH_LEN]
15611556
.to_owned();
15621557

1563-
utils::ensure_dir_exists("download dir", &cx.download_dir, &|_: Notification<'_>| {}).unwrap();
1558+
utils::ensure_dir_exists("download dir", &cx.download_dir).unwrap();
15641559
let partial_path = cx.download_dir.join(format!("{target_hash}.partial"));
15651560
utils_raw::write_file(
15661561
&partial_path,

src/dist/temp.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::{fmt, fs, ops};
33

44
pub(crate) use anyhow::{Context as _, Result};
55
use thiserror::Error as ThisError;
6+
use tracing::debug;
67

78
use crate::notifications::Notification;
89
use crate::utils::{self, raw};
@@ -103,7 +104,7 @@ impl Context {
103104
// This is technically racey, but the probability of getting the same
104105
// random names at exactly the same time is... low.
105106
if !raw::path_exists(&temp_dir) {
106-
(self.notify_handler)(Notification::CreatingDirectory("temp", &temp_dir));
107+
debug!(name = "temp", path = %temp_dir.display(), "creating directory");
107108
fs::create_dir(&temp_dir)
108109
.with_context(|| CreatingError::Directory(PathBuf::from(&temp_dir)))?;
109110
return Ok(Dir {

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-
CreatingDirectory(&'a str, &'a Path),
4140
LinkingDirectory(&'a Path, &'a Path),
4241
CopyingDirectory(&'a Path, &'a Path),
4342
RemovingDirectory(&'a str, &'a Path),
@@ -124,8 +123,7 @@ impl Notification<'_> {
124123
NonFatalError(_) => NotificationLevel::Error,
125124
SignatureInvalid(_) => NotificationLevel::Warn,
126125
SetDefaultBufferSize(_) => NotificationLevel::Trace,
127-
CreatingDirectory(_, _)
128-
| RemovingDirectory(_, _)
126+
RemovingDirectory(_, _)
129127
| LinkingDirectory(_, _)
130128
| CopyingDirectory(_, _)
131129
| DownloadingFile(_, _)
@@ -261,9 +259,6 @@ impl Display for Notification<'_> {
261259
}
262260
SignatureInvalid(url) => write!(f, "Signature verification failed for '{url}'"),
263261
RetryingDownload(url) => write!(f, "retrying download for '{url}'"),
264-
CreatingDirectory(name, path) => {
265-
write!(f, "creating {} directory: '{}'", name, path.display())
266-
}
267262
Error(e) => write!(f, "error: '{e}'"),
268263
LinkingDirectory(_, dest) => write!(f, "linking directory from: '{}'", dest.display()),
269264
CopyingDirectory(src, _) => write!(f, "copying directory from: '{}'", src.display()),

src/utils/mod.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::process::ExitStatus;
1111
use anyhow::{Context, Result, anyhow, bail};
1212
use retry::delay::{Fibonacci, jitter};
1313
use retry::{OperationResult, retry};
14+
use tracing::debug;
1415
use url::Url;
1516

1617
use crate::errors::*;
@@ -60,16 +61,9 @@ impl From<ExitStatus> for ExitCode {
6061
}
6162
}
6263

63-
pub fn ensure_dir_exists<'a, N>(
64-
name: &'static str,
65-
path: &'a Path,
66-
notify_handler: &'a dyn Fn(N),
67-
) -> Result<bool>
68-
where
69-
N: From<Notification<'a>>,
70-
{
64+
pub fn ensure_dir_exists(name: &'static str, path: &Path) -> Result<bool> {
7165
raw::ensure_dir_exists(path, |_| {
72-
notify_handler(Notification::CreatingDirectory(name, path).into())
66+
debug!(name, path = %path.display(), "creating directory");
7367
})
7468
.with_context(|| RustupError::CreatingDirectory {
7569
name,

0 commit comments

Comments
 (0)