Skip to content

Commit f329c9c

Browse files
authored
Merge pull request #2589 from kinnison/ensure-env-file
Ensure env file exists
2 parents cc9ce76 + d33c53f commit f329c9c

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

src/cli/self_update.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ pub fn install(
338338

339339
let install_res: Result<utils::ExitCode> = (|| {
340340
install_bins()?;
341+
do_write_env_files()?;
341342
if !opts.no_modify_path {
342343
do_add_to_path()?;
343344
}

src/cli/self_update/env.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ case ":${PATH}:" in
55
*:"{cargo_bin}":*)
66
;;
77
*)
8-
# Prepending path in case a system-installed rustc must be overwritten
8+
# Prepending path in case a system-installed rustc needs to be overridden
99
export PATH="{cargo_bin}:$PATH"
1010
;;
1111
esac

src/cli/self_update/unix.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ pub fn do_remove_from_path() -> Result<()> {
8181
}
8282

8383
pub fn do_add_to_path() -> Result<()> {
84-
let mut written = vec![];
85-
8684
for sh in shell::get_available_shells() {
8785
let source_cmd = sh.source_string()?;
8886
for rc in sh.update_rcs() {
@@ -92,13 +90,6 @@ pub fn do_add_to_path() -> Result<()> {
9290
path: rc.to_path_buf(),
9391
}
9492
})?;
95-
let script = sh.env_script();
96-
// Only write scripts once.
97-
// TODO 2021: remove this code if Rustup adds 0 shell scripts.
98-
if !written.contains(&script) {
99-
script.write()?;
100-
written.push(script);
101-
}
10293
}
10394
}
10495
}
@@ -108,6 +99,21 @@ pub fn do_add_to_path() -> Result<()> {
10899
Ok(())
109100
}
110101

102+
pub fn do_write_env_files() -> Result<()> {
103+
let mut written = vec![];
104+
105+
for sh in shell::get_available_shells() {
106+
let script = sh.env_script();
107+
// Only write each possible script once.
108+
if !written.contains(&script) {
109+
script.write()?;
110+
written.push(script);
111+
}
112+
}
113+
114+
Ok(())
115+
}
116+
111117
/// Tell the upgrader to replace the rustup bins, then delete
112118
/// itself. Like with uninstallation, on Windows we're going to
113119
/// have to jump through hoops to make everything work right.

src/cli/self_update/windows.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ pub fn do_add_to_path() -> Result<()> {
144144
_apply_new_path(new_path)
145145
}
146146

147+
// Nothing to do for Windows for now
148+
pub fn do_write_env_files() -> Result<()> {
149+
Ok(())
150+
}
151+
147152
fn _apply_new_path(new_path: Option<String>) -> Result<()> {
148153
use std::ptr;
149154
use winapi::shared::minwindef::*;

tests/cli-inst-interactive.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ Rust is installed now. Great!
110110
);
111111
if cfg!(unix) {
112112
assert!(!config.homedir.join(".profile").exists());
113+
assert!(config.cargodir.join("env").exists());
113114
}
114115
});
115116
}

0 commit comments

Comments
 (0)