Skip to content

Commit a1b2ace

Browse files
committed
notifications: log directly on creating temp files
1 parent 473381a commit a1b2ace

File tree

5 files changed

+5
-29
lines changed

5 files changed

+5
-29
lines changed

src/config.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,7 @@ impl<'a> Cfg<'a> {
290290
};
291291

292292
let dist_root_server = dist_root_server(process)?;
293-
294-
let notify_clone = notify_handler.clone();
295-
let tmp_cx = temp::Context::new(
296-
rustup_dir.join("tmp"),
297-
dist_root_server.as_str(),
298-
Box::new(move |n| (notify_clone)(n)),
299-
);
293+
let tmp_cx = temp::Context::new(rustup_dir.join("tmp"), dist_root_server.as_str());
300294
let dist_root = dist_root_server + "/dist";
301295

302296
let cfg = Self {

src/dist/manifestation/tests.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,7 @@ impl TestContext {
454454
let prefix_tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
455455

456456
let work_tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
457-
let tmp_cx = temp::Context::new(
458-
work_tempdir.path().to_owned(),
459-
DEFAULT_DIST_SERVER,
460-
Box::new(|_| ()),
461-
);
457+
let tmp_cx = temp::Context::new(work_tempdir.path().to_owned(), DEFAULT_DIST_SERVER);
462458

463459
let toolchain = ToolchainDesc::from_str("nightly-x86_64-apple-darwin").unwrap();
464460
let prefix = InstallPrefix::from(prefix_tempdir.path());

src/dist/temp.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ pub(crate) use anyhow::{Context as _, Result};
55
use thiserror::Error as ThisError;
66
use tracing::{debug, warn};
77

8-
use crate::notifications::Notification;
98
use crate::utils::{self, raw};
109

1110
#[derive(Debug, ThisError)]
@@ -73,19 +72,13 @@ impl Drop for File {
7372
pub struct Context {
7473
root_directory: PathBuf,
7574
pub dist_server: String,
76-
notify_handler: Box<dyn Fn(Notification<'_>)>,
7775
}
7876

7977
impl Context {
80-
pub fn new(
81-
root_directory: PathBuf,
82-
dist_server: &str,
83-
notify_handler: Box<dyn Fn(Notification<'_>)>,
84-
) -> Self {
78+
pub fn new(root_directory: PathBuf, dist_server: &str) -> Self {
8579
Self {
8680
root_directory,
8781
dist_server: dist_server.to_owned(),
88-
notify_handler,
8982
}
9083
}
9184

@@ -130,7 +123,7 @@ impl Context {
130123
// This is technically racey, but the probability of getting the same
131124
// random names at exactly the same time is... low.
132125
if !raw::path_exists(&temp_file) {
133-
(self.notify_handler)(Notification::CreatingFile(&temp_file));
126+
debug!(path = %temp_file.display(), "creating temp file");
134127
fs::File::create(&temp_file)
135128
.with_context(|| CreatingError::File(PathBuf::from(&temp_file)))?;
136129
return Ok(File { path: temp_file });

src/notifications.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ pub enum Notification<'a> {
5252
Error(String),
5353
UsingCurl,
5454
UsingReqwest,
55-
CreatingFile(&'a Path),
5655
SetAutoInstall(&'a str),
5756
SetDefaultToolchain(Option<&'a ToolchainName>),
5857
SetOverrideToolchain(&'a Path, &'a str),
@@ -114,7 +113,6 @@ impl Notification<'_> {
114113
| UsingCurl
115114
| UsingReqwest => NotificationLevel::Debug,
116115
Error(_) => NotificationLevel::Error,
117-
CreatingFile(_) => NotificationLevel::Debug,
118116
ToolchainDirectory(_)
119117
| LookingForToolchain(_)
120118
| InstallingToolchain(_)
@@ -244,7 +242,6 @@ impl Display for Notification<'_> {
244242
ResumingPartialDownload => write!(f, "resuming partial download"),
245243
UsingCurl => write!(f, "downloading with curl"),
246244
UsingReqwest => write!(f, "downloading with reqwest"),
247-
CreatingFile(path) => write!(f, "creating temp file: {}", path.display()),
248245
SetAutoInstall(auto) => write!(f, "auto install set to '{auto}'"),
249246
SetDefaultToolchain(None) => write!(f, "default toolchain unset"),
250247
SetDefaultToolchain(Some(name)) => write!(f, "default toolchain set to '{name}'"),

src/test/dist.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ impl DistContext {
4848
pkg_dir,
4949
inst_dir,
5050
prefix,
51-
cx: temp::Context::new(
52-
tmp_dir.path().to_owned(),
53-
DEFAULT_DIST_SERVER,
54-
Box::new(|_| ()),
55-
),
51+
cx: temp::Context::new(tmp_dir.path().to_owned(), DEFAULT_DIST_SERVER),
5652
tp: TestProcess::default(),
5753
_tmp_dir: tmp_dir,
5854
})

0 commit comments

Comments
 (0)