From f4cadad6ef06e237b9ae5f98aa5692d304e544f7 Mon Sep 17 00:00:00 2001 From: Bala FA Date: Mon, 5 Jun 2023 02:52:11 +0530 Subject: [PATCH] list_objects(): fix user metadata as per MinIO server (#30) Signed-off-by: Bala.FA --- Cargo.toml | 1 - src/s3/client.rs | 18 ++++++++++-------- src/s3/utils.rs | 25 ++++++++++++++++++++++--- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ccd89d5..4c0bce9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ urlencoding = "2.1.0" lazy_static = "1.4.0" regex = "1.5.6" chrono = "0.4.19" -chrono_locale = "0.1.1" sha2 = "0.10.2" base64 = "0.13.0" md5 = "0.7.0" diff --git a/src/s3/client.rs b/src/s3/client.rs index c8ec833..4601b55 100644 --- a/src/s3/client.rs +++ b/src/s3/client.rs @@ -118,7 +118,7 @@ fn parse_list_objects_contents( is_delete_marker: bool, ) -> Result<(), Error> { loop { - let mut content = match root.take_child(tag) { + let content = match root.take_child(tag) { Some(v) => v, None => break, }; @@ -142,15 +142,17 @@ fn parse_list_objects_contents( ), None => (None, None), }; - let user_metadata = match content.get_mut_child("UserMetadata") { + let user_metadata = match content.get_child("UserMetadata") { Some(v) => { let mut map: HashMap = HashMap::new(); - loop { - let item = match v.take_child("Items") { - Some(v) => v, - None => break, - }; - map.insert(get_text(&item, "Key")?, get_text(&item, "Value")?); + for xml_node in &v.children { + let u = xml_node + .as_element() + .ok_or(Error::XmlError(format!("unable to convert to element")))?; + map.insert( + u.name.to_string(), + u.get_text().unwrap_or_default().to_string(), + ); } Some(map) } diff --git a/src/s3/utils.rs b/src/s3/utils.rs index 15e5ecf..323dc71 100644 --- a/src/s3/utils.rs +++ b/src/s3/utils.rs @@ -16,8 +16,7 @@ use crate::s3::error::Error; pub use base64::encode as b64encode; use byteorder::{BigEndian, ReadBytesExt}; -use chrono::{DateTime, NaiveDateTime, ParseError, Utc}; -use chrono_locale::LocaleDate; +use chrono::{DateTime, Datelike, NaiveDateTime, ParseError, Utc}; use crc::{Crc, CRC_32_ISO_HDLC}; use lazy_static::lazy_static; use md5::compute as md5compute; @@ -72,7 +71,27 @@ pub fn to_amz_date(time: UtcTime) -> String { } pub fn to_http_header_value(time: UtcTime) -> String { - time.formatl("%a, %d %b %Y %H:%M:%S GMT", "C").to_string() + format!( + "{}, {} {} {} GMT", + time.weekday(), + time.day(), + match time.month() { + 1 => "Jan", + 2 => "Feb", + 3 => "Mar", + 4 => "Apr", + 5 => "May", + 6 => "Jun", + 7 => "Jul", + 8 => "Aug", + 9 => "Sep", + 10 => "Oct", + 11 => "Nov", + 12 => "Dec", + _ => "", + }, + time.format("%Y %H:%M:%S").to_string() + ) } pub fn to_iso8601utc(time: UtcTime) -> String {