@@ -22,6 +22,28 @@ fn run(cmd: &mut Command, step: &str) -> Result<(), Box<dyn Error>> {
2222 Ok ( ( ) )
2323}
2424
25+ /// Like `run`, but retries up to `attempts` times on failure (useful for
26+ /// transient network errors such as GitHub returning HTTP 500 during git clone).
27+ fn run_with_retry (
28+ build_cmd : & dyn Fn ( ) -> Command ,
29+ step : & str ,
30+ attempts : u32 ,
31+ ) -> Result < ( ) , Box < dyn Error > > {
32+ let mut last_err: Box < dyn Error > = "no attempts made" . into ( ) ;
33+ for attempt in 1 ..=attempts {
34+ if attempt > 1 {
35+ println ! ( "cargo:warning={step}: retry {attempt}/{attempts} after transient failure" ) ;
36+ std:: thread:: sleep ( std:: time:: Duration :: from_secs ( 5 ) ) ;
37+ }
38+ let mut cmd = build_cmd ( ) ;
39+ match run ( & mut cmd, step) {
40+ Ok ( ( ) ) => return Ok ( ( ) ) ,
41+ Err ( e) => last_err = e,
42+ }
43+ }
44+ Err ( last_err)
45+ }
46+
2547fn nproc ( ) -> String {
2648 std:: thread:: available_parallelism ( )
2749 . map ( |n| n. get ( ) . to_string ( ) )
@@ -88,12 +110,17 @@ fn main() -> Result<(), Box<dyn Error>> {
88110 // 1) Fetch obs-studio source into revo-lib/obs-libobs
89111 if !obs_src. exists ( ) {
90112 fs:: create_dir_all ( & obs_root) ?;
91- run (
92- Command :: new ( "git" )
93- . arg ( "clone" )
94- . arg ( "https://github.com/obsproject/obs-studio.git" )
95- . arg ( & obs_src) ,
113+ let obs_src_clone = obs_src. clone ( ) ;
114+ run_with_retry (
115+ & || {
116+ let mut cmd = Command :: new ( "git" ) ;
117+ cmd. arg ( "clone" )
118+ . arg ( "https://github.com/obsproject/obs-studio.git" )
119+ . arg ( & obs_src_clone) ;
120+ cmd
121+ } ,
96122 "git clone obs-studio" ,
123+ 3 ,
97124 ) ?;
98125 }
99126
0 commit comments