From cee81b6812042c009a417cd9fb8069f8e40b9485 Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Thu, 5 Oct 2023 10:38:58 +0200 Subject: [PATCH] Make object store structures more resilient Signed-off-by: Tomasz Pietrek --- async-nats/src/jetstream/object_store/mod.rs | 21 +++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/async-nats/src/jetstream/object_store/mod.rs b/async-nats/src/jetstream/object_store/mod.rs index d16a72dc9..a719c5cda 100644 --- a/async-nats/src/jetstream/object_store/mod.rs +++ b/async-nats/src/jetstream/object_store/mod.rs @@ -130,9 +130,11 @@ impl ObjectStore { let bucket = self .stream .context - .get_object_store(&link_name) + .get_object_store(&link.bucket) .await - .map_err(|err| GetError::with_source(GetErrorKind::Other, err))?; + .map_err(|err| { + GetError::with_source(GetErrorKind::Other, err) + })?; let object = bucket.get(&link_name).await?; return Ok(object); } @@ -349,7 +351,7 @@ impl ObjectStore { chunks: object_chunks, size: object_size, digest: Some(format!("SHA-256={}", URL_SAFE.encode(digest))), - modified: OffsetDateTime::now_utc(), + modified: Some(OffsetDateTime::now_utc()), deleted: false, }; @@ -712,7 +714,7 @@ impl ObjectStore { nuid: nuid::next().to_string(), size: 0, chunks: 0, - modified: OffsetDateTime::now_utc(), + modified: Some(OffsetDateTime::now_utc()), digest: None, deleted: false, }; @@ -775,7 +777,7 @@ impl ObjectStore { nuid: nuid::next().to_string(), size: 0, chunks: 0, - modified: OffsetDateTime::now_utc(), + modified: Some(OffsetDateTime::now_utc()), digest: None, deleted: false, }; @@ -1063,21 +1065,26 @@ pub struct ObjectInfo { /// Name of the object pub name: String, /// A short human readable description of the object. + #[serde(default)] pub description: Option, /// Link this object points to, if any. + #[serde(default)] pub options: Option, /// Name of the bucket the object is stored in. pub bucket: String, /// Unique identifier used to uniquely identify this version of the object. + #[serde(default)] pub nuid: String, /// Size in bytes of the object. + #[serde(default)] pub size: usize, /// Number of chunks the object is stored in. + #[serde(default)] pub chunks: usize, /// Date and time the object was last modified. - #[serde(with = "rfc3339")] + #[serde(default, with = "rfc3339::option")] #[serde(rename = "mtime")] - pub modified: time::OffsetDateTime, + pub modified: Option, /// Digest of the object stream. #[serde(default, skip_serializing_if = "Option::is_none")] pub digest: Option,