@@ -9,6 +9,8 @@ pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> {
9
9
use crate :: utils:: get_juliaserver_base_url;
10
10
use crate :: { get_juliaup_target, get_own_version} ;
11
11
use anyhow:: { anyhow, bail} ;
12
+ use dialoguer:: { theme:: SimpleTheme , Confirm } ;
13
+ use is_terminal:: IsTerminal ;
12
14
13
15
update_version_db ( paths) . with_context ( || "Failed to update versions db." ) ?;
14
16
@@ -33,7 +35,7 @@ pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> {
33
35
) ,
34
36
} ;
35
37
36
- eprintln ! ( "Checking for self-updates" ) ;
38
+ eprintln ! ( "Checking for self-updates on channel: {}" , juliaup_channel ) ;
37
39
38
40
let version_url = juliaupserver_base. join ( version_url_path) . with_context ( || {
39
41
format ! (
@@ -44,53 +46,57 @@ pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> {
44
46
45
47
let version = download_juliaup_version ( & version_url. to_string ( ) ) ?;
46
48
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
+
47
66
config_file. self_data . last_selfupdate = Some ( chrono:: Utc :: now ( ) ) ;
48
67
49
68
save_config_db ( & mut config_file) . with_context ( || "Failed to save configuration file." ) ?;
50
69
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 ( ) ;
63
71
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." ) ?;
66
74
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) ;
69
76
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
+ } ) ?;
78
85
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." ) ?;
81
88
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." ) ) ?;
85
92
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
+ ) ;
90
97
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) ;
94
100
95
101
Ok ( ( ) )
96
102
}
0 commit comments