@@ -195,35 +195,41 @@ pub async fn download_stacks_dataset_if_required(config: &mut Config, ctx: &Cont
195
195
Ok ( response) => response. bytes ( ) . await ,
196
196
Err ( e) => Err ( e) ,
197
197
} ;
198
- match ( local_sha_file, remote_sha_file) {
198
+ let should_download = match ( local_sha_file, remote_sha_file) {
199
199
( Ok ( local) , Ok ( remote_response) ) => {
200
- println ! ( "{:?}" , local) ;
201
- println ! ( "{:?}" , remote_response) ;
202
- }
203
- ( Ok ( local) , _) => {
204
- // println!("Local: {:?}", local)
200
+ let cache_invalidated = remote_response. starts_with ( & local[ 0 ..32 ] ) == false ;
201
+ if cache_invalidated {
202
+ info ! (
203
+ ctx. expect_logger( ) ,
204
+ "More recent Stacks archive file detected"
205
+ ) ;
206
+ }
207
+ cache_invalidated
205
208
}
206
209
( _, _) => {
207
- // We will download the latest file
208
- println ! ( "error reading local / remote" ) ;
210
+ info ! (
211
+ ctx. expect_logger( ) ,
212
+ "Unable to retrieve Stacks archive file locally"
213
+ ) ;
214
+ true
209
215
}
210
- }
211
-
212
- if !tsv_file_path. exists ( ) {
213
- info ! ( ctx. expect_logger( ) , "Downloading {}" , url) ;
214
- match download_tsv_file ( & config) . await {
215
- Ok ( _) => { }
216
- Err ( e) => {
217
- error ! ( ctx. expect_logger( ) , "{}" , e) ;
218
- std:: process:: exit ( 1 ) ;
219
- }
220
- }
221
- } else {
216
+ } ;
217
+ if !should_download {
222
218
info ! (
223
219
ctx. expect_logger( ) ,
224
- "Building in-memory chainstate from file {}" ,
225
- tsv_file_path. display( )
220
+ "Stacks archive file already up to date"
226
221
) ;
222
+ config. add_local_stacks_tsv_source ( & tsv_file_path) ;
223
+ return false ;
224
+ }
225
+
226
+ info ! ( ctx. expect_logger( ) , "Downloading {}" , url) ;
227
+ match download_tsv_file ( & config) . await {
228
+ Ok ( _) => { }
229
+ Err ( e) => {
230
+ error ! ( ctx. expect_logger( ) , "{}" , e) ;
231
+ std:: process:: exit ( 1 ) ;
232
+ }
227
233
}
228
234
config. add_local_stacks_tsv_source ( & tsv_file_path) ;
229
235
}
0 commit comments