1
- use std:: { collections :: HashMap , path:: Path } ;
1
+ use std:: path:: Path ;
2
2
3
3
use anyhow:: anyhow;
4
4
use async_trait:: async_trait;
5
5
6
6
use mithril_common:: {
7
7
entities:: {
8
8
AncillaryLocation , CompressionAlgorithm , DigestLocation , FileUri , ImmutableFileNumber ,
9
- ImmutablesLocation ,
10
9
} ,
11
10
StdError , StdResult ,
12
11
} ;
@@ -21,39 +20,6 @@ pub enum FileDownloaderUri {
21
20
}
22
21
23
22
impl FileDownloaderUri {
24
- /// Expand the immutable locations to a list of file URIs
25
- pub fn expand_immutable_files_location_to_file_downloader_uris (
26
- immutable_files_location : & ImmutablesLocation ,
27
- immutable_files_range : & [ ImmutableFileNumber ] ,
28
- ) -> StdResult < Vec < ( ImmutableFileNumber , FileDownloaderUri ) > > {
29
- match immutable_files_location {
30
- ImmutablesLocation :: CloudStorage {
31
- uri,
32
- compression_algorithm : _,
33
- } => {
34
- let expand_variables = immutable_files_range
35
- . iter ( )
36
- . map ( |immutable_file_number| {
37
- HashMap :: from ( [ (
38
- "immutable_file_number" . to_string ( ) ,
39
- format ! ( "{:05}" , immutable_file_number) ,
40
- ) ] )
41
- } )
42
- . collect ( ) ;
43
- let file_downloader_uris = uri
44
- . expand_to_file_uris ( expand_variables) ?
45
- . into_iter ( )
46
- . map ( FileDownloaderUri :: FileUri ) ;
47
- let immutable_files_range = immutable_files_range. iter ( ) . copied ( ) ;
48
-
49
- Ok ( immutable_files_range. zip ( file_downloader_uris) . collect ( ) )
50
- }
51
- ImmutablesLocation :: Unknown => {
52
- Err ( anyhow ! ( "Unknown location type to download immutable" ) )
53
- }
54
- }
55
- }
56
-
57
23
/// Get the URI as a string
58
24
pub fn as_str ( & self ) -> & str {
59
25
match self {
@@ -271,58 +237,8 @@ pub trait FileDownloader: Sync + Send {
271
237
272
238
#[ cfg( test) ]
273
239
mod tests {
274
- use mithril_common:: entities:: { MultiFilesUri , TemplateUri } ;
275
-
276
240
use super :: * ;
277
241
278
- #[ test]
279
- fn immutable_files_location_to_file_downloader_uris ( ) {
280
- let immutable_files_location = ImmutablesLocation :: CloudStorage {
281
- uri : MultiFilesUri :: Template ( TemplateUri (
282
- "http://whatever/{immutable_file_number}.tar.gz" . to_string ( ) ,
283
- ) ) ,
284
- compression_algorithm : Some ( CompressionAlgorithm :: Gzip ) ,
285
- } ;
286
- let immutable_files_range: Vec < ImmutableFileNumber > = ( 1 ..=3 ) . collect ( ) ;
287
-
288
- let file_downloader_uris =
289
- FileDownloaderUri :: expand_immutable_files_location_to_file_downloader_uris (
290
- & immutable_files_location,
291
- & immutable_files_range,
292
- )
293
- . unwrap ( ) ;
294
-
295
- assert_eq ! (
296
- file_downloader_uris,
297
- vec![
298
- (
299
- 1 ,
300
- FileDownloaderUri :: FileUri ( FileUri ( "http://whatever/00001.tar.gz" . to_string( ) ) )
301
- ) ,
302
- (
303
- 2 ,
304
- FileDownloaderUri :: FileUri ( FileUri ( "http://whatever/00002.tar.gz" . to_string( ) ) )
305
- ) ,
306
- (
307
- 3 ,
308
- FileDownloaderUri :: FileUri ( FileUri ( "http://whatever/00003.tar.gz" . to_string( ) ) )
309
- ) ,
310
- ]
311
- ) ;
312
- }
313
-
314
- #[ test]
315
- fn immutable_files_location_to_file_downloader_uris_return_error_when_location_is_unknown ( ) {
316
- let immutable_files_location = ImmutablesLocation :: Unknown ;
317
- let immutable_files_range: Vec < ImmutableFileNumber > = ( 1 ..=1 ) . collect ( ) ;
318
-
319
- FileDownloaderUri :: expand_immutable_files_location_to_file_downloader_uris (
320
- & immutable_files_location,
321
- & immutable_files_range,
322
- )
323
- . expect_err ( "expand_immutable_files_location_to_file_downloader_uris should fail" ) ;
324
- }
325
-
326
242
#[ test]
327
243
fn download_event_type_builds_started_event ( ) {
328
244
let download_event_type = DownloadEvent :: Immutable {
0 commit comments