-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathcommand_selfuninstall.rs
132 lines (112 loc) · 4.93 KB
/
command_selfuninstall.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#[cfg(feature = "selfupdate")]
use anyhow::Result;
#[cfg(feature = "selfupdate")]
pub fn run_command_selfuninstall(paths: &crate::global_paths::GlobalPaths) -> Result<()> {
use dialoguer::Confirm;
use crate::{
command_config_backgroundselfupdate::run_command_config_backgroundselfupdate,
command_config_modifypath::run_command_config_modifypath,
command_config_startupselfupdate::run_command_config_startupselfupdate,
command_config_symlinks::run_command_config_symlinks,
};
let choice = Confirm::new()
.with_prompt("Do you really want to uninstall Julia?")
.default(false)
.interact()?;
if !choice {
return Ok(());
}
eprint!("Removing background self update task.");
match run_command_config_backgroundselfupdate(Some(0), true, paths) {
Ok(_) => eprintln!(" Success."),
Err(_) => eprintln!(" Failed."),
};
eprint!("Removing startup self update configuration.");
match run_command_config_startupselfupdate(Some(0), true, &paths) {
Ok(_) => eprintln!(" Success."),
Err(_) => eprintln!(" Failed."),
};
eprint!("Removing PATH modifications in startup scripts.");
match run_command_config_modifypath(Some(false), true, &paths) {
Ok(_) => eprintln!(" Success."),
Err(_) => eprintln!(" Failed."),
};
eprint!("Removing symlinks.");
match run_command_config_symlinks(Some(false), true, &paths) {
Ok(_) => eprintln!(" Success."),
Err(_) => eprintln!(" Failed."),
};
eprint!("Deleting Juliaup home folder {:?}.", paths.juliauphome);
match std::fs::remove_dir_all(&paths.juliauphome) {
Ok(_) => eprintln!(" Success."),
Err(_) => eprintln!(" Failed."),
};
if paths.juliauphome != paths.juliaupselfhome {
let juliaup_binfolder_path = paths.juliaupselfhome.join("bin");
let julia_symlink_path = juliaup_binfolder_path.join("julia");
let julialauncher_path = juliaup_binfolder_path.join("julialauncher");
let juliaup_path = juliaup_binfolder_path.join("juliaup");
let juliaup_config_path = paths.juliaupselfhome.join("juliaupself.json");
eprint!("Deleting julia symlink {:?}.", julia_symlink_path);
match std::fs::remove_file(&julia_symlink_path) {
Ok(_) => eprintln!(" Success."),
Err(_) => eprintln!(" Failed."),
};
eprint!("Deleting julialauncher binary {:?}.", julialauncher_path);
match std::fs::remove_file(&julialauncher_path) {
Ok(_) => eprintln!(" Success."),
Err(_) => eprintln!(" Failed."),
};
eprint!("Deleting juliaup binary {:?}.", juliaup_path);
match std::fs::remove_file(&juliaup_path) {
Ok(_) => eprintln!(" Success."),
Err(_) => eprintln!(" Failed."),
};
if juliaup_binfolder_path.read_dir()?.next().is_none() {
eprint!(
"Deleting the Juliaup bin folder {:?}.",
juliaup_binfolder_path
);
match std::fs::remove_dir(&juliaup_binfolder_path) {
Ok(_) => {
eprintln!(" Success.");
eprint!(
"Deleting the Juliaup configuration file {:?}.",
juliaup_config_path
);
match std::fs::remove_file(&juliaup_config_path) {
Ok(_) => eprintln!(" Success."),
Err(_) => eprintln!(" Failed."),
};
if paths.juliaupselfhome.read_dir()?.next().is_none() {
eprint!("Deleting the Juliaup folder {:?}.", paths.juliaupselfhome);
match std::fs::remove_dir(&paths.juliaupselfhome) {
Ok(_) => eprintln!(" Success."),
Err(_) => {
eprintln!(" Failed, skipping removal of the entire Juliaup folder.")
}
};
} else {
eprintln!("The Juliaup folder {:?} is not empty, skipping removal of the entire Juliaup folder.", paths.juliaupselfhome);
}
}
Err(_) => eprintln!(" Failed, skipping removal of the entire Juliaup folder."),
};
} else {
eprintln!("The Juliaup bin folder {:?} is not empty, skipping removal of the entire Juliaup folder.", juliaup_binfolder_path);
}
}
eprintln!("Successfully removed Juliaup.");
Ok(())
}
#[cfg(not(feature = "selfupdate"))]
use anyhow::Result;
#[cfg(not(feature = "selfupdate"))]
pub fn run_command_selfuninstall_unavailable() -> Result<()> {
eprintln!(
"Self uninstall command is unavailable in this variant of Juliaup.
This software was built with the intention of distributing it
through a package manager other than cargo or upstream."
);
Ok(())
}