From 744db3e7c1195947cc489ec163c53c075beddf62 Mon Sep 17 00:00:00 2001 From: Allen Welkie Date: Tue, 2 May 2017 23:37:29 -0400 Subject: [PATCH 1/3] Edit .bash_profile if it exists --- src/rustup-cli/self_update.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/rustup-cli/self_update.rs b/src/rustup-cli/self_update.rs index 0c52720ece..b9092cb16b 100644 --- a/src/rustup-cli/self_update.rs +++ b/src/rustup-cli/self_update.rs @@ -1041,6 +1041,16 @@ fn get_add_path_methods() -> Vec { let zprofile = zdotdir.map(|p| p.join(".zprofile")); profiles.push(zprofile); } + + if shell.contains("bash") { + if let Some(bash_profile) = utils::home_dir().map(|p| p.join(".bash_profile")) { + // Only update .bash_profile if it exists because creating .bash_profile + // will cause .profile to not be read + if bash_profile.exists() { + profiles.push(Some(bash_profile)); + } + } + } } let rcfiles = profiles.into_iter().filter_map(|f|f); From a947d668074fb42929a59a8a365a889253de81ed Mon Sep 17 00:00:00 2001 From: Allen Welkie Date: Tue, 2 May 2017 23:37:29 -0400 Subject: [PATCH 2/3] Remove path modification from .bash_profile --- src/rustup-cli/self_update.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rustup-cli/self_update.rs b/src/rustup-cli/self_update.rs index b9092cb16b..174b45dc3c 100644 --- a/src/rustup-cli/self_update.rs +++ b/src/rustup-cli/self_update.rs @@ -1178,8 +1178,9 @@ fn get_remove_path_methods() -> Result> { } let profile = utils::home_dir().map(|p| p.join(".profile")); + let bash_profile = utils::home_dir().map(|p| p.join(".bash_profile")); - let rcfiles = vec![profile]; + let rcfiles = vec![profile, bash_profile]; let existing_rcfiles = rcfiles.into_iter() .filter_map(|f|f) .filter(|f| f.exists()); From 579399f7be586892c9163a3eedf2f976818761ad Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 24 Jun 2017 02:37:48 +0000 Subject: [PATCH 3/3] Don't check SHELL for bash before writing .bash_profile. Add tests --- src/rustup-cli/self_update.rs | 14 ++++++-------- tests/cli-self-upd.rs | 25 ++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/rustup-cli/self_update.rs b/src/rustup-cli/self_update.rs index 174b45dc3c..e5b8495350 100644 --- a/src/rustup-cli/self_update.rs +++ b/src/rustup-cli/self_update.rs @@ -1041,15 +1041,13 @@ fn get_add_path_methods() -> Vec { let zprofile = zdotdir.map(|p| p.join(".zprofile")); profiles.push(zprofile); } + } - if shell.contains("bash") { - if let Some(bash_profile) = utils::home_dir().map(|p| p.join(".bash_profile")) { - // Only update .bash_profile if it exists because creating .bash_profile - // will cause .profile to not be read - if bash_profile.exists() { - profiles.push(Some(bash_profile)); - } - } + if let Some(bash_profile) = utils::home_dir().map(|p| p.join(".bash_profile")) { + // Only update .bash_profile if it exists because creating .bash_profile + // will cause .profile to not be read + if bash_profile.exists() { + profiles.push(Some(bash_profile)); } } diff --git a/tests/cli-self-upd.rs b/tests/cli-self-upd.rs index 854e2fdaa7..b572eb3969 100644 --- a/tests/cli-self-upd.rs +++ b/tests/cli-self-upd.rs @@ -323,6 +323,23 @@ fn install_adds_path_to_profile() { install_adds_path_to_rc(".profile"); } +#[test] +#[cfg(unix)] +fn install_adds_path_to_bash_profile() { + install_adds_path_to_rc(".bash_profile"); +} + +#[test] +#[cfg(unix)] +fn install_does_not_add_path_to_bash_profile_that_doesnt_exist() { + setup(&|config| { + let ref rc = config.homedir.join(".bash_profile"); + expect_ok(config, &["rustup-init", "-y"]); + + assert!(!rc.exists()); + }); +} + #[test] #[cfg(unix)] fn install_with_zsh_adds_path_to_zprofile() { @@ -399,10 +416,16 @@ fn uninstall_removes_path_from_rc(rcfile: &str) { #[test] #[cfg(unix)] -fn uninstall_removes_path_from_bashrc() { +fn uninstall_removes_path_from_profile() { uninstall_removes_path_from_rc(".profile"); } +#[test] +#[cfg(unix)] +fn uninstall_removes_path_from_bash_profile() { + uninstall_removes_path_from_rc(".bash_profile"); +} + #[test] #[cfg(unix)] fn uninstall_doesnt_touch_rc_files_that_dont_contain_cargo_home() {