Skip to content

Commit 4328637

Browse files
committed
notifications: log directly on directory deletions
1 parent fa4a3b1 commit 4328637

File tree

4 files changed

+30
-41
lines changed

4 files changed

+30
-41
lines changed

src/dist/component/package.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ impl Package for DirectoryPackage {
138138

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

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

531-
impl Package for TarPackage<'_> {
531+
impl Package for TarPackage {
532532
fn contains(&self, component: &str, short_name: Option<&str>) -> bool {
533533
self.0.contains(component, short_name)
534534
}
@@ -547,16 +547,16 @@ impl Package for TarPackage<'_> {
547547
}
548548

549549
#[derive(Debug)]
550-
pub(crate) struct TarGzPackage<'a>(TarPackage<'a>);
550+
pub(crate) struct TarGzPackage(TarPackage);
551551

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

559-
impl Package for TarGzPackage<'_> {
559+
impl Package for TarGzPackage {
560560
fn contains(&self, component: &str, short_name: Option<&str>) -> bool {
561561
self.0.contains(component, short_name)
562562
}
@@ -575,16 +575,16 @@ impl Package for TarGzPackage<'_> {
575575
}
576576

577577
#[derive(Debug)]
578-
pub(crate) struct TarXzPackage<'a>(TarPackage<'a>);
578+
pub(crate) struct TarXzPackage(TarPackage);
579579

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

587-
impl Package for TarXzPackage<'_> {
587+
impl Package for TarXzPackage {
588588
fn contains(&self, component: &str, short_name: Option<&str>) -> bool {
589589
self.0.contains(component, short_name)
590590
}
@@ -603,16 +603,16 @@ impl Package for TarXzPackage<'_> {
603603
}
604604

605605
#[derive(Debug)]
606-
pub(crate) struct TarZStdPackage<'a>(TarPackage<'a>);
606+
pub(crate) struct TarZStdPackage(TarPackage);
607607

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

615-
impl Package for TarZStdPackage<'_> {
615+
impl Package for TarZStdPackage {
616616
fn contains(&self, component: &str, short_name: Option<&str>) -> bool {
617617
self.0.contains(component, short_name)
618618
}

src/dist/component/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ enum ChangedItem<'a> {
187187
AddedFile(PathBuf),
188188
AddedDir(PathBuf),
189189
RemovedFile(PathBuf, temp::File<'a>),
190-
RemovedDir(PathBuf, temp::Dir<'a>),
190+
RemovedDir(PathBuf, temp::Dir),
191191
ModifiedFile(PathBuf, Option<temp::File<'a>>),
192192
}
193193

src/dist/temp.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +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;
6+
use tracing::{debug, warn};
77

88
use crate::notifications::Notification;
99
use crate::utils::{self, raw};
@@ -19,27 +19,27 @@ pub(crate) enum CreatingError {
1919
}
2020

2121
#[derive(Debug)]
22-
pub(crate) struct Dir<'a> {
23-
cfg: &'a Context,
22+
pub(crate) struct Dir {
2423
path: PathBuf,
2524
}
2625

27-
impl ops::Deref for Dir<'_> {
26+
impl ops::Deref for Dir {
2827
type Target = Path;
2928

3029
fn deref(&self) -> &Path {
3130
self.path.as_path()
3231
}
3332
}
3433

35-
impl Drop for Dir<'_> {
34+
impl Drop for Dir {
3635
fn drop(&mut self) {
3736
if raw::is_directory(&self.path) {
38-
let n = Notification::DirectoryDeletion(
39-
&self.path,
40-
remove_dir_all::remove_dir_all(&self.path),
41-
);
42-
(self.cfg.notify_handler)(n);
37+
match remove_dir_all::remove_dir_all(&self.path) {
38+
Ok(()) => debug!(path = %self.path.display(), "deleted temp directory"),
39+
Err(e) => {
40+
warn!(path = %self.path.display(), error = %e, "could not delete temp directory")
41+
}
42+
}
4343
}
4444
}
4545
}
@@ -93,7 +93,7 @@ impl Context {
9393
.with_context(|| CreatingError::Root(PathBuf::from(&self.root_directory)))
9494
}
9595

96-
pub(crate) fn new_directory(&self) -> Result<Dir<'_>> {
96+
pub(crate) fn new_directory(&self) -> Result<Dir> {
9797
self.create_root()?;
9898

9999
loop {
@@ -107,10 +107,7 @@ impl Context {
107107
debug!(name = "temp", path = %temp_dir.display(), "creating directory");
108108
fs::create_dir(&temp_dir)
109109
.with_context(|| CreatingError::Directory(PathBuf::from(&temp_dir)))?;
110-
return Ok(Dir {
111-
cfg: self,
112-
path: temp_dir,
113-
});
110+
return Ok(Dir { path: temp_dir });
114111
}
115112
}
116113
}

src/notifications.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pub enum Notification<'a> {
5656
CreatingRoot(&'a Path),
5757
CreatingFile(&'a Path),
5858
FileDeletion(&'a Path, io::Result<()>),
59-
DirectoryDeletion(&'a Path, io::Result<()>),
6059
SetAutoInstall(&'a str),
6160
SetDefaultToolchain(Option<&'a ToolchainName>),
6261
SetOverrideToolchain(&'a Path, &'a str),
@@ -119,7 +118,7 @@ impl Notification<'_> {
119118
| UsingReqwest => NotificationLevel::Debug,
120119
Error(_) => NotificationLevel::Error,
121120
CreatingRoot(_) | CreatingFile(_) => NotificationLevel::Debug,
122-
FileDeletion(_, result) | DirectoryDeletion(_, result) => match result {
121+
FileDeletion(_, result) => match result {
123122
Ok(_) => NotificationLevel::Debug,
124123
Err(_) => NotificationLevel::Warn,
125124
},
@@ -261,13 +260,6 @@ impl Display for Notification<'_> {
261260
write!(f, "could not delete temp file: {}", path.display())
262261
}
263262
}
264-
DirectoryDeletion(path, result) => {
265-
if result.is_ok() {
266-
write!(f, "deleted temp directory: {}", path.display())
267-
} else {
268-
write!(f, "could not delete temp directory: {}", path.display())
269-
}
270-
}
271263
SetAutoInstall(auto) => write!(f, "auto install set to '{auto}'"),
272264
SetDefaultToolchain(None) => write!(f, "default toolchain unset"),
273265
SetDefaultToolchain(Some(name)) => write!(f, "default toolchain set to '{name}'"),

0 commit comments

Comments
 (0)