@@ -40,6 +40,20 @@ use azure_sdk_core::{
40
40
util:: HeaderMapExt ,
41
41
} ;
42
42
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
+
43
57
pub trait BlockListTypeSupport {
44
58
type O ;
45
59
fn with_block_list_type ( self , block_list_type : BlockListType ) -> Self :: O ;
@@ -94,7 +108,10 @@ pub struct Blob {
94
108
pub name : String ,
95
109
pub container_name : String ,
96
110
pub snapshot_time : Option < DateTime < Utc > > ,
111
+ #[ cfg( not( feature = "azurite_workaround" ) ) ]
97
112
pub creation_time : DateTime < Utc > ,
113
+ #[ cfg( feature = "azurite_workaround" ) ]
114
+ pub creation_time : Option < DateTime < Utc > > ,
98
115
pub last_modified : Option < DateTime < Utc > > , // optional because unavailable in uncommitted blobs
99
116
pub etag : Option < String > , // optional because unavailable in uncommitted blobs
100
117
pub content_length : u64 ,
@@ -129,7 +146,12 @@ impl Blob {
129
146
pub ( crate ) fn parse ( elem : & Element , container_name : & str ) -> Result < Blob , AzureError > {
130
147
let name = cast_must :: < String > ( elem, & [ "Name" ] ) ?;
131
148
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" ) ) ]
132
153
let creation_time = cast_must :: < DateTime < Utc > > ( elem, & [ "Properties" , "Creation-Time" ] ) ?;
154
+
133
155
let last_modified = cast_optional :: < DateTime < Utc > > ( elem, & [ "Properties" , "Last-Modified" ] ) ?;
134
156
let etag = cast_optional :: < String > ( elem, & [ "Properties" , "Etag" ] ) ?;
135
157
@@ -252,13 +274,19 @@ impl Blob {
252
274
) -> Result < Blob , AzureError > {
253
275
trace ! ( "\n {:?}" , h) ;
254
276
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) ?;
262
290
263
291
let content_type = h
264
292
. get_as_string ( header:: CONTENT_TYPE )
0 commit comments