@@ -145,22 +145,38 @@ pub fn self_replace() -> Result<utils::ExitCode> {
145
145
Ok ( utils:: ExitCode ( 0 ) )
146
146
}
147
147
148
- fn remove_legacy_paths ( ) -> Result < ( ) > {
149
- let export = format ! ( "export PATH= \" {}/bin:$PATH \" \n " , shell :: cargo_home_str ( ) ? ) . into_bytes ( ) ;
148
+ fn remove_legacy_source_command ( source_cmd : String ) -> Result < ( ) > {
149
+ let cmd_bytes = source_cmd . into_bytes ( ) ;
150
150
for rc in shell:: legacy_paths ( ) . filter ( |rc| rc. is_file ( ) ) {
151
151
let file = utils:: read_file ( "rcfile" , & rc) ?;
152
152
let file_bytes = file. into_bytes ( ) ;
153
153
// FIXME: This is whitespace sensitive where it should not be.
154
154
if let Some ( idx) = file_bytes
155
- . windows ( export . len ( ) )
156
- . position ( |w| w == export . as_slice ( ) )
155
+ . windows ( cmd_bytes . len ( ) )
156
+ . position ( |w| w == cmd_bytes . as_slice ( ) )
157
157
{
158
158
// Here we rewrite the file without the offending line.
159
159
let mut new_bytes = file_bytes[ ..idx] . to_vec ( ) ;
160
- new_bytes. extend ( & file_bytes[ idx + export . len ( ) ..] ) ;
160
+ new_bytes. extend ( & file_bytes[ idx + cmd_bytes . len ( ) ..] ) ;
161
161
let new_file = String :: from_utf8 ( new_bytes) . unwrap ( ) ;
162
162
utils:: write_file ( "rcfile" , & rc, & new_file) ?;
163
163
}
164
164
}
165
165
Ok ( ( ) )
166
166
}
167
+
168
+ fn remove_legacy_paths ( ) -> Result < ( ) > {
169
+ // Before the work to support more kinds of shells, which was released in
170
+ // version 1.23.0 of rustup, we always inserted this line instead, which is
171
+ // now considered legacy
172
+ remove_legacy_source_command ( format ! (
173
+ "export PATH=\" {}/bin:$PATH\" \n " ,
174
+ shell:: cargo_home_str( ) ?
175
+ ) ) ?;
176
+ // Unfortunately in 1.23, we accidentally used `source` rather than `.`
177
+ // which, while widely supported, isn't actually POSIX, so we also
178
+ // clean that up here. This issue was filed as #2623.
179
+ remove_legacy_source_command ( format ! ( "source \" {}/env\" \n " , shell:: cargo_home_str( ) ?) ) ?;
180
+
181
+ Ok ( ( ) )
182
+ }
0 commit comments