@@ -40,6 +40,20 @@ use azure_sdk_core::{
4040 util:: HeaderMapExt ,
4141} ;
4242
43+ #[ cfg( feature = "azurite_workaround" ) ]
44+ fn get_creation_time ( h : & header:: HeaderMap ) -> Result < Option < DateTime < Utc > > , AzureError > {
45+ if let Some ( creation_time) = h. get ( CREATION_TIME ) {
46+ // Check that the creation time is valid
47+ let creation_time = creation_time. to_str ( ) ?;
48+ let creation_time = DateTime :: parse_from_rfc2822 ( creation_time) ?;
49+ let creation_time = DateTime :: from_utc ( creation_time. naive_utc ( ) , Utc ) ;
50+ Ok ( Some ( creation_time) )
51+ } else {
52+ // Not having a creation time is ok
53+ Ok ( None )
54+ }
55+ }
56+
4357pub trait BlockListTypeSupport {
4458 type O ;
4559 fn with_block_list_type ( self , block_list_type : BlockListType ) -> Self :: O ;
@@ -94,7 +108,10 @@ pub struct Blob {
94108 pub name : String ,
95109 pub container_name : String ,
96110 pub snapshot_time : Option < DateTime < Utc > > ,
111+ #[ cfg( not( feature = "azurite_workaround" ) ) ]
97112 pub creation_time : DateTime < Utc > ,
113+ #[ cfg( feature = "azurite_workaround" ) ]
114+ pub creation_time : Option < DateTime < Utc > > ,
98115 pub last_modified : Option < DateTime < Utc > > , // optional because unavailable in uncommitted blobs
99116 pub etag : Option < String > , // optional because unavailable in uncommitted blobs
100117 pub content_length : u64 ,
@@ -129,7 +146,12 @@ impl Blob {
129146 pub ( crate ) fn parse ( elem : & Element , container_name : & str ) -> Result < Blob , AzureError > {
130147 let name = cast_must :: < String > ( elem, & [ "Name" ] ) ?;
131148 let snapshot_time = cast_optional :: < DateTime < Utc > > ( elem, & [ "Snapshot" ] ) ?;
149+
150+ #[ cfg( feature = "azurite_workaround" ) ]
151+ let creation_time = cast_optional :: < DateTime < Utc > > ( elem, & [ "Properties" , "Creation-Time" ] ) ?;
152+ #[ cfg( not( feature = "azurite_workaround" ) ) ]
132153 let creation_time = cast_must :: < DateTime < Utc > > ( elem, & [ "Properties" , "Creation-Time" ] ) ?;
154+
133155 let last_modified = cast_optional :: < DateTime < Utc > > ( elem, & [ "Properties" , "Last-Modified" ] ) ?;
134156 let etag = cast_optional :: < String > ( elem, & [ "Properties" , "Etag" ] ) ?;
135157
@@ -252,13 +274,19 @@ impl Blob {
252274 ) -> Result < Blob , AzureError > {
253275 trace ! ( "\n {:?}" , h) ;
254276
255- let creation_time = h
256- . get ( CREATION_TIME )
257- . ok_or_else ( || AzureError :: HeaderNotFound ( CREATION_TIME . to_owned ( ) ) ) ?
258- . to_str ( ) ?;
259- let creation_time = DateTime :: parse_from_rfc2822 ( creation_time) ?;
260- let creation_time = DateTime :: from_utc ( creation_time. naive_utc ( ) , Utc ) ;
261- trace ! ( "creation_time == {:?}" , creation_time) ;
277+ #[ cfg( not( feature = "azurite_workaround" ) ) ]
278+ let creation_time = {
279+ let creation_time = h
280+ . get ( CREATION_TIME )
281+ . ok_or_else ( || AzureError :: HeaderNotFound ( CREATION_TIME . to_owned ( ) ) ) ?
282+ . to_str ( ) ?;
283+ let creation_time = DateTime :: parse_from_rfc2822 ( creation_time) ?;
284+ let creation_time = DateTime :: from_utc ( creation_time. naive_utc ( ) , Utc ) ;
285+ trace ! ( "creation_time == {:?}" , creation_time) ;
286+ creation_time
287+ } ;
288+ #[ cfg( feature = "azurite_workaround" ) ]
289+ let creation_time = get_creation_time ( h) ?;
262290
263291 let content_type = h
264292 . get_as_string ( header:: CONTENT_TYPE )
0 commit comments