Skip to content

Commit 354710a

Browse files
committed
dist: move Notification into dist::download
1 parent 38d1852 commit 354710a

File tree

9 files changed

+31
-37
lines changed

9 files changed

+31
-37
lines changed

src/cli/rustup_mode.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ use crate::{
3333
command, component_for_bin,
3434
config::{ActiveReason, Cfg},
3535
dist::{
36-
AutoInstallMode, PartialToolchainDesc, Profile, TargetTriple, download::DownloadCfg, manifest::{Component, ComponentStatus}
36+
AutoInstallMode, PartialToolchainDesc, Profile, TargetTriple,
37+
download::DownloadCfg,
38+
manifest::{Component, ComponentStatus},
3739
},
3840
errors::RustupError,
3941
install::{InstallMethod, UpdateStatus},

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/component/package.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,7 @@ fn unpack_without_first_dir<R: Read>(
300300
}
301301
};
302302
let unpack_ram = unpack_ram(IO_CHUNK_SIZE, effective_max_ram, cx);
303-
let mut io_executor: Box<dyn Executor> =
304-
get_executor(cx.notifier, unpack_ram, cx.process)?;
303+
let mut io_executor: Box<dyn Executor> = get_executor(cx.notifier, unpack_ram, cx.process)?;
305304

306305
let mut directories: HashMap<PathBuf, DirStatus> = HashMap::new();
307306
// Path is presumed to exist. Call it a precondition.

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: 4 additions & 10 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;
@@ -454,10 +453,7 @@ pub(crate) struct FileReaderWithProgress<'a> {
454453
}
455454

456455
impl<'a> FileReaderWithProgress<'a> {
457-
pub(crate) fn new_file(
458-
path: &Path,
459-
notifier: &'a Notifier,
460-
) -> Result<Self> {
456+
pub(crate) fn new_file(path: &Path, notifier: &'a Notifier) -> Result<Self> {
461457
let fh = match File::open(path) {
462458
Ok(fh) => fh,
463459
Err(_) => {
@@ -489,10 +485,8 @@ impl io::Read for FileReaderWithProgress<'_> {
489485
Ok(nbytes) => {
490486
self.nbytes += nbytes as u64;
491487
if nbytes != 0 {
492-
self.notifier.handle(Notification::DownloadDataReceived(
493-
&buf[0..nbytes],
494-
None,
495-
));
488+
self.notifier
489+
.handle(Notification::DownloadDataReceived(&buf[0..nbytes], None));
496490
}
497491
if (nbytes == 0) || (self.flen == self.nbytes) {
498492
self.notifier.handle(Notification::DownloadFinished(None));

0 commit comments

Comments
 (0)