diff --git a/src/rustup-cli/self_update.rs b/src/rustup-cli/self_update.rs index 0c52720ece..e5b8495350 100644 --- a/src/rustup-cli/self_update.rs +++ b/src/rustup-cli/self_update.rs @@ -1043,6 +1043,14 @@ fn get_add_path_methods() -> Vec { } } + 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); rcfiles.map(PathUpdateMethod::RcFile).collect() } @@ -1168,8 +1176,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()); 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() {