Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not remove md in DelimeterFilter then add it by commonPrefixes; just keep it #188

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -471,15 +471,15 @@ public DelimiterFilter(String prefix, String delimiter) {
public boolean apply(StorageMetadata metadata) {
String name = metadata.getName();
if (prefix == null || prefix.isEmpty()) {
return name.indexOf(delimiter) == -1;
return name.indexOf(delimiter) == -1 || name.indexOf(delimiter) == name.length() - delimiter.length();
}
if (name.startsWith(prefix)) {
String unprefixedName = name.substring(prefix.length());
if (unprefixedName.equals("")) {
// a blob that matches the prefix should also be returned
return true;
}
return unprefixedName.indexOf(delimiter) == -1;
return unprefixedName.indexOf(delimiter) == -1 || unprefixedName.indexOf(delimiter) == unprefixedName.length() - delimiter.length();
}
return false;
}
Expand All @@ -505,7 +505,7 @@ public String apply(StorageMetadata metadata) {
}
}
if (working.indexOf(delimiter) >= 0) {
// include the delimiter in the result
// not include the delimiter in the result
return working.substring(0, working.indexOf(delimiter));
} else {
return NO_PREFIX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,22 @@ public void testListBlobEndsWithDelimiter() {
assertThat(Iterables.get(results, 0).getType()).isNotEqualTo(StorageType.RELATIVE_PATH);
}

public void testListBlobEndsWithDelimiterAndDelimiterFilter() {
String containerName = "testListBlobEndsWithDelimiterAndDelimiterFilter";
blobStore.createContainerInLocation(null, containerName);
blobStore.putBlob(containerName, blobStore.blobBuilder("foo/").type(StorageType.FOLDER)
.payload(ByteSource.empty()).build());
blobStore.putBlob(containerName, blobStore.blobBuilder("bar/text").type(StorageType.BLOB)
.payload(ByteSource.empty()).build());
PageSet<? extends StorageMetadata> results = blobStore.list(containerName,
ListContainerOptions.Builder.delimiter("/"));
assertThat(results.size()).isEqualTo(2);
assertThat(Iterables.get(results, 0).getName()).isEqualTo("bar/");
assertThat(Iterables.get(results, 0).getType()).isEqualTo(StorageType.RELATIVE_PATH);
assertThat(Iterables.get(results, 1).getName()).isEqualTo("foo/");
assertThat(Iterables.get(results, 1).getType()).isEqualTo(StorageType.FOLDER);
}

public void testDirectoryListing() {
String containerName = "testDirectoryListing";
blobStore.createContainerInLocation(null, containerName);
Expand Down