@@ -34,7 +34,7 @@ use filetime::FileTime;
34
34
use sha2:: digest:: Digest ;
35
35
use termcolor:: { ColorChoice , StandardStream , WriteColor } ;
36
36
use utils:: channel:: GitInfo ;
37
- use utils:: helpers:: hex_encode;
37
+ use utils:: helpers:: { hex_encode, retry } ;
38
38
39
39
use crate :: core:: builder;
40
40
use crate :: core:: builder:: Kind ;
@@ -1688,18 +1688,25 @@ impl Build {
1688
1688
return ;
1689
1689
}
1690
1690
}
1691
- if let Ok ( ( ) ) = fs:: hard_link ( & src, dst) {
1692
- // Attempt to "easy copy" by creating a hard link
1693
- // (symlinks don't work on windows), but if that fails
1694
- // just fall back to a slow `copy` operation.
1695
- } else {
1696
- if let Err ( e) = fs:: copy ( & src, dst) {
1697
- panic ! ( "failed to copy `{}` to `{}`: {}" , src. display( ) , dst. display( ) , e)
1691
+ // workaround for https://github.com/rust-lang/rust/issues/127126
1692
+ // retry linking or copying up to 10 times or until success.
1693
+ let result: io:: Result < ( ) > = retry ( 10 , || {
1694
+ if let Ok ( ( ) ) = fs:: hard_link ( & src, dst) {
1695
+ // Attempt to "easy copy" by creating a hard link
1696
+ // (symlinks don't work on windows), but if that fails
1697
+ // just fall back to a slow `copy` operation.
1698
+ Ok ( ( ) )
1699
+ } else {
1700
+ fs:: copy ( & src, dst) ?;
1701
+ t ! ( fs:: set_permissions( dst, metadata. permissions( ) ) ) ;
1702
+ let atime = FileTime :: from_last_access_time ( & metadata) ;
1703
+ let mtime = FileTime :: from_last_modification_time ( & metadata) ;
1704
+ t ! ( filetime:: set_file_times( dst, atime, mtime) ) ;
1705
+ Ok ( ( ) )
1698
1706
}
1699
- t ! ( fs:: set_permissions( dst, metadata. permissions( ) ) ) ;
1700
- let atime = FileTime :: from_last_access_time ( & metadata) ;
1701
- let mtime = FileTime :: from_last_modification_time ( & metadata) ;
1702
- t ! ( filetime:: set_file_times( dst, atime, mtime) ) ;
1707
+ } ) ;
1708
+ if let Err ( e) = result {
1709
+ panic ! ( "failed to copy `{}` to `{}`: {}" , src. display( ) , dst. display( ) , e)
1703
1710
}
1704
1711
}
1705
1712
0 commit comments