From 360236d2311bb98256f026274812479a5e3f9661 Mon Sep 17 00:00:00 2001 From: Peter Winckles Date: Thu, 15 Jul 2021 06:59:14 -0500 Subject: [PATCH] fix prefix offset when not using an s3 prefix --- src/ocfl/store/s3.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ocfl/store/s3.rs b/src/ocfl/store/s3.rs index 483d867..c0c5f81 100644 --- a/src/ocfl/store/s3.rs +++ b/src/ocfl/store/s3.rs @@ -595,18 +595,23 @@ impl S3Client { ..Default::default() }))?; + let prefix_offset = if self.prefix.is_empty() { + 0 + } else { + self.prefix.len() + 1 + }; + if let Some(contents) = &result.contents { for object in contents { - objects.push(object.key.as_ref().unwrap()[self.prefix.len() + 1..].to_owned()); + objects.push(object.key.as_ref().unwrap()[prefix_offset..].to_owned()); } } if let Some(prefixes) = &result.common_prefixes { for prefix in prefixes { let length = prefix.prefix.as_ref().unwrap().len() - 1; - directories.push( - prefix.prefix.as_ref().unwrap()[self.prefix.len() + 1..length].to_owned(), - ); + directories + .push(prefix.prefix.as_ref().unwrap()[prefix_offset..length].to_owned()); } }