Skip to content

Commit

Permalink
s3s-fs: fix path matching and add start_after (#112)
Browse files Browse the repository at this point in the history
This commit adds support for `start_after` and fixes some issues with
`Path::start_with` being more strict than `str::start_with`.
  • Loading branch information
LucioFranco authored Dec 1, 2023
1 parent 54124ba commit aed0cd1
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions crates/s3s-fs/src/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,17 @@ impl S3 for FileSystem {
let file_path = entry.path();
let key = try_!(file_path.strip_prefix(&path));
let delimiter = input.delimiter.as_ref().map_or("/", |d| d.as_str());
let Some(key_str) = normalize_path(key, delimiter) else { continue };
let Some(key_str) = normalize_path(key, delimiter) else {
continue;
};

if let Some(ref prefix) = input.prefix {
let prefix_path: PathBuf = prefix.split(delimiter).collect();
if !key.starts_with(prefix_path) {

let key_s = format!("{}", key.display());
let prefix_path_s = format!("{}", prefix_path.display());

if !key_s.starts_with(&prefix_path_s) {
continue;
}
}
Expand All @@ -389,6 +395,15 @@ impl S3 for FileSystem {
lhs_key.cmp(rhs_key)
});

let objects = if let Some(marker) = &input.start_after {
objects
.into_iter()
.skip_while(|n| n.key.as_deref().unwrap_or("") <= marker.as_str())
.collect()
} else {
objects
};

let key_count = try_!(i32::try_from(objects.len()));

let output = ListObjectsV2Output {
Expand Down

0 comments on commit aed0cd1

Please sign in to comment.