@@ -6,7 +6,7 @@ use std::env;
66use std:: env:: consts:: EXE_SUFFIX ;
77use std:: ffi:: OsStr ;
88use std:: fs;
9- use std:: io;
9+ use std:: io:: { self , Write } ;
1010use std:: path:: { Path , PathBuf } ;
1111use std:: process:: Command ;
1212use std:: sync:: Arc ;
@@ -232,7 +232,7 @@ pub fn setup_test_state(test_dist_dir: tempfile::TempDir) -> (tempfile::TempDir,
232232 let rls_path = config. exedir . join ( format ! ( "rls{EXE_SUFFIX}" ) ) ;
233233 let rust_lldb_path = config. exedir . join ( format ! ( "rust-lldb{EXE_SUFFIX}" ) ) ;
234234
235- copy_binary ( build_path, & rustup_path) . unwrap ( ) ;
235+ hard_link ( build_path, & rustup_path) . unwrap ( ) ;
236236 hard_link ( & rustup_path, setup_path) . unwrap ( ) ;
237237 hard_link ( & rustup_path, rustc_path) . unwrap ( ) ;
238238 hard_link ( & rustup_path, cargo_path) . unwrap ( ) ;
@@ -282,6 +282,7 @@ fn create_local_update_server(self_dist: &Path, exedir: &Path, version: &str) ->
282282
283283 fs:: create_dir_all ( dist_dir) . unwrap ( ) ;
284284 output_release_file ( self_dist, "1" , version) ;
285+ // TODO: should this hardlink?
285286 fs:: copy ( rustup_bin, dist_exe) . unwrap ( ) ;
286287
287288 let root_url = format ! ( "file://{}" , self_dist. display( ) ) ;
@@ -303,9 +304,21 @@ pub fn self_update_setup(f: &dyn Fn(&mut Config, &Path), version: &str) {
303304 let trip = this_host_triple ( ) ;
304305 let dist_dir = self_dist. join ( format ! ( "archive/{version}/{trip}" ) ) ;
305306 let dist_exe = dist_dir. join ( format ! ( "rustup-init{EXE_SUFFIX}" ) ) ;
307+ let dist_tmp = dist_dir. join ( "rustup-init-tmp" ) ;
306308
307309 // Modify the exe so it hashes different
308- raw:: append_file ( & dist_exe, "" ) . unwrap ( ) ;
310+ // 1) move out of the way the file
311+ fs:: rename ( & dist_exe, & dist_tmp) . unwrap ( ) ;
312+ // 2) copy it
313+ fs:: copy ( dist_tmp, & dist_exe) . unwrap ( ) ;
314+ // modify it
315+ let mut dest_file = fs:: OpenOptions :: new ( )
316+ . write ( true )
317+ . append ( true )
318+ . create ( true )
319+ . open ( dist_exe)
320+ . unwrap ( ) ;
321+ writeln ! ( dest_file) . unwrap ( ) ;
309322
310323 f ( config, self_dist) ;
311324 } ) ;
@@ -322,8 +335,21 @@ pub fn with_update_server(config: &mut Config, version: &str, f: &dyn Fn(&mut Co
322335 let trip = this_host_triple ( ) ;
323336 let dist_dir = self_dist. join ( format ! ( "archive/{version}/{trip}" ) ) ;
324337 let dist_exe = dist_dir. join ( format ! ( "rustup-init{EXE_SUFFIX}" ) ) ;
338+ let dist_tmp = dist_dir. join ( "rustup-init-tmp" ) ;
339+
325340 // Modify the exe so it hashes different
326- raw:: append_file ( & dist_exe, "" ) . unwrap ( ) ;
341+ // 1) move out of the way the file
342+ fs:: rename ( & dist_exe, & dist_tmp) . unwrap ( ) ;
343+ // 2) copy it
344+ fs:: copy ( dist_tmp, & dist_exe) . unwrap ( ) ;
345+ // modify it
346+ let mut dest_file = fs:: OpenOptions :: new ( )
347+ . write ( true )
348+ . append ( true )
349+ . create ( true )
350+ . open ( dist_exe)
351+ . unwrap ( ) ;
352+ writeln ! ( dest_file) . unwrap ( ) ;
327353
328354 config. rustup_update_root = Some ( root_url) ;
329355 f ( config) ;
@@ -1498,19 +1524,3 @@ where
14981524 }
14991525 inner ( a. as_ref ( ) , b. as_ref ( ) )
15001526}
1501-
1502- pub fn copy_binary < A , B > ( a : A , b : B ) -> io:: Result < ( ) >
1503- where
1504- A : AsRef < Path > ,
1505- B : AsRef < Path > ,
1506- {
1507- fn inner ( a : & Path , b : & Path ) -> io:: Result < ( ) > {
1508- match fs:: remove_file ( b) {
1509- Err ( e) if e. kind ( ) != io:: ErrorKind :: NotFound => return Err ( e) ,
1510- _ => { }
1511- }
1512- fs:: copy ( a, b) . map ( drop)
1513- }
1514- let _lock = cmd_lock ( ) . write ( ) . unwrap ( ) ;
1515- inner ( a. as_ref ( ) , b. as_ref ( ) )
1516- }
0 commit comments