Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
dbdc567
chore: avoid trailing whitespace in error message
djc Oct 1, 2025
41bebe2
notifications: log directly when using download backends
djc Sep 24, 2025
3be758c
notifications: log directly for valid checksums
djc Sep 24, 2025
7f28035
notifications: log directly when component is already installed
djc Sep 24, 2025
1c75418
notifications: log directly when failing to update hash file
djc Sep 24, 2025
f4497dc
notifications: log directly when hash file not found
djc Sep 24, 2025
16bd807
notifications: log directly after failing to determine memory limit
djc Sep 24, 2025
736226d
notifications: log directly on missing components
djc Sep 24, 2025
111c503
notifications: log directly when installing components
djc Sep 24, 2025
19ce863
notifications: log directly when removing components
djc Sep 24, 2025
682e55e
notifications: log directly for manifest downloads
djc Sep 24, 2025
8262c18
notifications: log directly for downloaded manifests
djc Sep 24, 2025
fd6b456
notifications: log directly when downloading legacy manifests
djc Sep 24, 2025
893594b
notifications: log directly on missing components
djc Sep 24, 2025
2749700
notifications: log directly when skipping components
djc Sep 24, 2025
011d923
notifications: log directly when removing stray hash files
djc Sep 24, 2025
caf8be9
notifications: log directly when downloading files
djc Sep 24, 2025
6ad046e
notifications: log directly when resuming partial downloads
djc Sep 24, 2025
9826ece
notifications: log directly when setting auto install mode
djc Sep 24, 2025
054e3c6
notifications: log directly when setting the default toolchain
djc Sep 24, 2025
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
11 changes: 8 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use anyhow::{Context, Result, anyhow, bail};
use serde::Deserialize;
use thiserror::Error as ThisError;
use tokio_stream::StreamExt;
use tracing::{error, trace};
use tracing::{error, info, trace};

use crate::dist::AutoInstallMode;
use crate::{
Expand Down Expand Up @@ -344,7 +344,12 @@ impl<'a> Cfg<'a> {
s.default_toolchain = toolchain.map(|t| t.to_string());
Ok(())
})?;
(self.notify_handler)(Notification::SetDefaultToolchain(toolchain));

match toolchain {
Some(t) => info!("default toolchain set to {t}"),
None => info!("default toolchain unset"),
}

Ok(())
}

Expand Down Expand Up @@ -376,7 +381,7 @@ impl<'a> Cfg<'a> {
s.auto_install = Some(mode);
Ok(())
})?;
(self.notify_handler)(Notification::SetAutoInstall(mode.as_str()));
info!("setting auto install mode to {}", mode.as_str());
Ok(())
}

Expand Down
8 changes: 3 additions & 5 deletions src/dist/component/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::path::{Path, PathBuf};

use anyhow::{Context, Result, anyhow, bail};
use tar::EntryType;
use tracing::warn;
use tracing::{error, warn};

use crate::diskio::{CompletedIo, Executor, FileBuffer, IO_CHUNK_SIZE, Item, Kind, get_executor};
use crate::dist::component::components::*;
Expand Down Expand Up @@ -290,10 +290,8 @@ fn unpack_without_first_dir<R: Read>(
let entries = archive.entries()?;
let effective_max_ram = match effective_limits::memory_limit() {
Ok(ram) => Some(ram as usize),
Err(e) => {
if let Some(h) = cx.notify_handler {
h(Notification::Error(e.to_string()))
}
Err(error) => {
error!("can't determine memory limit: {error}");
None
}
};
Expand Down
16 changes: 10 additions & 6 deletions src/dist/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::path::{Path, PathBuf};

use anyhow::{Context, Result, anyhow};
use sha2::{Digest, Sha256};
use tracing::debug;
use tracing::warn;
use url::Url;

use crate::dist::temp;
Expand Down Expand Up @@ -50,7 +52,7 @@ impl<'a> DownloadCfg<'a> {
let cached_result = file_hash(&target_file, self.notify_handler)?;
if hash == cached_result {
(self.notify_handler)(Notification::FileAlreadyDownloaded);
(self.notify_handler)(Notification::ChecksumValid(url.as_ref()));
debug!(url = url.as_ref(), "checksum passed");
return Ok(File { path: target_file });
} else {
(self.notify_handler)(Notification::CachedFileChecksumFailed);
Expand Down Expand Up @@ -105,8 +107,7 @@ impl<'a> DownloadCfg<'a> {
.into())
}
} else {
(self.notify_handler)(Notification::ChecksumValid(url.as_ref()));

debug!(url = url.as_ref(), "checksum passed");
utils::rename("downloaded", &partial_file_path, &target_file, self.process)?;
Ok(File { path: target_file })
}
Expand Down Expand Up @@ -160,10 +161,13 @@ impl<'a> DownloadCfg<'a> {
return Ok(None);
}
} else {
(self.notify_handler)(Notification::CantReadUpdateHash(hash_file));
warn!(
"can't read update hash {}, can't skip update",
hash_file.display()
);
}
} else {
(self.notify_handler)(Notification::NoUpdateHash(hash_file));
debug!(file = %hash_file.display(), "no update hash file found");
}
}

