Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/rustup-cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,14 @@ fn get_add_path_methods() -> Vec<PathUpdateMethod> {
}
}

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()
}
Expand Down Expand Up @@ -1168,8 +1176,9 @@ fn get_remove_path_methods() -> Result<Vec<PathUpdateMethod>> {
}

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());
Expand Down
25 changes: 24 additions & 1 deletion tests/cli-self-upd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down