Skip to content

Commit 552ade9

Browse files
committed
dist: move Notification into dist::download
1 parent 9702194 commit 552ade9

File tree

7 files changed

+24
-26
lines changed

7 files changed

+24
-26
lines changed

src/diskio/threaded.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use sharded_slab::pool::{OwnedRef, OwnedRefMut};
1515
use tracing::debug;
1616

1717
use super::{CompletedIo, Executor, Item, perform};
18-
use crate::dist::download::Notifier;
19-
use crate::notifications::Notification;
18+
use crate::dist::download::{Notification, Notifier};
2019

2120
#[derive(Copy, Clone, Debug, Enum)]
2221
pub(crate) enum Bucket {

src/dist/download.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate::config::Cfg;
1515
use crate::dist::temp;
1616
use crate::download::{download_file, download_file_with_resume};
1717
use crate::errors::*;
18-
use crate::notifications::Notification;
1918
use crate::process::Process;
2019
use crate::utils;
2120

@@ -339,9 +338,25 @@ impl DownloadTracker {
339338
}
340339
}
341340

342-
fn file_hash(path: &Path, notify_handler: &Notifier) -> Result<String> {
341+
#[derive(Debug)]
342+
pub(crate) enum Notification<'a> {
343+
/// The URL of the download is passed as the last argument, to allow us to track concurrent downloads.
344+
DownloadingComponent(&'a str, &'a str),
345+
RetryingDownload(&'a str),
346+
/// Received the Content-Length of the to-be downloaded data with
347+
/// the respective URL of the download (for tracking concurrent downloads).
348+
DownloadContentLengthReceived(u64, Option<&'a str>),
349+
/// Received some data.
350+
DownloadDataReceived(&'a [u8], Option<&'a str>),
351+
/// Download has finished.
352+
DownloadFinished(Option<&'a str>),
353+
/// Download has failed.
354+
DownloadFailed(&'a str),
355+
}
356+
357+
fn file_hash(path: &Path, notifier: &Notifier) -> Result<String> {
343358
let mut hasher = Sha256::new();
344-
let mut downloaded = utils::FileReaderWithProgress::new_file(path, notify_handler)?;
359+
let mut downloaded = utils::FileReaderWithProgress::new_file(path, notifier)?;
345360
use std::io::Read;
346361
let mut buf = vec![0; 32768];
347362
while let Ok(n) = downloaded.read(&mut buf) {

src/dist/manifestation.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ use crate::dist::component::{
1717
Components, Package, PackageContext, TarGzPackage, TarXzPackage, TarZStdPackage, Transaction,
1818
};
1919
use crate::dist::config::Config;
20-
use crate::dist::download::{DownloadCfg, File};
20+
use crate::dist::download::{DownloadCfg, File, Notification};
2121
use crate::dist::manifest::{Component, CompressionKind, HashedBinary, Manifest, TargetedPackage};
2222
use crate::dist::prefix::InstallPrefix;
2323
#[cfg(test)]
2424
use crate::dist::temp;
2525
use crate::dist::{DEFAULT_DIST_SERVER, Profile, TargetTriple};
2626
use crate::errors::RustupError;
27-
use crate::notifications::Notification;
2827
use crate::process::Process;
2928
use crate::utils;
3029

src/download/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ use tracing::warn;
2727
use url::Url;
2828

2929
use crate::{
30-
dist::download::Notifier, errors::RustupError, notifications::Notification, process::Process,
30+
dist::download::{Notification, Notifier},
31+
errors::RustupError,
32+
process::Process,
3133
};
3234

3335
#[cfg(test)]

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ pub mod env_var;
7979
pub mod errors;
8080
mod fallback_settings;
8181
mod install;
82-
pub mod notifications;
8382
pub mod process;
8483
mod settings;
8584
#[cfg(feature = "test")]

src/notifications.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/utils/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ use retry::{OperationResult, retry};
1414
use tracing::{debug, info, warn};
1515
use url::Url;
1616

17-
use crate::dist::download::Notifier;
17+
use crate::dist::download::{Notification, Notifier};
1818
use crate::errors::*;
1919
use crate::process::Process;
2020

21-
use crate::notifications::Notification;
2221
#[cfg(not(windows))]
2322
pub(crate) use crate::utils::raw::find_cmd;
2423
pub(crate) use crate::utils::raw::is_directory;

0 commit comments

Comments
 (0)