Skip to content

Commit

Permalink
Merge pull request #1925 from C-Saunders/shell_profile_amend_failure_msg
Browse files Browse the repository at this point in the history
Make error message more specific when the shell profile cannot be updated.
  • Loading branch information
kinnison authored Jul 1, 2019
2 parents eabe5ac + 188c2b1 commit 8fab4b4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/cli/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,11 @@ error_chain! {
)
display("`rustup target add {}` includes `all`", t.join(" "))
}
WritingShellProfile {
path: PathBuf,
} {
description("could not amend shell profile")
display("could not amend shell profile: '{}'", path.display())
}
}
}
6 changes: 5 additions & 1 deletion src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,11 @@ fn do_add_to_path(methods: &[PathUpdateMethod]) -> Result<()> {
};
let addition = format!("\n{}", shell_export_string()?);
if !file.contains(&addition) {
utils::append_file("rcfile", rcpath, &addition)?;
utils::append_file("rcfile", rcpath, &addition).chain_err(|| {
ErrorKind::WritingShellProfile {
path: rcpath.to_path_buf(),
}
})?;
}
} else {
unreachable!()
Expand Down
14 changes: 14 additions & 0 deletions tests/cli-self-upd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,20 @@ fn install_does_not_add_path_to_bash_profile_that_doesnt_exist() {
});
}

#[test]
#[cfg(unix)]
fn install_errors_when_rc_file_cannot_be_updated() {
setup(&|config| {
let rc = config.homedir.join(".bash_profile");
fs::File::create(&rc).unwrap();
let mut perms = fs::metadata(&rc).unwrap().permissions();
perms.set_readonly(true);
fs::set_permissions(&rc, perms).unwrap();

expect_err(config, &["rustup-init", "-y"], "amend shell");
});
}

#[test]
#[cfg(unix)]
fn install_with_zsh_adds_path_to_zprofile() {
Expand Down

0 comments on commit 8fab4b4

Please sign in to comment.