Skip to content

Commit aa49fbc

Browse files
committed
Only check for direct download versions when necessary
1 parent aa227de commit aa49fbc

6 files changed

+33
-16
lines changed

src/bin/juliaup.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn main() -> Result<()> {
9595
Juliaup::Add { channel } => run_command_add(&channel, &paths),
9696
Juliaup::Remove { channel } => run_command_remove(&channel, &paths),
9797
Juliaup::Status {} => run_command_status(&paths),
98-
Juliaup::Update { channel } => run_command_update(channel, &paths),
98+
Juliaup::Update { channel } => run_command_update(&channel, &paths),
9999
Juliaup::Gc { prune_linked } => run_command_gc(prune_linked, &paths),
100100
Juliaup::Link {
101101
channel,

src/command_add.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ pub fn run_command_add(channel: &str, paths: &GlobalPaths) -> Result<()> {
1818
return add_non_db(channel, paths);
1919
}
2020

21-
update_version_db(paths).with_context(|| "Failed to update versions db.")?;
21+
update_version_db(&Some(channel.to_string()), paths)
22+
.with_context(|| "Failed to update versions db.")?;
2223
let version_db =
2324
load_versions_db(paths).with_context(|| "`add` command failed to load versions db.")?;
2425

src/command_selfupdate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> {
1010
use crate::{get_juliaup_target, get_own_version};
1111
use anyhow::{anyhow, bail};
1212

13-
update_version_db(paths).with_context(|| "Failed to update versions db.")?;
13+
update_version_db(&None, paths).with_context(|| "Failed to update versions db.")?;
1414

1515
let mut config_file = load_mut_config_db(paths)
1616
.with_context(|| "`selfupdate` command failed to load configuration db.")?;
@@ -97,7 +97,7 @@ pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> {
9797
Win32::{System::Console::GetConsoleWindow, UI::Shell::IInitializeWithWindow},
9898
};
9999

100-
update_version_db(paths).with_context(|| "Failed to update versions db.")?;
100+
update_version_db(&None, paths).with_context(|| "Failed to update versions db.")?;
101101

102102
let update_manager = windows::Services::Store::StoreContext::GetDefault()
103103
.with_context(|| "Failed to get the store context.")?;
@@ -146,6 +146,6 @@ pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> {
146146

147147
#[cfg(not(any(feature = "windowsstore", feature = "selfupdate")))]
148148
pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> {
149-
update_version_db(paths).with_context(|| "Failed to update versions db.")?;
149+
update_version_db(&None, paths).with_context(|| "Failed to update versions db.")?;
150150
Ok(())
151151
}

src/command_update.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ fn update_channel(
120120
Ok(())
121121
}
122122

123-
pub fn run_command_update(channel: Option<String>, paths: &GlobalPaths) -> Result<()> {
124-
update_version_db(paths).with_context(|| "Failed to update versions db.")?;
123+
pub fn run_command_update(channel: &Option<String>, paths: &GlobalPaths) -> Result<()> {
124+
update_version_db(channel, paths).with_context(|| "Failed to update versions db.")?;
125125

126126
let version_db =
127127
load_versions_db(paths).with_context(|| "`update` command failed to load versions db.")?;
@@ -136,7 +136,7 @@ pub fn run_command_update(channel: Option<String>, paths: &GlobalPaths) -> Resul
136136
}
137137
}
138138
Some(channel) => {
139-
if !config_file.data.installed_channels.contains_key(&channel) {
139+
if !config_file.data.installed_channels.contains_key(channel) {
140140
bail!(
141141
"'{}' cannot be updated because it is currently not installed.",
142142
channel

src/command_update_version_db.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{global_paths::GlobalPaths, operations::update_version_db};
22
use anyhow::{Context, Result};
33

44
pub fn run_command_update_version_db(paths: &GlobalPaths) -> Result<()> {
5-
update_version_db(paths).with_context(|| "Failed to update version db.")?;
5+
update_version_db(&None, paths).with_context(|| "Failed to update version db.")?;
66

77
Ok(())
88
}

src/operations.rs

+23-7
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ mod tests {
14131413
}
14141414
}
14151415

1416-
pub fn update_version_db(paths: &GlobalPaths) -> Result<()> {
1416+
pub fn update_version_db(channel: &Option<String>, paths: &GlobalPaths) -> Result<()> {
14171417
eprintln!(
14181418
"{} for new Julia versions",
14191419
style("Checking").green().bold()
@@ -1462,7 +1462,7 @@ pub fn update_version_db(paths: &GlobalPaths) -> Result<()> {
14621462
None => "release".to_string(),
14631463
};
14641464

1465-
// TODO Figure out how we can learn about the correctn Juliaup channel here
1465+
// TODO Figure out how we can learn about the correct Juliaup channel here
14661466
#[cfg(not(feature = "selfupdate"))]
14671467
let juliaup_channel = "release".to_string();
14681468

@@ -1522,7 +1522,7 @@ pub fn update_version_db(paths: &GlobalPaths) -> Result<()> {
15221522
delete_old_version_db = true;
15231523
}
15241524

1525-
let direct_download_etags = download_direct_download_etags(&old_config_file.data)?;
1525+
let direct_download_etags = download_direct_download_etags(&channel, &old_config_file.data)?;
15261526

15271527
let mut new_config_file = load_mut_config_db(paths).with_context(|| {
15281528
"`run_command_update_version_db` command failed to load configuration db."
@@ -1624,6 +1624,7 @@ where
16241624

16251625
#[cfg(windows)]
16261626
fn download_direct_download_etags(
1627+
channel: &Option<String>,
16271628
config_data: &JuliaupConfig,
16281629
) -> Result<Vec<(String, Option<String>)>> {
16291630
use windows::core::HSTRING;
@@ -1636,8 +1637,15 @@ fn download_direct_download_etags(
16361637

16371638
let mut requests = Vec::new();
16381639

1639-
for (channel_name, channel) in &config_data.installed_channels {
1640-
if let JuliaupConfigChannel::DirectDownloadChannel { url, .. } = channel {
1640+
for (channel_name, installed_channel) in &config_data.installed_channels {
1641+
if let Some(chan) = channel{
1642+
// TODO: convert to an if-let chain once stabilized https://github.com/rust-lang/rust/pull/132833
1643+
if chan != channel_name {
1644+
continue;
1645+
}
1646+
}
1647+
1648+
if let JuliaupConfigChannel::DirectDownloadChannel { url, .. } = installed_channel {
16411649
let http_client = http_client.clone();
16421650
let url_clone = url.clone();
16431651
let channel_name_clone = channel_name.clone();
@@ -1691,6 +1699,7 @@ fn download_direct_download_etags(
16911699

16921700
#[cfg(not(windows))]
16931701
fn download_direct_download_etags(
1702+
channel: &Option<String>,
16941703
config_data: &JuliaupConfig,
16951704
) -> Result<Vec<(String, Option<String>)>> {
16961705
use std::sync::Arc;
@@ -1699,8 +1708,15 @@ fn download_direct_download_etags(
16991708

17001709
let mut requests = Vec::new();
17011710

1702-
for (channel_name, channel) in &config_data.installed_channels {
1703-
if let JuliaupConfigChannel::DirectDownloadChannel { url, .. } = channel {
1711+
for (channel_name, installed_channel) in &config_data.installed_channels {
1712+
if let Some(chan) = channel{
1713+
// TODO: convert to an if-let chain once stabilized https://github.com/rust-lang/rust/pull/132833
1714+
if chan != channel_name {
1715+
continue;
1716+
}
1717+
}
1718+
1719+
if let JuliaupConfigChannel::DirectDownloadChannel { url, .. } = installed_channel {
17041720
let client = Arc::clone(&client);
17051721
let url_clone = url.clone();
17061722
let channel_name_clone = channel_name.clone();

0 commit comments

Comments
 (0)