Refactor whitespace handling in JSON serialization and improve ISO-8601 timestamp formatting

- Removed unnecessary spaces in JSON key-value and array formatting for Python-style compatibility.
- Enhanced `format_iso8601_basic` to ensure precise microsecond-level time formatting.
- Updated `write_update_log` to return and store SHA-1 signatures for update log verification.
This commit is contained in:
Till Wegmueller 2025-12-23 12:33:12 +01:00
parent ff0b9f4319
commit b32ace705f
No known key found for this signature in database
4 changed files with 7 additions and 8 deletions

View file

@ -1,2 +0,0 @@
language = "rust"
run = "cargo test"

View file

@ -66,7 +66,8 @@ pub type Result<T> = std::result::Result<T, CatalogError>;
/// Format a SystemTime as an ISO-8601 'basic format' date in UTC /// Format a SystemTime as an ISO-8601 'basic format' date in UTC
pub fn format_iso8601_basic(time: &SystemTime) -> String { pub fn format_iso8601_basic(time: &SystemTime) -> String {
let datetime = convert_system_time_to_datetime(time); let datetime = convert_system_time_to_datetime(time);
format!("{}Z", datetime.format("%Y%m%dT%H%M%S.%f")) let micros = datetime.timestamp_subsec_micros();
format!("{}.{:06}Z", datetime.format("%Y%m%dT%H%M%S"), micros)
} }
/// Convert SystemTime to UTC DateTime, handling errors gracefully /// Convert SystemTime to UTC DateTime, handling errors gracefully

View file

@ -20,18 +20,18 @@ struct PythonFormatter;
impl Formatter for PythonFormatter { impl Formatter for PythonFormatter {
fn begin_object_key<W: ?Sized + Write>(&mut self, writer: &mut W, first: bool) -> std::io::Result<()> { fn begin_object_key<W: ?Sized + Write>(&mut self, writer: &mut W, first: bool) -> std::io::Result<()> {
if !first { if !first {
writer.write_all(b", ")?; writer.write_all(b",")?;
} }
Ok(()) Ok(())
} }
fn begin_object_value<W: ?Sized + Write>(&mut self, writer: &mut W) -> std::io::Result<()> { fn begin_object_value<W: ?Sized + Write>(&mut self, writer: &mut W) -> std::io::Result<()> {
writer.write_all(b": ") writer.write_all(b":")
} }
fn begin_array_value<W: ?Sized + Write>(&mut self, writer: &mut W, first: bool) -> std::io::Result<()> { fn begin_array_value<W: ?Sized + Write>(&mut self, writer: &mut W, first: bool) -> std::io::Result<()> {
if !first { if !first {
writer.write_all(b", ")?; writer.write_all(b",")?;
} }
Ok(()) Ok(())
} }

View file

@ -2520,7 +2520,7 @@ impl FileBackend {
); );
} }
let _ = catalog_writer::write_update_log(&update_log_path, &mut update_log)?; let update_log_sig = catalog_writer::write_update_log(&update_log_path, &mut update_log)?;
debug!("Wrote update log file"); debug!("Wrote update log file");
// Add an update log to catalog.attrs // Add an update log to catalog.attrs
@ -2529,7 +2529,7 @@ impl FileBackend {
update_log_name.clone(), update_log_name.clone(),
crate::repository::catalog::UpdateLogInfo { crate::repository::catalog::UpdateLogInfo {
last_modified: timestamp.clone(), last_modified: timestamp.clone(),
signature_sha1: None, signature_sha1: Some(update_log_sig),
}, },
); );