@@ -49,6 +49,20 @@ use std::path::{Component, Path, PathBuf};
49
49
use std:: process:: { self , Command } ;
50
50
mod types;
51
51
use types:: PathUpdateMethod ;
52
+ #[ cfg( unix) ]
53
+ mod unix;
54
+ #[ cfg( unix) ]
55
+ mod os {
56
+ #[ cfg( unix) ]
57
+ pub use crate :: self_update:: unix:: * ;
58
+ }
59
+
60
+ #[ cfg( unix) ]
61
+ pub use os:: {
62
+ complete_windows_uninstall, delete_rustup_and_cargo_home, run_update, self_replace,
63
+ } ;
64
+ #[ cfg( unix) ]
65
+ use os:: * ;
52
66
53
67
pub struct InstallOpts < ' a > {
54
68
pub default_host_triple : Option < String > ,
@@ -477,42 +491,6 @@ fn do_pre_install_options_sanity_checks(opts: &InstallOpts) -> Result<()> {
477
491
Ok ( ( ) )
478
492
}
479
493
480
- // If the user is trying to install with sudo, on some systems this will
481
- // result in writing root-owned files to the user's home directory, because
482
- // sudo is configured not to change $HOME. Don't let that bogosity happen.
483
- #[ cfg( unix) ]
484
- fn do_anti_sudo_check ( no_prompt : bool ) -> Result < ( ) > {
485
- pub fn home_mismatch ( ) -> ( bool , PathBuf , PathBuf ) {
486
- let fallback = || ( false , PathBuf :: new ( ) , PathBuf :: new ( ) ) ;
487
- // test runner should set this, nothing else
488
- if env:: var_os ( "RUSTUP_INIT_SKIP_SUDO_CHECK" ) . map_or ( false , |s| s == "yes" ) {
489
- return fallback ( ) ;
490
- }
491
-
492
- match ( utils:: home_dir_from_passwd ( ) , env:: var_os ( "HOME" ) ) {
493
- ( Some ( pw) , Some ( eh) ) if eh != pw => return ( true , PathBuf :: from ( eh) , pw) ,
494
- ( None , _) => warn ! ( "getpwuid_r: couldn't get user data" ) ,
495
- _ => { }
496
- }
497
- fallback ( )
498
- }
499
-
500
- match home_mismatch ( ) {
501
- ( false , _, _) => { }
502
- ( true , env_home, euid_home) => {
503
- err ! ( "$HOME differs from euid-obtained home directory: you may be using sudo" ) ;
504
- err ! ( "$HOME directory: {}" , env_home. display( ) ) ;
505
- err ! ( "euid-obtained home directory: {}" , euid_home. display( ) ) ;
506
- if !no_prompt {
507
- err ! ( "if this is what you want, restart the installation with `-y'" ) ;
508
- process:: exit ( 1 ) ;
509
- }
510
- }
511
- }
512
-
513
- Ok ( ( ) )
514
- }
515
-
516
494
// Provide guidance about setting up MSVC if it doesn't appear to be
517
495
// installed
518
496
#[ cfg( windows) ]
@@ -537,6 +515,7 @@ fn do_msvc_check(opts: &InstallOpts) -> Result<bool> {
537
515
Ok ( true )
538
516
}
539
517
518
+
540
519
#[ cfg( not( windows) ) ]
541
520
fn do_msvc_check ( _opts : & InstallOpts ) -> Result < bool > {
542
521
Ok ( true )
@@ -897,14 +876,6 @@ pub fn uninstall(no_prompt: bool) -> Result<()> {
897
876
process:: exit ( 0 ) ;
898
877
}
899
878
900
- #[ cfg( unix) ]
901
- fn delete_rustup_and_cargo_home ( ) -> Result < ( ) > {
902
- let cargo_home = utils:: cargo_home ( ) ?;
903
- utils:: remove_dir ( "cargo_home" , & cargo_home, & |_: Notification < ' _ > | ( ) ) ?;
904
-
905
- Ok ( ( ) )
906
- }
907
-
908
879
// The last step of uninstallation is to delete *this binary*,
909
880
// rustup.exe and the CARGO_HOME that contains it. On Unix, this
910
881
// works fine. On Windows you can't delete files while they are open,
@@ -1115,11 +1086,6 @@ fn wait_for_parent() -> Result<()> {
1115
1086
Ok ( ( ) )
1116
1087
}
1117
1088
1118
- #[ cfg( unix) ]
1119
- pub fn complete_windows_uninstall ( ) -> Result < ( ) > {
1120
- panic ! ( "stop doing that" )
1121
- }
1122
-
1123
1089
/// Decide which rcfiles we're going to update, so we
1124
1090
/// can tell the user before they confirm.
1125
1091
fn get_add_path_methods ( ) -> Vec < PathUpdateMethod > {
@@ -1157,30 +1123,6 @@ fn shell_export_string() -> Result<String> {
1157
1123
Ok ( format ! ( r#"export PATH="{}:$PATH""# , path) )
1158
1124
}
1159
1125
1160
- #[ cfg( unix) ]
1161
- fn do_add_to_path ( methods : & [ PathUpdateMethod ] ) -> Result < ( ) > {
1162
- for method in methods {
1163
- if let PathUpdateMethod :: RcFile ( ref rcpath) = * method {
1164
- let file = if rcpath. exists ( ) {
1165
- utils:: read_file ( "rcfile" , rcpath) ?
1166
- } else {
1167
- String :: new ( )
1168
- } ;
1169
- let addition = format ! ( "\n {}" , shell_export_string( ) ?) ;
1170
- if !file. contains ( & addition) {
1171
- utils:: append_file ( "rcfile" , rcpath, & addition) . chain_err ( || {
1172
- ErrorKind :: WritingShellProfile {
1173
- path : rcpath. to_path_buf ( ) ,
1174
- }
1175
- } ) ?;
1176
- }
1177
- } else {
1178
- unreachable ! ( )
1179
- }
1180
- }
1181
-
1182
- Ok ( ( ) )
1183
- }
1184
1126
1185
1127
#[ cfg( windows) ]
1186
1128
fn do_add_to_path ( methods : & [ PathUpdateMethod ] ) -> Result < ( ) > {
@@ -1371,35 +1313,6 @@ fn do_remove_from_path(methods: &[PathUpdateMethod]) -> Result<()> {
1371
1313
Ok ( ( ) )
1372
1314
}
1373
1315
1374
- #[ cfg( unix) ]
1375
- fn do_remove_from_path ( methods : & [ PathUpdateMethod ] ) -> Result < ( ) > {
1376
- for method in methods {
1377
- if let PathUpdateMethod :: RcFile ( ref rcpath) = * method {
1378
- let file = utils:: read_file ( "rcfile" , rcpath) ?;
1379
- let addition = format ! ( "\n {}\n " , shell_export_string( ) ?) ;
1380
-
1381
- let file_bytes = file. into_bytes ( ) ;
1382
- let addition_bytes = addition. into_bytes ( ) ;
1383
-
1384
- let idx = file_bytes
1385
- . windows ( addition_bytes. len ( ) )
1386
- . position ( |w| w == & * addition_bytes) ;
1387
- if let Some ( i) = idx {
1388
- let mut new_file_bytes = file_bytes[ ..i] . to_vec ( ) ;
1389
- new_file_bytes. extend ( & file_bytes[ i + addition_bytes. len ( ) ..] ) ;
1390
- let new_file = String :: from_utf8 ( new_file_bytes) . unwrap ( ) ;
1391
- utils:: write_file ( "rcfile" , rcpath, & new_file) ?;
1392
- } else {
1393
- // Weird case. rcfile no longer needs to be modified?
1394
- }
1395
- } else {
1396
- unreachable ! ( )
1397
- }
1398
- }
1399
-
1400
- Ok ( ( ) )
1401
- }
1402
-
1403
1316
/// Self update downloads rustup-init to `CARGO_HOME`/bin/rustup-init
1404
1317
/// and runs it.
1405
1318
///
@@ -1576,28 +1489,6 @@ pub fn prepare_update() -> Result<Option<PathBuf>> {
1576
1489
Ok ( Some ( setup_path) )
1577
1490
}
1578
1491
1579
- /// Tell the upgrader to replace the rustup bins, then delete
1580
- /// itself. Like with uninstallation, on Windows we're going to
1581
- /// have to jump through hoops to make everything work right.
1582
- ///
1583
- /// On windows we're not going to wait for it to finish before exiting
1584
- /// successfully, so it should not do much, and it should try
1585
- /// really hard to succeed, because at this point the upgrade is
1586
- /// considered successful.
1587
- #[ cfg( unix) ]
1588
- pub fn run_update ( setup_path : & Path ) -> Result < ( ) > {
1589
- let status = Command :: new ( setup_path)
1590
- . arg ( "--self-replace" )
1591
- . status ( )
1592
- . chain_err ( || "unable to run updater" ) ?;
1593
-
1594
- if !status. success ( ) {
1595
- return Err ( "self-updated failed to replace rustup executable" . into ( ) ) ;
1596
- }
1597
-
1598
- process:: exit ( 0 ) ;
1599
- }
1600
-
1601
1492
#[ cfg( windows) ]
1602
1493
pub fn run_update ( setup_path : & Path ) -> Result < ( ) > {
1603
1494
Command :: new ( setup_path)
@@ -1608,16 +1499,6 @@ pub fn run_update(setup_path: &Path) -> Result<()> {
1608
1499
process:: exit ( 0 ) ;
1609
1500
}
1610
1501
1611
- /// This function is as the final step of a self-upgrade. It replaces
1612
- /// `CARGO_HOME`/bin/rustup with the running exe, and updates the the
1613
- /// links to it. On windows this will run *after* the original
1614
- /// rustup process exits.
1615
- #[ cfg( unix) ]
1616
- pub fn self_replace ( ) -> Result < ( ) > {
1617
- install_bins ( ) ?;
1618
-
1619
- Ok ( ( ) )
1620
- }
1621
1502
1622
1503
#[ cfg( windows) ]
1623
1504
pub fn self_replace ( ) -> Result < ( ) > {
0 commit comments