Skip to content

Commit 42c18db

Browse files
committed
notifications: log directly when path canonicalization fails
1 parent e2d0949 commit 42c18db

File tree

6 files changed

+14
-33
lines changed

6 files changed

+14
-33
lines changed

src/cli/rustup_mode.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,10 +1557,7 @@ fn override_remove(
15571557
};
15581558

15591559
for p in &paths {
1560-
if cfg
1561-
.settings_file
1562-
.with_mut(|s| Ok(s.remove_override(p, cfg.notify_handler.as_ref())))?
1563-
{
1560+
if cfg.settings_file.with_mut(|s| Ok(s.remove_override(p)))? {
15641561
info!("override toolchain for '{}' removed", p.display());
15651562
} else {
15661563
info!("no override toolchain for '{}'", p.display());

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ impl<'a> Cfg<'a> {
576576

577577
while let Some(d) = dir {
578578
// First check the override database
579-
if let Some(name) = settings.dir_override(d, notify) {
579+
if let Some(name) = settings.dir_override(d) {
580580
let reason = ActiveReason::OverrideDB(d.to_owned());
581581
// Note that `rustup override set` fully resolves it's input
582582
// before writing to settings.toml, so resolving here may not

src/notifications.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ pub enum Notification<'a> {
5050
DownloadFinished(Option<&'a str>),
5151
/// Download has failed.
5252
DownloadFailed(&'a str),
53-
NoCanonicalPath(&'a Path),
5453
ResumingPartialDownload,
5554
/// This would make more sense as a crate::notifications::Notification
5655
/// member, but the notification callback is already narrowed to
@@ -135,7 +134,6 @@ impl Notification<'_> {
135134
| UsingCurl
136135
| UsingReqwest => NotificationLevel::Debug,
137136
RenameInUse(_, _) => NotificationLevel::Info,
138-
NoCanonicalPath(_) => NotificationLevel::Warn,
139137
Error(_) => NotificationLevel::Error,
140138
CreatingRoot(_) | CreatingFile(_) => NotificationLevel::Debug,
141139
FileDeletion(_, result) | DirectoryDeletion(_, result) => match result {
@@ -281,7 +279,6 @@ impl Display for Notification<'_> {
281279
DownloadDataReceived(data, _) => write!(f, "received some data of size {}", data.len()),
282280
DownloadFinished(_) => write!(f, "download finished"),
283281
DownloadFailed(_) => write!(f, "download failed"),
284-
NoCanonicalPath(path) => write!(f, "could not canonicalize path: '{}'", path.display()),
285282
ResumingPartialDownload => write!(f, "resuming partial download"),
286283
UsingCurl => write!(f, "downloading with curl"),
287284
UsingReqwest => write!(f, "downloading with reqwest"),

src/settings.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,22 +98,16 @@ pub struct Settings {
9898
}
9999

100100
impl Settings {
101-
fn path_to_key(path: &Path, notify_handler: &dyn Fn(Notification<'_>)) -> String {
101+
fn path_to_key(path: &Path) -> String {
102102
if path.exists() {
103-
utils::canonicalize_path(path, notify_handler)
104-
.display()
105-
.to_string()
103+
utils::canonicalize_path(path).display().to_string()
106104
} else {
107105
path.display().to_string()
108106
}
109107
}
110108

111-
pub(crate) fn remove_override(
112-
&mut self,
113-
path: &Path,
114-
notify_handler: &dyn Fn(Notification<'_>),
115-
) -> bool {
116-
let key = Self::path_to_key(path, notify_handler);
109+
pub(crate) fn remove_override(&mut self, path: &Path) -> bool {
110+
let key = Self::path_to_key(path);
117111
self.overrides.remove(&key).is_some()
118112
}
119113

@@ -123,17 +117,13 @@ impl Settings {
123117
toolchain: String,
124118
notify_handler: &dyn Fn(Notification<'_>),
125119
) {
126-
let key = Self::path_to_key(path, notify_handler);
120+
let key = Self::path_to_key(path);
127121
notify_handler(Notification::SetOverrideToolchain(path, &toolchain));
128122
self.overrides.insert(key, toolchain);
129123
}
130124

131-
pub(crate) fn dir_override(
132-
&self,
133-
dir: &Path,
134-
notify_handler: &dyn Fn(Notification<'_>),
135-
) -> Option<String> {
136-
let key = Self::path_to_key(dir, notify_handler);
125+
pub(crate) fn dir_override(&self, dir: &Path) -> Option<String> {
126+
let key = Self::path_to_key(dir);
137127
self.overrides.get(&key).cloned()
138128
}
139129

src/toolchain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ impl<'a> Toolchain<'a> {
9797
}
9898
ActiveReason::OverrideDB(path) => format!(
9999
"the directory override for '{}' specifies an uninstalled toolchain",
100-
utils::canonicalize_path(path, cfg.notify_handler.as_ref()).display(),
100+
utils::canonicalize_path(path).display(),
101101
),
102102
ActiveReason::ToolchainFile(path) => format!(
103103
"the toolchain file at '{}' specifies an uninstalled toolchain",
104-
utils::canonicalize_path(path, cfg.notify_handler.as_ref()).display(),
104+
utils::canonicalize_path(path).display(),
105105
),
106106
ActiveReason::Default => {
107107
"the default toolchain does not describe an installed toolchain".to_string()

src/utils/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +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;
14+
use tracing::{debug, warn};
1515
use url::Url;
1616

1717
use crate::errors::*;
@@ -127,12 +127,9 @@ pub(crate) fn filter_file<F: FnMut(&str) -> bool>(
127127
})
128128
}
129129

130-
pub(crate) fn canonicalize_path<'a, N>(path: &'a Path, notify_handler: &dyn Fn(N)) -> PathBuf
131-
where
132-
N: From<Notification<'a>>,
133-
{
130+
pub(crate) fn canonicalize_path(path: &Path) -> PathBuf {
134131
fs::canonicalize(path).unwrap_or_else(|_| {
135-
notify_handler(Notification::NoCanonicalPath(path).into());
132+
warn!(path = %path.display(), "could not canonicalize path");
136133
PathBuf::from(path)
137134
})
138135
}

0 commit comments

Comments
 (0)