From c61e8bc28b75687375c503de080498633e999856 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Mon, 30 Oct 2017 12:44:25 -0700 Subject: [PATCH] Implement partial prefix support for Atmos Atmos only supports listing by directories while other blobstores allow listing via arbitrary prefixes. Allow requests which list directories via both prefix and delimiter = "/" to succeed instead of failing all requests. Also change a test which specified recursive to instead be delimiter = "/". Fixes gaul/s3proxy#244. --- .../java/org/jclouds/atmos/blobstore/AtmosBlobStore.java | 9 ++++++++- .../integration/AtmosContainerIntegrationLiveTest.java | 7 +------ .../internal/BaseContainerIntegrationTest.java | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobStore.java b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobStore.java index 1550932609..ca84fe896c 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobStore.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobStore.java @@ -220,8 +220,15 @@ public class AtmosBlobStore extends BaseBlobStore { @Override public PageSet list(String container, org.jclouds.blobstore.options.ListContainerOptions options) { - checkArgument(Strings.isNullOrEmpty(options.getPrefix()), "does not support prefixes"); + // TODO: recursive? + if (!Strings.nullToEmpty(options.getDelimiter()).equals("/") && !Strings.isNullOrEmpty(options.getPrefix())) { + throw new IllegalArgumentException("Atmos can only list via prefix if delimiter is / and the prefix matches an existing directory"); + } container = AtmosUtils.adjustContainerIfDirOptionPresent(container, options); + if (!Strings.isNullOrEmpty(options.getPrefix())) { + // this only works when the prefix exactly matches a directory, the common usage + container += "/" + options.getPrefix(); + } ListOptions nativeOptions = container2ContainerListOptions.apply(options); // until includeMeta() option works for namespace interface PageSet list = container2ResourceList.apply(sync.listDirectory(container, diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosContainerIntegrationLiveTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosContainerIntegrationLiveTest.java index c29f80cf90..4814918e1f 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosContainerIntegrationLiveTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosContainerIntegrationLiveTest.java @@ -58,16 +58,11 @@ public class AtmosContainerIntegrationLiveTest extends BaseContainerIntegrationT @Override public void testContainerListWithPrefix() { - throw new SkipException("Prefix option has not been plumbed down to Atmos"); + throw new SkipException("Atmos can only list prefix which matches an existing directory"); } @Override public void testDelimiterList() { throw new SkipException("Delimiter support is not yet implemented"); } - - @Override - public void testListContainerPrefix() throws InterruptedException { - throw new SkipException("Prefix support is not yet implemented"); - } } diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseContainerIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseContainerIntegrationTest.java index e6cb0ae158..554c75a65a 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseContainerIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseContainerIntegrationTest.java @@ -310,7 +310,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest { add15UnderRoot(containerName); awaitConsistency(); PageSet container = view.getBlobStore().list( - containerName, new ListContainerOptions().recursive().prefix(prefix)); + containerName, new ListContainerOptions().prefix(prefix).delimiter("/")); assert container.getNextMarker() == null; assertEquals(container.size(), 10); } finally {