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 98c006d9a7..77cee20861 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java @@ -343,8 +343,9 @@ public final class LocalBlobStore implements BlobStore { } })); - if (options.getDelimiter() != null) { - return extractCommonPrefixes(contents, options.getDelimiter(), options.getPrefix()); + if (options.getDelimiter() != null || !options.isRecursive()) { + String delimiter = options.getDelimiter() == null ? storageStrategy.getSeparator() : options.getDelimiter(); + return extractCommonPrefixes(contents, delimiter, options.getPrefix()); } return contents; 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 421cb2dc15..cb9f79e0a1 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 @@ -72,7 +72,7 @@ public class ListContainerTest { blobStore.putBlob(containerName, blobStore.blobBuilder("bar").payload("").build()); Iterable results = concatter.execute(containerName, - ListContainerOptions.Builder.prefix(prefix).recursive()); + ListContainerOptions.Builder.prefix(prefix)./* irrelevant */recursive()); assertThat(results).hasSize(3); assertThat(Iterables.get(results, 0).getName()).isEqualTo(prefix); assertThat(Iterables.get(results, 0).getType()).isEqualTo(StorageType.BLOB); @@ -126,6 +126,28 @@ public class ListContainerTest { assertThat(Iterables.get(results, 2).getName()).isEqualTo(prefix + "baz/object"); } + public void testListRecursivePrefixDelimiter() { + String containerName = "testListRecursivePrefixDelimiter"; + String prefix = "foo/"; + blobStore.createContainerInLocation(null, containerName); + blobStore.putBlob(containerName, blobStore.blobBuilder(prefix + "object").payload("").build()); + blobStore.putBlob(containerName, blobStore.blobBuilder(prefix + "bar/object").payload("") + .build()); + blobStore.putBlob(containerName, blobStore.blobBuilder(prefix + "baz/object").payload("") + .build()); + blobStore.putBlob(containerName, blobStore.blobBuilder("bar/object").payload("").build()); + + Iterable results = concatter.execute(containerName, + ListContainerOptions.Builder.prefix(prefix)); + assertThat(results).hasSize(3); + assertThat(Iterables.get(results, 0).getType()).isEqualTo(StorageType.RELATIVE_PATH); + assertThat(Iterables.get(results, 0).getName()).isEqualTo(prefix + "bar/"); + assertThat(Iterables.get(results, 1).getType()).isEqualTo(StorageType.RELATIVE_PATH); + assertThat(Iterables.get(results, 1).getName()).isEqualTo(prefix + "baz/"); + assertThat(Iterables.get(results, 2).getType()).isEqualTo(StorageType.BLOB); + assertThat(Iterables.get(results, 2).getName()).isEqualTo(prefix + "object"); + } + public void testListDirectory() { String containerName = "testListDir"; String directory = "dir";