From 1cb082297218532510f32a77a36915a97a09c192 Mon Sep 17 00:00:00 2001 From: Timur Alperovich Date: Thu, 25 Jun 2015 15:16:52 -0700 Subject: [PATCH] JCLOUDS-930: Add prefix option to OpenStack Swift. Plumbs the prefix option to the openstack-swift provider. In the process, the support for the recursive option is modified to avoid setting the _path_ parameter, but rather use the delimiter if required (setting the delimiter is sufficient for a non-recursive listing). --- .../blobstore/functions/ToListContainerOptions.java | 13 ++++++++----- .../integration/SwiftContainerLiveTest.java | 6 ------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/functions/ToListContainerOptions.java b/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/functions/ToListContainerOptions.java index 2650f5b389..fbfb0c9bf3 100644 --- a/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/functions/ToListContainerOptions.java +++ b/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/functions/ToListContainerOptions.java @@ -28,12 +28,12 @@ public class ToListContainerOptions implements @Override public org.jclouds.openstack.swift.v1.options.ListContainerOptions apply(ListContainerOptions from) { checkNotNull(from, "set options to instance NONE instead of passing null"); - org.jclouds.openstack.swift.v1.options.ListContainerOptions options = new org.jclouds.openstack.swift.v1.options.ListContainerOptions(); - if ((from.getDir() == null) && (from.isRecursive())) { - options.prefix(""); + if (from.getDir() != null && from.getPrefix() != null) { + throw new IllegalArgumentException("Cannot set both directory and prefix"); } - if ((from.getDir() == null) && (!from.isRecursive())) { - options.path(""); + org.jclouds.openstack.swift.v1.options.ListContainerOptions options = new org.jclouds.openstack.swift.v1.options.ListContainerOptions(); + if (from.getDir() == null && !from.isRecursive()) { + options.delimiter('/'); } if ((from.getDir() != null) && (from.isRecursive())) { options.prefix(from.getDir().endsWith("/") ? from.getDir() : from.getDir() + "/"); @@ -41,6 +41,9 @@ public class ToListContainerOptions implements if ((from.getDir() != null) && (!from.isRecursive())) { options.path(from.getDir()); } + if (from.getPrefix() != null) { + options.prefix(from.getPrefix()); + } if (from.getMarker() != null) { options.marker(from.getMarker()); } diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftContainerLiveTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftContainerLiveTest.java index c2fd8003d1..9bd85d6f5f 100644 --- a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftContainerLiveTest.java +++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftContainerLiveTest.java @@ -21,7 +21,6 @@ import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CRED import java.util.Properties; import org.jclouds.blobstore.integration.internal.BaseContainerLiveTest; -import org.testng.SkipException; import org.testng.annotations.Test; @Test(groups = "live", testName = "SwiftContainerLiveTest") @@ -37,9 +36,4 @@ public class SwiftContainerLiveTest extends BaseContainerLiveTest { setIfTestSystemPropertyPresent(props, CREDENTIAL_TYPE); return props; } - - @Override - public void testContainerListWithPrefix() { - throw new SkipException("Prefix option has not been plumbed down to Swift"); - } }