Compare commits

..

No commits in common. "a0fa50dfcd5f31837ca2d5d67ad0cfcbf8bfecb4" and "75d5d08ee1f46b238d6efe3f3f39cc6b9a8d3856" have entirely different histories.

View file

@ -426,10 +426,8 @@ where
// Drop the first key if needed // Drop the first key if needed
// Only AfterKey requires it according to the S3 spec and our implem. // Only AfterKey requires it according to the S3 spec and our implem.
match (&cursor, iter.peek()) { match (&cursor, iter.peek()) {
(RangeBegin::AfterKey { key }, Some(object)) if &object.key == key => { (RangeBegin::AfterKey { key }, Some(object)) if &object.key == key => iter.next(),
iter.next(); (_, _) => None,
}
_ => (),
}; };
while let Some(object) = iter.peek() { while let Some(object) = iter.peek() {
@ -438,22 +436,16 @@ where
return Ok(None); return Ok(None);
} }
match acc.extract(query, &cursor, &mut iter) { cursor = match acc.extract(query, &cursor, &mut iter) {
ExtractionResult::Extracted { key } => { ExtractionResult::Extracted { key } => RangeBegin::AfterKey { key },
cursor = RangeBegin::AfterKey { key };
}
ExtractionResult::SkipTo { key, fallback_key } => { ExtractionResult::SkipTo { key, fallback_key } => {
cursor = RangeBegin::IncludingKey { key, fallback_key }; RangeBegin::IncludingKey { key, fallback_key }
} }
ExtractionResult::FilledAtUpload { key, upload } => { ExtractionResult::FilledAtUpload { key, upload } => {
return Ok(Some(RangeBegin::AfterUpload { key, upload })); return Ok(Some(RangeBegin::AfterUpload { key, upload }))
}
ExtractionResult::Filled => {
return Ok(Some(cursor));
}
ExtractionResult::NoMore => {
return Ok(None);
} }
ExtractionResult::Filled => return Ok(Some(cursor)),
ExtractionResult::NoMore => return Ok(None),
}; };
} }
@ -527,8 +519,8 @@ fn fetch_part_info<'a>(
/// This key can be the prefix in the base case, or intermediate /// This key can be the prefix in the base case, or intermediate
/// points in the dataset if we are continuing a previous listing. /// points in the dataset if we are continuing a previous listing.
impl ListObjectsQuery { impl ListObjectsQuery {
fn build_accumulator(&self) -> ObjectAccumulator { fn build_accumulator(&self) -> Accumulator<String, ObjectInfo> {
ObjectAccumulator::new(self.common.page_size) Accumulator::<String, ObjectInfo>::new(self.common.page_size)
} }
fn begin(&self) -> Result<RangeBegin, Error> { fn begin(&self) -> Result<RangeBegin, Error> {
@ -537,10 +529,9 @@ impl ListObjectsQuery {
// In V2 mode, the continuation token is defined as an opaque // In V2 mode, the continuation token is defined as an opaque
// string in the spec, so we can do whatever we want with it. // string in the spec, so we can do whatever we want with it.
// In our case, it is defined as either [ or ] (for include // In our case, it is defined as either [ or ] (for include
// or exclude), followed by a base64-encoded string
// representing the key to start with. // representing the key to start with.
(Some(token), _) => match &token.get(..1) { (Some(token), _) => match &token[..1] {
Some("[") => Ok(RangeBegin::IncludingKey { "[" => Ok(RangeBegin::IncludingKey {
key: String::from_utf8( key: String::from_utf8(
BASE64_STANDARD BASE64_STANDARD
.decode(token[1..].as_bytes()) .decode(token[1..].as_bytes())
@ -548,7 +539,7 @@ impl ListObjectsQuery {
)?, )?,
fallback_key: None, fallback_key: None,
}), }),
Some("]") => Ok(RangeBegin::AfterKey { "]" => Ok(RangeBegin::AfterKey {
key: String::from_utf8( key: String::from_utf8(
BASE64_STANDARD BASE64_STANDARD
.decode(token[1..].as_bytes()) .decode(token[1..].as_bytes())
@ -589,8 +580,8 @@ impl ListObjectsQuery {
} }
impl ListMultipartUploadsQuery { impl ListMultipartUploadsQuery {
fn build_accumulator(&self) -> UploadAccumulator { fn build_accumulator(&self) -> Accumulator<Uuid, UploadInfo> {
UploadAccumulator::new(self.common.page_size) Accumulator::<Uuid, UploadInfo>::new(self.common.page_size)
} }
fn begin(&self) -> Result<RangeBegin, Error> { fn begin(&self) -> Result<RangeBegin, Error> {
@ -674,7 +665,6 @@ impl<K: std::cmp::Ord, V> Accumulator<K, V> {
Some(p) => p, Some(p) => p,
None => return None, None => return None,
}; };
assert!(pfx.starts_with(&query.prefix));
// Try to register this prefix // Try to register this prefix
// If not possible, we can return early // If not possible, we can return early
@ -685,11 +675,8 @@ impl<K: std::cmp::Ord, V> Accumulator<K, V> {
// We consume the whole common prefix from the iterator // We consume the whole common prefix from the iterator
let mut last_pfx_key = &object.key; let mut last_pfx_key = &object.key;
loop { loop {
match objects.peek() { last_pfx_key = match objects.peek() {
Some(o) if o.key.starts_with(pfx) => { Some(o) if o.key.starts_with(pfx) => &o.key,
last_pfx_key = &o.key;
objects.next();
}
Some(_) => { Some(_) => {
return Some(ExtractionResult::Extracted { return Some(ExtractionResult::Extracted {
key: last_pfx_key.to_owned(), key: last_pfx_key.to_owned(),
@ -705,6 +692,8 @@ impl<K: std::cmp::Ord, V> Accumulator<K, V> {
} }
} }
}; };
objects.next();
} }
} }
@ -719,11 +708,12 @@ impl<K: std::cmp::Ord, V> Accumulator<K, V> {
} }
// Otherwise, we need to check if we can add it // Otherwise, we need to check if we can add it
if self.is_full() { match self.is_full() {
false true => false,
} else { false => {
self.common_prefixes.insert(key); self.common_prefixes.insert(key);
true true
}
} }
} }
@ -731,11 +721,12 @@ impl<K: std::cmp::Ord, V> Accumulator<K, V> {
// It is impossible to add twice a key, this is an error // It is impossible to add twice a key, this is an error
assert!(!self.keys.contains_key(&key)); assert!(!self.keys.contains_key(&key));
if self.is_full() { match self.is_full() {
false true => false,
} else { false => {
self.keys.insert(key, value); self.keys.insert(key, value);
true true
}
} }
} }
} }
@ -752,7 +743,6 @@ impl ExtractAccumulator for ObjectAccumulator {
} }
let object = objects.next().expect("This iterator can not be empty as it is checked earlier in the code. This is a logic bug, please report it."); let object = objects.next().expect("This iterator can not be empty as it is checked earlier in the code. This is a logic bug, please report it.");
assert!(object.key.starts_with(&query.prefix));
let version = match object.versions().iter().find(|x| x.is_data()) { let version = match object.versions().iter().find(|x| x.is_data()) {
Some(v) => v, Some(v) => v,