40
40
//! ```
41
41
//!
42
42
//! # Download a snapshot
43
+ //! **Note:** _Available on crate feature_ **fs** _only._
43
44
//!
44
45
//! To download and simultaneously unpack the tarball of a snapshots using the [ClientBuilder][crate::client::ClientBuilder].
45
46
//!
63
64
//! ```
64
65
65
66
use anyhow:: Context ;
66
- use slog:: { warn , Logger } ;
67
- use std:: { path :: Path , sync:: Arc } ;
67
+ use slog:: Logger ;
68
+ use std:: sync:: Arc ;
68
69
use thiserror:: Error ;
69
70
70
71
use crate :: aggregator_client:: { AggregatorClient , AggregatorClientError , AggregatorRequest } ;
71
- use crate :: feedback:: { FeedbackSender , MithrilEvent } ;
72
+ use crate :: feedback:: FeedbackSender ;
73
+ #[ cfg( feature = "fs" ) ]
72
74
use crate :: snapshot_downloader:: SnapshotDownloader ;
73
75
use crate :: { MithrilResult , Snapshot , SnapshotListItem } ;
74
76
@@ -89,6 +91,7 @@ pub enum SnapshotClientError {
89
91
/// Aggregator client for the snapshot artifact
90
92
pub struct SnapshotClient {
91
93
aggregator_client : Arc < dyn AggregatorClient > ,
94
+ #[ cfg( feature = "fs" ) ]
92
95
snapshot_downloader : Arc < dyn SnapshotDownloader > ,
93
96
feedback_sender : FeedbackSender ,
94
97
logger : Logger ,
@@ -98,12 +101,13 @@ impl SnapshotClient {
98
101
/// Constructs a new `SnapshotClient`.
99
102
pub fn new (
100
103
aggregator_client : Arc < dyn AggregatorClient > ,
101
- snapshot_downloader : Arc < dyn SnapshotDownloader > ,
104
+ # [ cfg ( feature = "fs" ) ] snapshot_downloader : Arc < dyn SnapshotDownloader > ,
102
105
feedback_sender : FeedbackSender ,
103
106
logger : Logger ,
104
107
) -> Self {
105
108
Self {
106
109
aggregator_client,
110
+ #[ cfg( feature = "fs" ) ]
107
111
snapshot_downloader,
108
112
feedback_sender,
109
113
logger,
@@ -143,15 +147,18 @@ impl SnapshotClient {
143
147
}
144
148
}
145
149
150
+ cfg_fs ! {
146
151
/// Download and unpack the given snapshot to the given directory
147
152
///
148
153
/// **NOTE**: The directory should already exist, and the user running the binary
149
154
/// must have read/write access to it.
150
155
pub async fn download_unpack(
151
156
& self ,
152
157
snapshot: & Snapshot ,
153
- target_dir : & Path ,
158
+ target_dir: & std :: path :: Path ,
154
159
) -> MithrilResult <( ) > {
160
+ use crate :: feedback:: MithrilEvent ;
161
+
155
162
for location in snapshot. locations. as_slice( ) {
156
163
if self . snapshot_downloader. probe( location) . await . is_ok( ) {
157
164
let download_id = MithrilEvent :: new_snapshot_download_id( ) ;
@@ -182,7 +189,7 @@ impl SnapshotClient {
182
189
Ok ( ( ) )
183
190
}
184
191
Err ( e) => {
185
- warn ! (
192
+ slog :: warn!(
186
193
self . logger,
187
194
"Failed downloading snapshot from '{location}' Error: {e}."
188
195
) ;
@@ -200,14 +207,18 @@ impl SnapshotClient {
200
207
}
201
208
. into( ) )
202
209
}
210
+ }
203
211
}
204
212
205
- #[ cfg( test) ]
206
- mod tests {
213
+ #[ cfg( all ( test, feature = "fs" ) ) ]
214
+ mod tests_download {
207
215
use crate :: {
208
- aggregator_client:: MockAggregatorHTTPClient , feedback:: StackFeedbackReceiver ,
209
- snapshot_downloader:: MockHttpSnapshotDownloader , test_utils,
216
+ aggregator_client:: MockAggregatorHTTPClient ,
217
+ feedback:: { MithrilEvent , StackFeedbackReceiver } ,
218
+ snapshot_downloader:: MockHttpSnapshotDownloader ,
219
+ test_utils,
210
220
} ;
221
+ use std:: path:: Path ;
211
222
212
223
use super :: * ;
213
224
0 commit comments