File tree Expand file tree Collapse file tree 1 file changed +21
-7
lines changed
crates/era-downloader/src Expand file tree Collapse file tree 1 file changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -67,16 +67,30 @@ impl<Http: HttpClient + Clone> EraClient<Http> {
6767
6868 let number =
6969 self . file_name_to_number ( file_name) . ok_or_eyre ( "Cannot parse number from file name" ) ?;
70- let mut stream = client. get ( url) . await ?;
71- let mut file = File :: create ( & path) . await ?;
72- let mut hasher = Sha256 :: new ( ) ;
7370
74- while let Some ( item) = stream. next ( ) . await . transpose ( ) ? {
75- io:: copy ( & mut item. as_ref ( ) , & mut file) . await ?;
76- hasher. update ( item) ;
71+ let mut tries = 1 ..3 ;
72+ let mut actual_checksum: eyre:: Result < _ > ;
73+ loop {
74+ actual_checksum = async {
75+ let mut file = File :: create ( & path) . await ?;
76+ let mut stream = client. get ( url. clone ( ) ) . await ?;
77+ let mut hasher = Sha256 :: new ( ) ;
78+
79+ while let Some ( item) = stream. next ( ) . await . transpose ( ) ? {
80+ io:: copy ( & mut item. as_ref ( ) , & mut file) . await ?;
81+ hasher. update ( item) ;
82+ }
83+
84+ Ok ( hasher. finalize ( ) . to_vec ( ) )
85+ }
86+ . await ;
87+
88+ if actual_checksum. is_ok ( ) || tries. next ( ) . is_none ( ) {
89+ break ;
90+ }
7791 }
7892
79- let actual_checksum = hasher . finalize ( ) . to_vec ( ) ;
93+ let actual_checksum = actual_checksum? ;
8094
8195 let file = File :: open ( self . folder . join ( Self :: CHECKSUMS ) ) . await ?;
8296 let reader = io:: BufReader :: new ( file) ;
You can’t perform that action at this time.
0 commit comments