diff --git a/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java index abb7bd0d433..5691a3143cb 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java @@ -471,7 +471,7 @@ 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()); @@ -479,7 +479,7 @@ public boolean apply(StorageMetadata metadata) { // 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; } @@ -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; diff --git a/blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/ListContainerTest.java b/blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/ListContainerTest.java index cb9f79e0a19..78af809efe4 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/ListContainerTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/ListContainerTest.java @@ -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 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);