1
1
use anyhow:: Context ;
2
2
use async_trait:: async_trait;
3
3
use futures:: Future ;
4
- use indicatif:: { MultiProgress , ProgressBar , ProgressDrawTarget , ProgressState , ProgressStyle } ;
4
+ use indicatif:: { MultiProgress , ProgressBar , ProgressState , ProgressStyle } ;
5
5
use slog_scope:: { debug, warn} ;
6
6
use std:: {
7
7
fmt:: Write ,
@@ -24,7 +24,9 @@ use mithril_common::{
24
24
25
25
use crate :: {
26
26
aggregator_client:: { AggregatorHTTPClientError , CertificateClient , SnapshotClient } ,
27
- utils:: { SnapshotUnpacker , SnapshotUnpackerError } ,
27
+ utils:: {
28
+ DownloadProgressReporter , ProgressOutputType , SnapshotUnpacker , SnapshotUnpackerError ,
29
+ } ,
28
30
} ;
29
31
30
32
/// [SnapshotService] related errors.
@@ -72,7 +74,7 @@ pub trait SnapshotService: Sync + Send {
72
74
snapshot_entity : & SignedEntity < Snapshot > ,
73
75
pathdir : & Path ,
74
76
genesis_verification_key : & str ,
75
- progress_target : ProgressDrawTarget ,
77
+ progress_output_type : ProgressOutputType ,
76
78
) -> StdResult < PathBuf > ;
77
79
}
78
80
@@ -210,12 +212,12 @@ impl SnapshotService for MithrilClientSnapshotService {
210
212
snapshot_entity : & SignedEntity < Snapshot > ,
211
213
download_dir : & Path ,
212
214
genesis_verification_key : & str ,
213
- progress_target : ProgressDrawTarget ,
215
+ progress_output_type : ProgressOutputType ,
214
216
) -> StdResult < PathBuf > {
215
217
debug ! ( "Snapshot service: download." ) ;
216
218
217
219
let db_dir = download_dir. join ( "db" ) ;
218
- let progress_bar = MultiProgress :: with_draw_target ( progress_target ) ;
220
+ let progress_bar = MultiProgress :: with_draw_target ( progress_output_type . into ( ) ) ;
219
221
progress_bar. println ( "1/7 - Checking local disk info…" ) ?;
220
222
let unpacker = SnapshotUnpacker ;
221
223
@@ -246,7 +248,11 @@ impl SnapshotService for MithrilClientSnapshotService {
246
248
. progress_chars ( "#>-" ) ) ;
247
249
let snapshot_path = self
248
250
. snapshot_client
249
- . download ( & snapshot_entity. artifact , download_dir, pb)
251
+ . download (
252
+ & snapshot_entity. artifact ,
253
+ download_dir,
254
+ DownloadProgressReporter :: new ( pb, progress_output_type) ,
255
+ )
250
256
. await
251
257
. with_context ( || format ! ( "Could not download file in '{}'" , download_dir. display( ) ) ) ?;
252
258
@@ -550,7 +556,7 @@ mod tests {
550
556
& snapshot,
551
557
& test_path,
552
558
& genesis_verification_key. to_json_hex ( ) . unwrap ( ) ,
553
- ProgressDrawTarget :: hidden ( ) ,
559
+ ProgressOutputType :: Hidden ,
554
560
)
555
561
. await
556
562
. expect ( "Snapshot download should succeed." ) ;
@@ -590,7 +596,7 @@ mod tests {
590
596
& snapshot,
591
597
& test_path,
592
598
& genesis_verification_key. to_json_hex ( ) . unwrap ( ) ,
593
- ProgressDrawTarget :: hidden ( ) ,
599
+ ProgressOutputType :: Hidden ,
594
600
)
595
601
. await
596
602
. expect ( "Snapshot download should succeed." ) ;
@@ -636,7 +642,7 @@ mod tests {
636
642
& signed_entity,
637
643
& test_path,
638
644
& genesis_verification_key. to_json_hex ( ) . unwrap ( ) ,
639
- ProgressDrawTarget :: hidden ( ) ,
645
+ ProgressOutputType :: Hidden ,
640
646
)
641
647
. await
642
648
. expect_err ( "Snapshot digest comparison should fail." ) ;
@@ -684,7 +690,7 @@ mod tests {
684
690
& snapshot,
685
691
& test_path,
686
692
& genesis_verification_key. to_json_hex ( ) . unwrap ( ) ,
687
- ProgressDrawTarget :: hidden ( ) ,
693
+ ProgressOutputType :: Hidden ,
688
694
)
689
695
. await
690
696
. expect_err ( "Snapshot download should fail." ) ;
0 commit comments