@@ -666,9 +666,7 @@ fn print_results(cfg: &Config, client: &Client, bisection_result: &BisectionResu
666666 let r = match t. install ( & client, & dl_spec) {
667667 Ok ( ( ) ) => {
668668 let outcome = t. test ( & cfg) ;
669- if !cfg. args . preserve {
670- let _ = t. remove ( & dl_spec) ;
671- }
669+ remove_toolchain ( cfg, t, & dl_spec) ;
672670 // we want to fail, so a successful build doesn't satisfy us
673671 match outcome {
674672 TestOutcome :: Baseline => Satisfies :: No ,
@@ -698,6 +696,45 @@ fn print_results(cfg: &Config, client: &Client, bisection_result: &BisectionResu
698696 eprintln ! ( ) ;
699697}
700698
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+
701738fn print_final_report (
702739 cfg : & Config ,
703740 nightly_bisection_result : & BisectionResult ,
@@ -859,16 +896,12 @@ fn install_and_test(
859896 TestOutcome :: Regressed => Satisfies :: Yes ,
860897 } ;
861898 eprintln ! ( "RESULT: {}, ===> {}" , t, r) ;
862- if !cfg. args . preserve {
863- let _ = t. remove ( & dl_spec) ;
864- }
899+ remove_toolchain ( cfg, t, & dl_spec) ;
865900 eprintln ! ( ) ;
866901 Ok ( r)
867902 }
868903 Err ( error) => {
869- if !cfg. args . preserve {
870- let _ = t. remove ( & dl_spec) ;
871- }
904+ remove_toolchain ( cfg, t, & dl_spec) ;
872905 Err ( error)
873906 }
874907 }
0 commit comments