fix non-recursive list with empty prefix

This commit is contained in:
Ka-Hing Cheung 2015-02-20 19:11:03 -08:00 committed by Andrew Gaul
parent 7c9d6f7627
commit be7b9f4cc4
2 changed files with 16 additions and 1 deletions

View File

@ -174,6 +174,21 @@ public class FilesystemBlobStoreTest {
checkForContainerContent(CONTAINER_NAME, blobsExpected);
}
@Test
public void testList_RootNonRecursive() throws IOException {
blobStore.createContainerInLocation(null, CONTAINER_NAME);
// Testing list for an empty container
checkForContainerContent(CONTAINER_NAME, null);
TestUtils.createBlobsInContainer(CONTAINER_NAME, "a");
ListContainerOptions options = ListContainerOptions.Builder
.withDetails()
.inDirectory("");
PageSet<? extends StorageMetadata> res = blobStore.list(CONTAINER_NAME, options);
assertTrue(res.size() == 1);
assertEquals(res.iterator().next().getName(), "a");
}
public void testList_NotExistingContainer() {
// Testing list for a not existing container
try {

View File

@ -408,7 +408,7 @@ public final class LocalBlobStore implements BlobStore {
}
public boolean apply(StorageMetadata metadata) {
if (prefix == null)
if (prefix == null || prefix.isEmpty())
return metadata.getName().indexOf(delimiter) == -1;
// ensure we don't accidentally append twice
String toMatch = prefix.endsWith("/") ? prefix : prefix + delimiter;