@@ -666,9 +666,7 @@ fn print_results(cfg: &Config, client: &Client, bisection_result: &BisectionResu
666
666
let r = match t. install ( & client, & dl_spec) {
667
667
Ok ( ( ) ) => {
668
668
let outcome = t. test ( & cfg) ;
669
- if !cfg. args . preserve {
670
- let _ = t. remove ( & dl_spec) ;
671
- }
669
+ remove_toolchain ( cfg, t, & dl_spec) ;
672
670
// we want to fail, so a successful build doesn't satisfy us
673
671
match outcome {
674
672
TestOutcome :: Baseline => Satisfies :: No ,
@@ -698,6 +696,45 @@ fn print_results(cfg: &Config, client: &Client, bisection_result: &BisectionResu
698
696
eprintln ! ( ) ;
699
697
}
700
698
699
+ fn remove_toolchain ( cfg : & Config , toolchain : & Toolchain , dl_params : & DownloadParams ) {
700
+ if cfg. args . preserve {
701
+ // If `rustup toolchain link` was used to link to nightly, then even
702
+ // with --preserve, the toolchain link should be removed, otherwise it
703
+ // will go stale after 24 hours.
704
+ let toolchain_dir = cfg. toolchains_path . join ( toolchain. rustup_name ( ) ) ;
705
+ match fs:: symlink_metadata ( & toolchain_dir) {
706
+ Ok ( meta) => {
707
+ #[ cfg( windows) ]
708
+ let is_junction = {
709
+ use std:: os:: windows:: fs:: MetadataExt ;
710
+ ( meta. file_attributes ( ) & 1024 ) != 0
711
+ } ;
712
+ #[ cfg( not( windows) ) ]
713
+ let is_junction = false ;
714
+ if !meta. file_type ( ) . is_symlink ( ) && !is_junction {
715
+ return ;
716
+ }
717
+ debug ! ( "removing linked toolchain {}" , toolchain) ;
718
+ }
719
+ Err ( e) => {
720
+ debug ! (
721
+ "remove_toolchain: cannot stat toolchain {}: {}" ,
722
+ toolchain, e
723
+ ) ;
724
+ return ;
725
+ }
726
+ }
727
+ }
728
+ if let Err ( e) = toolchain. remove ( dl_params) {
729
+ debug ! (
730
+ "failed to remove toolchain {} in {}: {}" ,
731
+ toolchain,
732
+ cfg. toolchains_path. display( ) ,
733
+ e
734
+ ) ;
735
+ }
736
+ }
737
+
701
738
fn print_final_report (
702
739
cfg : & Config ,
703
740
nightly_bisection_result : & BisectionResult ,
@@ -859,16 +896,12 @@ fn install_and_test(
859
896
TestOutcome :: Regressed => Satisfies :: Yes ,
860
897
} ;
861
898
eprintln ! ( "RESULT: {}, ===> {}" , t, r) ;
862
- if !cfg. args . preserve {
863
- let _ = t. remove ( & dl_spec) ;
864
- }
899
+ remove_toolchain ( cfg, t, & dl_spec) ;
865
900
eprintln ! ( ) ;
866
901
Ok ( r)
867
902
}
868
903
Err ( error) => {
869
- if !cfg. args . preserve {
870
- let _ = t. remove ( & dl_spec) ;
871
- }
904
+ remove_toolchain ( cfg, t, & dl_spec) ;
872
905
Err ( error)
873
906
}
874
907
}
0 commit comments