Skip to content

Commit 3363086

Browse files
committed
Enhance according to review
1 parent c493f76 commit 3363086

File tree

3 files changed

+20
-34
lines changed

3 files changed

+20
-34
lines changed

src/cli/self_update.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ pub fn install(
344344

345345
if !opts.no_modify_path {
346346
do_add_to_path()?;
347-
#[cfg(windows)]
348347
do_add_to_programs()?;
349348
}
350349
utils::create_rustup_home()?;
@@ -856,7 +855,6 @@ pub fn uninstall(no_prompt: bool) -> Result<utils::ExitCode> {
856855

857856
// Remove CARGO_HOME/bin from PATH
858857
do_remove_from_path()?;
859-
#[cfg(windows)]
860858
do_remove_from_programs()?;
861859

862860
// Delete everything in CARGO_HOME *except* the rustup bin

src/cli/self_update/unix.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ pub fn do_write_env_files() -> Result<()> {
114114
Ok(())
115115
}
116116

117+
pub fn do_add_to_programs() -> Result<()> {
118+
Ok(())
119+
}
120+
121+
pub fn do_remove_from_programs() -> Result<()> {
122+
Ok(())
123+
}
124+
117125
/// Tell the upgrader to replace the rustup bins, then delete
118126
/// itself. Like with uninstallation, on Windows we're going to
119127
/// have to jump through hoops to make everything work right.

src/cli/self_update/windows.rs

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,17 @@ pub fn do_remove_from_path() -> Result<()> {
282282
_apply_new_path(new_path)
283283
}
284284

285+
const RUSTUP_UNINSTALL_ENTRY: &str = r"Software\Microsoft\Windows\CurrentVersion\Uninstall\Rustup";
286+
285287
pub fn do_add_to_programs() -> Result<()> {
286288
use std::path::PathBuf;
287289

288290
let key = RegKey::predef(HKEY_CURRENT_USER)
289-
.create_subkey(r"Software\Microsoft\Windows\CurrentVersion\Uninstall\rustup")
291+
.create_subkey(RUSTUP_UNINSTALL_ENTRY)
290292
.chain_err(|| ErrorKind::PermissionDenied)?
291293
.0;
292294

293-
// Don't overwrite registry if rustup is already installed
295+
// Don't overwrite registry if Rustup is already installed
294296
let prev = key
295297
.get_raw_value("UninstallString")
296298
.map(|val| from_winreg_value(&val));
@@ -304,8 +306,9 @@ pub fn do_add_to_programs() -> Result<()> {
304306

305307
let mut path = utils::cargo_home()?;
306308
path.push("bin\rustup.exe");
307-
let mut uninstall_cmd = path.into_os_string();
308-
uninstall_cmd.push(" self uninstall");
309+
let mut uninstall_cmd = OsString::from("\"");
310+
uninstall_cmd.push(path);
311+
uninstall_cmd.push("\" self uninstall");
309312

310313
let reg_value = RegValue {
311314
bytes: to_winreg_bytes(uninstall_cmd.encode_wide().collect()),
@@ -314,41 +317,18 @@ pub fn do_add_to_programs() -> Result<()> {
314317

315318
key.set_raw_value("UninstallString", &reg_value)
316319
.chain_err(|| ErrorKind::PermissionDenied)?;
317-
key.set_value("DisplayName", &"rustup - Rust toolchain manager")
320+
key.set_value("DisplayName", &"Rustup: the Rust toolchain installer")
318321
.chain_err(|| ErrorKind::PermissionDenied)?;
319322

320323
Ok(())
321324
}
322325

323326
pub fn do_remove_from_programs() -> Result<()> {
324-
use std::io;
325-
use std::path::PathBuf;
326-
327-
let root = RegKey::predef(HKEY_CURRENT_USER);
328-
329-
let key = match root.open_subkey(r"Software\Microsoft\Windows\CurrentVersion\Uninstall\rustup")
330-
{
331-
Ok(key) => key,
332-
Err(ref e) if e.kind() == io::ErrorKind::NotFound => return Ok(()),
333-
Err(e) => return Err(e).chain_err(|| ErrorKind::PermissionDenied),
334-
};
335-
336-
// Don't remove uninstall information from another installation
337-
let cur = key
338-
.get_raw_value("UninstallString")
339-
.map(|val| from_winreg_value(&val));
340-
if let Ok(Some(s)) = cur {
341-
let mut reg_path = PathBuf::from(OsString::from_wide(&s));
342-
reg_path.pop();
343-
let mut path = utils::cargo_home()?;
344-
path.push("bin");
345-
if reg_path != path {
346-
return Ok(());
347-
}
327+
match RegKey::predef(HKEY_CURRENT_USER).delete_subkey_all(RUSTUP_UNINSTALL_ENTRY) {
328+
Ok(()) => Ok(()),
329+
Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => Ok(()),
330+
Err(e) => Err(e).chain_err(|| ErrorKind::PermissionDenied),
348331
}
349-
350-
root.delete_subkey_all(r"Software\Microsoft\Windows\CurrentVersion\Uninstall\rustup")
351-
.chain_err(|| ErrorKind::PermissionDenied)
352332
}
353333

354334
/// Convert a vector UCS-2 chars to a null-terminated UCS-2 string in bytes

0 commit comments

Comments
 (0)