Expand All @@ -190,7 +194,7 @@ impl<'a> DownloadCfg<'a> {
}
.into());
} else {
(self.notify_handler)(Notification::ChecksumValid(url_str));
debug!(url = url_str, "checksum passed");
}

Ok(Some((file, partial_hash)))
Expand Down
116 changes: 67 additions & 49 deletions src/dist/manifestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use anyhow::{Context, Result, anyhow, bail};
use futures_util::stream::StreamExt;
use std::sync::Arc;
use tokio::sync::Semaphore;
use tracing::info;
use tracing::{info, warn};
use url::Url;

use crate::dist::component::{
Expand Down Expand Up @@ -122,13 +122,7 @@ impl Manifestation {

// Create the lists of components needed for installation
let config = self.read_config()?;
let mut update = Update::build_update(
self,
new_manifest,
&changes,
&config,
&download_cfg.notify_handler,
)?;
let mut update = Update::build_update(self, new_manifest, &changes, &config)?;

if update.nothing_changes() {
return Ok(UpdateStatus::Unchanged);
Expand All @@ -143,9 +137,17 @@ impl Manifestation {
e.downcast::<RustupError>()
{
for component in &components {
(download_cfg.notify_handler)(Notification::ForcingUnavailableComponent(
&component.name(new_manifest),
));
match &component.target {
Some(t) if t != &self.target_triple => warn!(
"skipping unavailable component {} for target {}",
component.short_name(new_manifest),
t
),
_ => warn!(
"skipping unavailable component {}",
component.short_name(new_manifest)
),
}
}
update.drop_components_to_install(&components);
}
Expand Down Expand Up @@ -224,24 +226,33 @@ impl Manifestation {

// Uninstall components
for component in &update.components_to_uninstall {
let notification = if implicit_modify {
Notification::RemovingOldComponent
} else {
Notification::RemovingComponent
};
(download_cfg.notify_handler)(notification(
&component.short_name(new_manifest),
&self.target_triple,
component.target.as_ref(),
));
match (implicit_modify, &component.target) {
(true, Some(t)) if t != &self.target_triple => {
info!(
"removing previous version of component {} for target {}",
component.short_name(new_manifest),
t
);
}
(false, Some(t)) if t != &self.target_triple => {
info!(
"removing component {} for target {}",
component.short_name(new_manifest),
t
);
}
(true, _) => {
info!(
"removing previous version of component {}",
component.short_name(new_manifest),
);
}
(false, _) => {
info!("removing component {}", component.short_name(new_manifest));
}
}

tx = self.uninstall_component(
component,
new_manifest,
tx,
&download_cfg.notify_handler,
download_cfg.process,
)?;
tx = self.uninstall_component(component, new_manifest, tx, download_cfg.process)?;
}

// Install components
Expand All @@ -254,11 +265,17 @@ impl Manifestation {
let short_pkg_name = component.short_name_in_manifest();
let short_name = component.short_name(new_manifest);

(download_cfg.notify_handler)(Notification::InstallingComponent(
&short_name,
&self.target_triple,
component.target.as_ref(),
));
match &component.target {
Some(t) if t != &self.target_triple => {
info!("installing component {short_name}");
}
_ => {
info!(
"installing component {short_name} for target {}",
self.target_triple
)
}
}

let cx = PackageContext {
tmp_cx,
Expand Down Expand Up @@ -319,7 +336,6 @@ impl Manifestation {
&self,
manifest: &Manifest,
tmp_cx: &temp::Context,
notify_handler: &dyn Fn(Notification<'_>),
process: &Process,
) -> Result<()> {
let prefix = self.installation.prefix();
Expand All @@ -337,7 +353,7 @@ impl Manifestation {
tx.remove_file("dist config", rel_config_path)?;

for component in config.components {
tx = self.uninstall_component(&component, manifest, tx, notify_handler, process)?;
tx = self.uninstall_component(&component, manifest, tx, process)?;
}
tx.commit();

Expand All @@ -349,7 +365,6 @@ impl Manifestation {
component: &Component,
manifest: &Manifest,
mut tx: Transaction<'a>,
notify_handler: &dyn Fn(Notification<'_>),
process: &Process,
) -> Result<Transaction<'a>> {
// For historical reasons, the rust-installer component
Expand All @@ -363,9 +378,10 @@ impl Manifestation {
} else if let Some(c) = self.installation.find(short_name)? {
tx = c.uninstall(tx, process)?;
} else {
notify_handler(Notification::MissingInstalledComponent(
&component.short_name(manifest),
));
warn!(
"component {} not found during uninstall",
component.short_name(manifest),
);
}

Ok(tx)
Expand Down Expand Up @@ -463,12 +479,7 @@ impl Manifestation {
let (installer_file, installer_hash) = dl.unwrap();

let prefix = self.installation.prefix();

notify_handler(Notification::InstallingComponent(
"rust",
&self.target_triple,
Some(&self.target_triple),
));
info!("installing component rust");

// Begin transaction
let mut tx = Transaction::new(prefix, tmp_cx, process);
Expand Down Expand Up @@ -539,7 +550,6 @@ impl Update {
new_manifest: &Manifest,
changes: &Changes,
config: &Option<Config>,
notify_handler: &dyn Fn(Notification<'_>),
) -> Result<Self> {
// The package to install.
let rust_package = new_manifest.get_package("rust")?;
Expand Down Expand Up @@ -601,9 +611,17 @@ impl Update {
if !starting_list.contains(component) {
result.components_to_install.push(component.clone());
} else if changes.explicit_add_components.contains(component) {
notify_handler(Notification::ComponentAlreadyInstalled(
&component.description(new_manifest),
));
match &component.target {
Some(t) if t != &manifestation.target_triple => info!(
"component {} for target {} is up to date",
component.short_name(new_manifest),
t,
),
_ => info!(
"component {} is up to date",
component.short_name(new_manifest)
),
}
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/dist/manifestation/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ impl TestContext {
let manifestation = Manifestation::open(self.prefix.clone(), trip)?;
let manifest = manifestation.load_manifest()?.unwrap();

manifestation.uninstall(&manifest, &self.tmp_cx, &|_| (), &self.tp.process)?;
manifestation.uninstall(&manifest, &self.tmp_cx, &self.tp.process)?;

Ok(())
}
Expand Down
37 changes: 23 additions & 14 deletions src/dist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ use itertools::Itertools;
use regex::Regex;
use serde::{Deserialize, Serialize};
use thiserror::Error as ThisError;
use tracing::{info, warn};
use tracing::{debug, info, warn};

use crate::{
config::{Cfg, dist_root_server},
errors::RustupError,
notifications::Notification,
process::Process,
toolchain::ToolchainName,
utils,
Expand Down Expand Up @@ -912,7 +911,10 @@ pub(crate) async fn update_from_dist(
if let Some(hash) = opts.update_hash {
// fresh_install means the toolchain isn't present, but hash_exists means there is a stray hash file
if fresh_install && Path::exists(hash) {
(opts.dl_cfg.notify_handler)(Notification::StrayHash(hash));
warn!(
"removing stray hash file in order to continue: {}",
hash.display()
);
std::fs::remove_file(hash)?;
}
}
Expand Down Expand Up @@ -990,11 +992,18 @@ pub(crate) async fn update_from_dist(
let cause = e.downcast_ref::<DistError>();
match cause {
Some(DistError::ToolchainComponentsMissing(components, manifest, ..)) => {
(opts.dl_cfg.notify_handler)(Notification::SkippingNightlyMissingComponent(
&toolchain,
current_manifest.as_ref().unwrap_or(manifest),
components,
));
let plural = if components.len() > 1 { "s" } else { "" };
let manifest = current_manifest.as_ref().unwrap_or(manifest);
let components = components
.iter()
.map(
|component| match component.target.as_ref() == Some(&toolchain.target) {
true => component.short_name(manifest),
false => component.name(manifest),
},
)
.join(", ");
info!("skipping nightly with missing component{plural}: {components}");

if first_err.is_none() {
first_err = Some(e);
Expand Down Expand Up @@ -1072,7 +1081,7 @@ async fn try_update_from_dist_(
let manifestation = Manifestation::open(prefix.clone(), toolchain.target.clone())?;

// TODO: Add a notification about which manifest version is going to be used
(download.notify_handler)(Notification::DownloadingManifest(&toolchain_str));
info!("syncing channel updates for {toolchain_str}");
match dl_v2_manifest(
download,
// Even if manifest has not changed, we must continue to install requested components.
Expand All @@ -1088,10 +1097,10 @@ async fn try_update_from_dist_(
.await
{
Ok(Some((m, hash))) => {
(download.notify_handler)(Notification::DownloadedManifest(
&m.date,
m.get_rust_version().ok(),
));
match m.get_rust_version() {
Ok(version) => info!("latest update on {} for version {version}", m.date),
Err(_) => info!("latest update on {}", m.date),
}

let profile_components = match profile {
Some(profile) => m.get_profile_components(profile, &toolchain.target)?,
Expand Down Expand Up @@ -1173,7 +1182,7 @@ async fn try_update_from_dist_(
Some(RustupError::ChecksumFailed { .. }) => return Ok(None),
Some(RustupError::DownloadNotExists { .. }) => {
// Proceed to try v1 as a fallback
(download.notify_handler)(Notification::DownloadingLegacyManifest)
debug!("manifest not found; trying legacy manifest");
}
_ => return Err(err),
}
Expand Down
Loading