|
1 | 1 | use std::fmt::{self, Display};
|
| 2 | +use std::io; |
2 | 3 | use std::path::{Path, PathBuf};
|
3 | 4 |
|
4 | 5 | use crate::settings::MetadataVersion;
|
5 |
| -use crate::{ |
6 |
| - dist::{ToolchainDesc, temp}, |
7 |
| - toolchain::ToolchainName, |
8 |
| - utils::notify::NotificationLevel, |
9 |
| -}; |
| 6 | +use crate::{dist::ToolchainDesc, toolchain::ToolchainName, utils::notify::NotificationLevel}; |
10 | 7 |
|
11 | 8 | #[derive(Debug)]
|
12 |
| -pub(crate) enum Notification<'a> { |
| 9 | +pub enum Notification<'a> { |
13 | 10 | Install(crate::dist::Notification<'a>),
|
14 | 11 | Utils(crate::utils::Notification<'a>),
|
15 |
| - Temp(temp::Notification<'a>), |
16 |
| - |
| 12 | + CreatingRoot(&'a Path), |
| 13 | + CreatingFile(&'a Path), |
| 14 | + CreatingDirectory(&'a Path), |
| 15 | + FileDeletion(&'a Path, io::Result<()>), |
| 16 | + DirectoryDeletion(&'a Path, io::Result<()>), |
17 | 17 | SetAutoInstall(&'a str),
|
18 | 18 | SetDefaultToolchain(Option<&'a ToolchainName>),
|
19 | 19 | SetOverrideToolchain(&'a Path, &'a str),
|
@@ -50,19 +50,21 @@ impl<'a> From<crate::utils::Notification<'a>> for Notification<'a> {
|
50 | 50 | Notification::Utils(n)
|
51 | 51 | }
|
52 | 52 | }
|
53 |
| -impl<'a> From<temp::Notification<'a>> for Notification<'a> { |
54 |
| - fn from(n: temp::Notification<'a>) -> Self { |
55 |
| - Notification::Temp(n) |
56 |
| - } |
57 |
| -} |
58 | 53 |
|
59 | 54 | impl Notification<'_> {
|
60 | 55 | pub(crate) fn level(&self) -> NotificationLevel {
|
61 | 56 | use self::Notification::*;
|
62 | 57 | match self {
|
63 | 58 | Install(n) => n.level(),
|
64 | 59 | Utils(n) => n.level(),
|
65 |
| - Temp(n) => n.level(), |
| 60 | + CreatingRoot(_) | CreatingFile(_) | CreatingDirectory(_) => NotificationLevel::Debug, |
| 61 | + FileDeletion(_, result) | DirectoryDeletion(_, result) => { |
| 62 | + if result.is_ok() { |
| 63 | + NotificationLevel::Debug |
| 64 | + } else { |
| 65 | + NotificationLevel::Warn |
| 66 | + } |
| 67 | + } |
66 | 68 | ToolchainDirectory(_)
|
67 | 69 | | LookingForToolchain(_)
|
68 | 70 | | InstallingToolchain(_)
|
@@ -92,7 +94,23 @@ impl Display for Notification<'_> {
|
92 | 94 | match self {
|
93 | 95 | Install(n) => n.fmt(f),
|
94 | 96 | Utils(n) => n.fmt(f),
|
95 |
| - Temp(n) => n.fmt(f), |
| 97 | + CreatingRoot(path) => write!(f, "creating temp root: {}", path.display()), |
| 98 | + CreatingFile(path) => write!(f, "creating temp file: {}", path.display()), |
| 99 | + CreatingDirectory(path) => write!(f, "creating temp directory: {}", path.display()), |
| 100 | + FileDeletion(path, result) => { |
| 101 | + if result.is_ok() { |
| 102 | + write!(f, "deleted temp file: {}", path.display()) |
| 103 | + } else { |
| 104 | + write!(f, "could not delete temp file: {}", path.display()) |
| 105 | + } |
| 106 | + } |
| 107 | + DirectoryDeletion(path, result) => { |
| 108 | + if result.is_ok() { |
| 109 | + write!(f, "deleted temp directory: {}", path.display()) |
| 110 | + } else { |
| 111 | + write!(f, "could not delete temp directory: {}", path.display()) |
| 112 | + } |
| 113 | + } |
96 | 114 | SetAutoInstall(auto) => write!(f, "auto install set to '{auto}'"),
|
97 | 115 | SetDefaultToolchain(None) => write!(f, "default toolchain unset"),
|
98 | 116 | SetDefaultToolchain(Some(name)) => write!(f, "default toolchain set to '{name}'"),
|
|
0 commit comments