Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#[macro_use]
pub mod log;
pub mod common;
mod download_tracker;
pub mod errors;
mod help;
mod job;
Expand Down
60 changes: 4 additions & 56 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
//! Just a dumping ground for cli stuff

use std::cell::RefCell;
use std::fmt::Display;
use std::fs;
use std::io::{BufRead, Write};
use std::path::{Path, PathBuf};
use std::sync::{Arc, LazyLock, Mutex};
use std::sync::LazyLock;
use std::{cmp, env};

use anyhow::{Context, Result, anyhow};
use git_testament::{git_testament, render_testament};
use termcolor::Color;
use tracing::{debug, error, info, trace, warn};
use tracing::{error, info, warn};
use tracing_subscriber::{EnvFilter, Registry, reload::Handle};

use crate::{
cli::download_tracker::DownloadTracker,
config::Cfg,
dist::{TargetTriple, ToolchainDesc},
errors::RustupError,
install::UpdateStatus,
notifications::Notification,
process::{Attr, Process},
toolchain::{LocalToolchainName, Toolchain, ToolchainName},
utils::{self, notify::NotificationLevel},
utils,
};

pub(crate) const WARN_COMPLETE_PROFILE: &str = "downloading with complete profile isn't recommended unless you are a developer of the rust language";
Expand Down Expand Up @@ -122,58 +119,9 @@ pub(crate) fn read_line(process: &Process) -> Result<String> {
.context("unable to read from stdin for confirmation")
}

pub(super) struct Notifier {
tracker: Mutex<DownloadTracker>,
ram_notice_shown: RefCell<bool>,
}

impl Notifier {
pub(super) fn new(quiet: bool, process: &Process) -> Self {
Self {
tracker: Mutex::new(DownloadTracker::new_with_display_progress(!quiet, process)),
ram_notice_shown: RefCell::new(false),
}
}

pub(super) fn handle(&self, n: Notification<'_>) {
if self.tracker.lock().unwrap().handle_notification(&n) {
return;
}

if let Notification::SetDefaultBufferSize(_) = &n {
if *self.ram_notice_shown.borrow() {
return;
} else {
*self.ram_notice_shown.borrow_mut() = true;
}
};
let level = n.level();
for n in format!("{n}").lines() {
match level {
NotificationLevel::Debug => {
debug!("{}", n);
}
NotificationLevel::Info => {
info!("{}", n);
}
NotificationLevel::Warn => {
warn!("{}", n);
}
NotificationLevel::Error => {
error!("{}", n);
}
NotificationLevel::Trace => {
trace!("{}", n);
}
}
}
}
}

#[tracing::instrument(level = "trace", skip(process))]
pub(crate) fn set_globals(current_dir: PathBuf, quiet: bool, process: &Process) -> Result<Cfg<'_>> {
let notifier = Notifier::new(quiet, process);
Cfg::from_env(current_dir, Arc::new(move |n| notifier.handle(n)), process)
Cfg::from_env(current_dir, quiet, process)
}

pub(crate) fn show_channel_update(
Expand Down
149 changes: 0 additions & 149 deletions src/cli/download_tracker.rs

This file was deleted.

12 changes: 8 additions & 4 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use crate::{
config::{ActiveReason, Cfg},
dist::{
AutoInstallMode, PartialToolchainDesc, Profile, TargetTriple,
download::DownloadCfg,
manifest::{Component, ComponentStatus},
},
errors::RustupError,
Expand Down Expand Up @@ -909,7 +910,7 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<utils::ExitCode
&& self_update_mode == SelfUpdateMode::Enable
&& !opts.no_self_update;

if self_update && check_rustup_update(cfg.process).await? {
if self_update && check_rustup_update(&DownloadCfg::new(cfg)).await? {
update_available = true;
}

Expand Down Expand Up @@ -937,10 +938,13 @@ async fn update(
if let Some(p) = opts.profile {
cfg.set_profile_override(p);
}

let cfg = &cfg;
if cfg.get_profile()? == Profile::Complete {
warn!("{}", common::WARN_COMPLETE_PROFILE);
}

let dl_cfg = DownloadCfg::new(cfg);
let names = opts.toolchain;
if !names.is_empty() {
for name in names {
Expand Down Expand Up @@ -994,7 +998,7 @@ async fn update(
}
}
if self_update {
exit_code &= self_update::self_update(cfg.process).await?;
exit_code &= self_update::self_update(&dl_cfg).await?;
}
} else if ensure_active_toolchain {
let (toolchain, reason) = cfg.ensure_active_toolchain(force_non_host, true).await?;
Expand All @@ -1003,7 +1007,7 @@ async fn update(
} else {
exit_code &= common::update_all_channels(cfg, opts.force).await?;
if self_update {
exit_code &= self_update::self_update(cfg.process).await?;
exit_code &= self_update::self_update(&dl_cfg).await?;
}

info!("cleaning up downloads & tmp directories");
Expand All @@ -1012,7 +1016,7 @@ async fn update(
}

if !cfg!(feature = "no-self-update") && self_update_mode == SelfUpdateMode::CheckOnly {
check_rustup_update(cfg.process).await?;
check_rustup_update(&dl_cfg).await?;
}

if cfg!(feature = "no-self-update") {
Expand Down
Loading
Loading