Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use tracing_subscriber::{EnvFilter, Registry, reload::Handle};
use crate::{
cli::download_tracker::DownloadTracker,
config::Cfg,
dist::{TargetTriple, ToolchainDesc, notifications as dist_notifications},
dist::{TargetTriple, ToolchainDesc},
errors::RustupError,
install::UpdateStatus,
notifications::Notification,
Expand Down Expand Up @@ -139,10 +139,7 @@ impl Notifier {
return;
}

if let Notification::Install(dist_notifications::Notification::Utils(
util_notifications::Notification::SetDefaultBufferSize(_),
)) = &n
{
if let Notification::Utils(util_notifications::Notification::SetDefaultBufferSize(_)) = &n {
if *self.ram_notice_shown.borrow() {
return;
} else {
Expand Down
16 changes: 6 additions & 10 deletions src/cli/download_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle};
use std::collections::HashMap;
use std::time::{Duration, Instant};

use crate::dist::Notification as In;
use crate::notifications::Notification;
use crate::process::Process;
use crate::utils::Notification as Un;
Expand Down Expand Up @@ -40,36 +39,33 @@ impl DownloadTracker {

pub(crate) fn handle_notification(&mut self, n: &Notification<'_>) -> bool {
match *n {
Notification::Install(In::Utils(Un::DownloadContentLengthReceived(
content_len,
url,
))) => {
Notification::Utils(Un::DownloadContentLengthReceived(content_len, url)) => {
if let Some(url) = url {
self.content_length_received(content_len, url);
}
true
}
Notification::Install(In::Utils(Un::DownloadDataReceived(data, url))) => {
Notification::Utils(Un::DownloadDataReceived(data, url)) => {
if let Some(url) = url {
self.data_received(data.len(), url);
}
true
}
Notification::Install(In::Utils(Un::DownloadFinished(url))) => {
Notification::Utils(Un::DownloadFinished(url)) => {
if let Some(url) = url {
self.download_finished(url);
}
true
}
Notification::Install(In::Utils(Un::DownloadFailed(url))) => {
Notification::Utils(Un::DownloadFailed(url)) => {
self.download_failed(url);
false
}
Notification::Install(In::DownloadingComponent(component, _, _, url)) => {
Notification::DownloadingComponent(component, _, _, url) => {
self.create_progress_bar(component.to_owned(), url.to_owned());
true
}
Notification::Install(In::RetryingDownload(url)) => {
Notification::RetryingDownload(url) => {
self.retrying_download(url);
true
}
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl<'a> Cfg<'a> {
/// construct a download configuration
pub(crate) fn download_cfg(
&'a self,
notify_handler: &'a dyn Fn(crate::dist::Notification<'_>),
notify_handler: &'a dyn Fn(Notification<'_>),
) -> DownloadCfg<'a> {
DownloadCfg {
dist_root: &self.dist_root_url,
Expand Down
76 changes: 25 additions & 51 deletions src/dist/component/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::io::Write;
use std::path::PathBuf;

use crate::dist::DEFAULT_DIST_SERVER;
use crate::dist::Notification;
use crate::dist::component::Transaction;
use crate::dist::prefix::InstallPrefix;
use crate::dist::temp;
Expand All @@ -24,9 +23,8 @@ fn add_file() {
Box::new(|_| ()),
);

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

let mut file = tx.add_file("c", PathBuf::from("foo/bar")).unwrap();
write!(file, "test").unwrap();
Expand All @@ -53,9 +51,8 @@ fn add_file_then_rollback() {
Box::new(|_| ()),
);

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

tx.add_file("c", PathBuf::from("foo/bar")).unwrap();
drop(tx);
Expand All @@ -76,9 +73,8 @@ fn add_file_that_exists() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

fs::create_dir_all(prefixdir.path().join("foo")).unwrap();
utils::write_file("", &prefixdir.path().join("foo/bar"), "").unwrap();
Expand Down Expand Up @@ -108,9 +104,8 @@ fn copy_file() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

let srcpath = srcdir.path().join("bar");
utils::write_file("", &srcpath, "").unwrap();
Expand All @@ -136,9 +131,8 @@ fn copy_file_then_rollback() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

let srcpath = srcdir.path().join("bar");
utils::write_file("", &srcpath, "").unwrap();
Expand All @@ -164,9 +158,8 @@ fn copy_file_that_exists() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

let srcpath = srcdir.path().join("bar");
utils::write_file("", &srcpath, "").unwrap();
Expand Down Expand Up @@ -201,9 +194,8 @@ fn copy_dir() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

let srcpath1 = srcdir.path().join("foo");
let srcpath2 = srcdir.path().join("bar/baz");
Expand Down Expand Up @@ -236,9 +228,8 @@ fn copy_dir_then_rollback() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

let srcpath1 = srcdir.path().join("foo");
let srcpath2 = srcdir.path().join("bar/baz");
Expand Down Expand Up @@ -271,9 +262,8 @@ fn copy_dir_that_exists() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

fs::create_dir_all(prefix.path().join("a")).unwrap();

Expand Down Expand Up @@ -303,9 +293,8 @@ fn remove_file() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

let filepath = prefixdir.path().join("foo");
utils::write_file("", &filepath, "").unwrap();
Expand All @@ -329,9 +318,8 @@ fn remove_file_then_rollback() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

let filepath = prefixdir.path().join("foo");
utils::write_file("", &filepath, "").unwrap();
Expand All @@ -355,9 +343,8 @@ fn remove_file_that_not_exists() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

let err = tx.remove_file("c", PathBuf::from("foo")).unwrap_err();

Expand All @@ -383,9 +370,8 @@ fn remove_dir() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

let filepath = prefixdir.path().join("foo/bar");
fs::create_dir_all(filepath.parent().unwrap()).unwrap();
Expand All @@ -410,9 +396,8 @@ fn remove_dir_then_rollback() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

let filepath = prefixdir.path().join("foo/bar");
fs::create_dir_all(filepath.parent().unwrap()).unwrap();
Expand All @@ -437,9 +422,8 @@ fn remove_dir_that_not_exists() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

let err = tx.remove_dir("c", PathBuf::from("foo")).unwrap_err();

Expand All @@ -465,9 +449,8 @@ fn write_file() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

let content = "hi".to_string();
tx.write_file("c", PathBuf::from("foo/bar"), content.clone())
Expand All @@ -493,9 +476,8 @@ fn write_file_then_rollback() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

let content = "hi".to_string();
tx.write_file("c", PathBuf::from("foo/bar"), content)
Expand All @@ -518,9 +500,8 @@ fn write_file_that_exists() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

let content = "hi".to_string();
utils_raw::write_file(&prefix.path().join("a"), &content).unwrap();
Expand Down Expand Up @@ -550,9 +531,8 @@ fn modify_file_that_not_exists() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

tx.modify_file(PathBuf::from("foo/bar")).unwrap();
tx.commit();
Expand All @@ -575,9 +555,8 @@ fn modify_file_that_exists() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

let path = prefix.path().join("foo");
utils_raw::write_file(&path, "wow").unwrap();
Expand All @@ -600,9 +579,8 @@ fn modify_file_that_not_exists_then_rollback() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

tx.modify_file(PathBuf::from("foo/bar")).unwrap();
drop(tx);
Expand All @@ -623,9 +601,8 @@ fn modify_file_that_exists_then_rollback() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

let path = prefix.path().join("foo");
utils_raw::write_file(&path, "wow").unwrap();
Expand All @@ -651,9 +628,8 @@ fn modify_twice_then_rollback() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

let path = prefix.path().join("foo");
utils_raw::write_file(&path, "wow").unwrap();
Expand All @@ -679,9 +655,8 @@ fn do_multiple_op_transaction(rollback: bool) {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

// copy_file
let relpath1 = PathBuf::from("bin/rustc");
Expand Down Expand Up @@ -781,9 +756,8 @@ fn rollback_failure_keeps_going() {

let prefix = InstallPrefix::from(prefixdir.path());

let notify = |_: Notification<'_>| ();
let tp = TestProcess::default();
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &notify, &tp.process);
let mut tx = Transaction::new(prefix.clone(), &tmp_cx, &|_| (), &tp.process);

write!(tx.add_file("", PathBuf::from("foo")).unwrap(), "").unwrap();
write!(tx.add_file("", PathBuf::from("bar")).unwrap(), "").unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/dist/component/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use std::path::{Path, PathBuf};

use anyhow::{Context, Result, anyhow};

use crate::dist::notifications::*;
use crate::dist::prefix::InstallPrefix;
use crate::dist::temp;
use crate::errors::*;
use crate::notifications::Notification;
use crate::process::Process;
use crate::utils;

Expand Down
2 changes: 1 addition & 1 deletion src/dist/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use anyhow::{Context, Result, anyhow};
use sha2::{Digest, Sha256};
use url::Url;

use crate::dist::notifications::*;
use crate::dist::temp;
use crate::download::download_file;
use crate::download::download_file_with_resume;
use crate::errors::*;
use crate::notifications::Notification;
use crate::process::Process;
use crate::utils;

Expand Down
Loading