From c8e11a8f9817bc780cb5858a946e5845788badd5 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Sun, 5 Jan 2020 00:32:56 +0100 Subject: Fix PATH getting wiped on Windows during install There was no variable expansion called for %PATH% in setx PATH ;%PATH% effectively replacing PATH with litteraly `;%PATH%`. The fix is simple, the command just needs to be called inside a shell with `cmd /C`. --- .../ds-install-wipes-user-path-on-windows.toml | 24 ++++++++++++++++++++++ .../ds-install-wipes-user-path-on-windows.toml | 24 ---------------------- src/main.rs | 7 ++++--- 3 files changed, 28 insertions(+), 27 deletions(-) create mode 100644 .dev-suite/ticket/closed/ds-install-wipes-user-path-on-windows.toml delete mode 100644 .dev-suite/ticket/open/ds-install-wipes-user-path-on-windows.toml diff --git a/.dev-suite/ticket/closed/ds-install-wipes-user-path-on-windows.toml b/.dev-suite/ticket/closed/ds-install-wipes-user-path-on-windows.toml new file mode 100644 index 0000000..eb168e9 --- /dev/null +++ b/.dev-suite/ticket/closed/ds-install-wipes-user-path-on-windows.toml @@ -0,0 +1,24 @@ +title = 'ds install wipes user PATH on Windows' +status = 'Closed' +id = 'a2448280-2f41-11ea-b9b7-55d06c658ffe' +assignees = [] +description = ''' +Currently on Windows, `ds install` calls the following command to add the folder +containing downloaded dev-suite binaries to the PATH: + +``` +setx PATH ;%PATH% +``` + +However this isn't called inside a shell, so variable expansion isn't performed, +and the PATH the user had previously set is lost into oblivion. + +A simple fix is to call this instead: + +``` +cmd /C "setx PATH ;%PATH%" +``` +''' +version = 'V1' + +[comments] diff --git a/.dev-suite/ticket/open/ds-install-wipes-user-path-on-windows.toml b/.dev-suite/ticket/open/ds-install-wipes-user-path-on-windows.toml deleted file mode 100644 index 73876b5..0000000 --- a/.dev-suite/ticket/open/ds-install-wipes-user-path-on-windows.toml +++ /dev/null @@ -1,24 +0,0 @@ -title = 'ds install wipes user PATH on Windows' -status = 'Open' -id = 'a2448280-2f41-11ea-b9b7-55d06c658ffe' -assignees = [] -description = ''' -Currently on Windows, `ds install` calls the following command to add the folder -containing downloaded dev-suite binaries to the PATH: - -``` -setx PATH ;%PATH% -``` - -However this isn't called inside a shell, so variable expansion isn't performed, -and the PATH the user had previously set is lost into oblivion. - -A simple fix is to call this instead: - -``` -cmd /C "setx PATH ;%PATH%" -``` -''' -version = 'V1' - -[comments] diff --git a/src/main.rs b/src/main.rs index a1450dc..8f5557d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -220,9 +220,10 @@ fn install() -> Result<()> { #[cfg(target_os = "windows")] { println!("Adding {} to your %PATH%", location.display()); - let mut location = location.into_os_string(); - location.push(";%PATH%"); - let _ = Command::new("setx").arg("PATH").arg(&location).output()?; + let mut command = std::ffi::OsStr::new("setx PATH ").to_os_string(); + command.push(location.into_os_string()); + command.push(";%PATH%"); + let _ = Command::new("cmd").arg("/C").arg(command).output()?; println!("You'll need to restart your computer for the %PATH% changes to take effect"); } println!("Installation complete"); -- cgit v1.2.3