@@ -6,7 +6,7 @@ use std::env;
6
6
use std:: env:: consts:: EXE_SUFFIX ;
7
7
use std:: ffi:: OsStr ;
8
8
use std:: fs;
9
- use std:: io;
9
+ use std:: io:: { self , Write } ;
10
10
use std:: path:: { Path , PathBuf } ;
11
11
use std:: process:: Command ;
12
12
use std:: sync:: Arc ;
@@ -232,7 +232,7 @@ pub fn setup_test_state(test_dist_dir: tempfile::TempDir) -> (tempfile::TempDir,
232
232
let rls_path = config. exedir . join ( format ! ( "rls{EXE_SUFFIX}" ) ) ;
233
233
let rust_lldb_path = config. exedir . join ( format ! ( "rust-lldb{EXE_SUFFIX}" ) ) ;
234
234
235
- copy_binary ( build_path, & rustup_path) . unwrap ( ) ;
235
+ hard_link ( build_path, & rustup_path) . unwrap ( ) ;
236
236
hard_link ( & rustup_path, setup_path) . unwrap ( ) ;
237
237
hard_link ( & rustup_path, rustc_path) . unwrap ( ) ;
238
238
hard_link ( & rustup_path, cargo_path) . unwrap ( ) ;
@@ -282,6 +282,7 @@ fn create_local_update_server(self_dist: &Path, exedir: &Path, version: &str) ->
282
282
283
283
fs:: create_dir_all ( dist_dir) . unwrap ( ) ;
284
284
output_release_file ( self_dist, "1" , version) ;
285
+ // TODO: should this hardlink?
285
286
fs:: copy ( rustup_bin, dist_exe) . unwrap ( ) ;
286
287
287
288
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) {
303
304
let trip = this_host_triple ( ) ;
304
305
let dist_dir = self_dist. join ( format ! ( "archive/{version}/{trip}" ) ) ;
305
306
let dist_exe = dist_dir. join ( format ! ( "rustup-init{EXE_SUFFIX}" ) ) ;
307
+ let dist_tmp = dist_dir. join ( "rustup-init-tmp" ) ;
306
308
307
309
// 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 ( ) ;
309
322
310
323
f ( config, self_dist) ;
311
324
} ) ;
@@ -322,8 +335,21 @@ pub fn with_update_server(config: &mut Config, version: &str, f: &dyn Fn(&mut Co
322
335
let trip = this_host_triple ( ) ;
323
336
let dist_dir = self_dist. join ( format ! ( "archive/{version}/{trip}" ) ) ;
324
337
let dist_exe = dist_dir. join ( format ! ( "rustup-init{EXE_SUFFIX}" ) ) ;
338
+ let dist_tmp = dist_dir. join ( "rustup-init-tmp" ) ;
339
+
325
340
// 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 ( ) ;
327
353
328
354
config. rustup_update_root = Some ( root_url) ;
329
355
f ( config) ;
@@ -1498,19 +1524,3 @@ where
1498
1524
}
1499
1525
inner ( a. as_ref ( ) , b. as_ref ( ) )
1500
1526
}
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