@@ -27,6 +27,9 @@ use std::sync::Arc;
2727use tempfile:: Builder ;
2828use toml:: Table ;
2929use std:: fs:: read_to_string;
30+ use futures:: Stream ;
31+ use futures:: stream:: StreamExt ;
32+ use azure_storage_blobs:: container:: operations:: BlobItem ;
3033
3134#[ derive( Deserialize ) ]
3235struct AzureConfig {
@@ -306,6 +309,33 @@ async fn azure_set_filename_tags(filename: String, user_tags: Vec<(String, Strin
306309 }
307310}
308311
312+ async fn azure_list_files ( directory : String ) -> Vec < String > {
313+ let azure_cfg = Arc :: new ( get_azure_credentials ( "azure" ) ) ;
314+ let storage_account = azure_cfg. account . as_str ( ) ;
315+ let storage_key = azure_cfg. key . clone ( ) ;
316+ let storage_container = azure_cfg. container . as_str ( ) ;
317+ let storage_credential = StorageCredentials :: access_key ( storage_account, storage_key) ;
318+ let container_r = ClientBuilder :: new ( storage_account, storage_credential)
319+ . container_client ( storage_container) ;
320+ let listbldr = container_r. list_blobs ( ) ;
321+ let mut liststream = listbldr. into_stream ( ) ;
322+ let mut listing = Vec :: new ( ) ;
323+ while let Some ( Ok ( page) ) = liststream. next ( ) . await {
324+ let blobs = page. blobs . items ;
325+ for blob in blobs {
326+ let blob_name = match blob {
327+ BlobItem :: Blob ( blob) => blob. name ,
328+ BlobItem :: BlobPrefix ( blob_prefix) => blob_prefix. name ,
329+ } ;
330+ listing. push ( blob_name. clone ( ) ) ;
331+
332+ }
333+ println ! ( "Listing count: {}" , listing. len( ) ) ;
334+ }
335+ //println!("Listing: {:?}", listing);
336+ return listing;
337+ }
338+
309339/// Implement Driver trait for AzureDriver
310340impl super :: Driver for AzureDriver {
311341 fn write_file ( & self , filename : String , data : Vec < u8 > , cont_type : String ) -> String {
@@ -336,4 +366,12 @@ impl super::Driver for AzureDriver {
336366 } ) ;
337367 return received_file;
338368 }
369+ fn list_files ( & self , directory : String ) -> Vec < String > {
370+ let mut ret = Vec :: new ( ) ;
371+ tokio:: task:: block_in_place ( || {
372+ let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
373+ ret = rt. block_on ( azure_list_files ( directory) ) ;
374+ } ) ;
375+ return ret;
376+ }
339377}
0 commit comments