Skip to content

Commit 70c5be5

Browse files
committed
fix: changes to asking the user for input on downgrade to allow switching back from a preview version to the release version.
1 parent 25df396 commit 70c5be5

File tree

1 file changed

+43
-37
lines changed

1 file changed

+43
-37
lines changed

src/command_selfupdate.rs

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> {
99
use crate::utils::get_juliaserver_base_url;
1010
use crate::{get_juliaup_target, get_own_version};
1111
use anyhow::{anyhow, bail};
12+
use dialoguer::{theme::SimpleTheme, Confirm};
13+
use is_terminal::IsTerminal;
1214

1315
update_version_db(paths).with_context(|| "Failed to update versions db.")?;
1416

@@ -33,7 +35,7 @@ pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> {
3335
),
3436
};
3537

36-
eprintln!("Checking for self-updates");
38+
eprintln!("Checking for self-updates on channel: {}", juliaup_channel);
3739

3840
let version_url = juliaupserver_base.join(version_url_path).with_context(|| {
3941
format!(
@@ -44,53 +46,57 @@ pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> {
4446

4547
let version = download_juliaup_version(&version_url.to_string())?;
4648

49+
// TODO: how to deal with automatic background updates?
50+
if version <= get_own_version().unwrap() && std::io::stdin().is_terminal() {
51+
eprintln!(
52+
"You are trying to install version: {}-{}, but the currently installed version is newer (or the same)",
53+
juliaup_channel, version
54+
);
55+
56+
match Confirm::with_theme(&SimpleTheme)
57+
.with_prompt("Do you want to continue?")
58+
.default(false)
59+
.interact()?
60+
{
61+
true => {}
62+
false => return Ok(()),
63+
}
64+
}
65+
4766
config_file.self_data.last_selfupdate = Some(chrono::Utc::now());
4867

4968
save_config_db(&mut config_file).with_context(|| "Failed to save configuration file.")?;
5069

51-
if version == get_own_version().unwrap() {
52-
eprintln!(
53-
"Juliaup unchanged on channel '{}' - {}",
54-
juliaup_channel, version
55-
);
56-
} else if version < get_own_version().unwrap() {
57-
eprintln!(
58-
"Local Juliaup version is newer on channel '{}' - {}",
59-
juliaup_channel, version
60-
);
61-
} else {
62-
let juliaup_target = get_juliaup_target();
70+
let juliaup_target = get_juliaup_target();
6371

64-
let juliaupserver_base =
65-
get_juliaserver_base_url().with_context(|| "Failed to get Juliaup server base URL.")?;
72+
let juliaupserver_base =
73+
get_juliaserver_base_url().with_context(|| "Failed to get Juliaup server base URL.")?;
6674

67-
let download_url_path =
68-
format!("juliaup/bin/juliaup-{}-{}.tar.gz", version, juliaup_target);
75+
let download_url_path = format!("juliaup/bin/juliaup-{}-{}.tar.gz", version, juliaup_target);
6976

70-
let new_juliaup_url = juliaupserver_base
71-
.join(&download_url_path)
72-
.with_context(|| {
73-
format!(
74-
"Failed to construct a valid url from '{}' and '{}'.",
75-
juliaupserver_base, download_url_path
76-
)
77-
})?;
77+
let new_juliaup_url = juliaupserver_base
78+
.join(&download_url_path)
79+
.with_context(|| {
80+
format!(
81+
"Failed to construct a valid url from '{}' and '{}'.",
82+
juliaupserver_base, download_url_path
83+
)
84+
})?;
7885

79-
let my_own_path = std::env::current_exe()
80-
.with_context(|| "Could not determine the path of the running exe.")?;
86+
let my_own_path = std::env::current_exe()
87+
.with_context(|| "Could not determine the path of the running exe.")?;
8188

82-
let my_own_folder = my_own_path
83-
.parent()
84-
.ok_or_else(|| anyhow!("Could not determine parent."))?;
89+
let my_own_folder = my_own_path
90+
.parent()
91+
.ok_or_else(|| anyhow!("Could not determine parent."))?;
8592

86-
eprintln!(
87-
"Found new version {} on channel {}.",
88-
version, juliaup_channel
89-
);
93+
eprintln!(
94+
"Found new version {} on channel {}.",
95+
version, juliaup_channel
96+
);
9097

91-
download_extract_sans_parent(&new_juliaup_url.to_string(), &my_own_folder, 0)?;
92-
eprintln!("Updated Juliaup to version {}.", version);
93-
}
98+
download_extract_sans_parent(&new_juliaup_url.to_string(), &my_own_folder, 0)?;
99+
eprintln!("Updated Juliaup to version {}.", version);
94100

95101
Ok(())
96102
}

0 commit comments

Comments
 (0)