JCLOUDS-929: Implement delimiter support in S3.

Plumb the delimiter option to the S3 API.
This commit is contained in:
Timur Alperovich 2015-06-09 14:28:29 -07:00 committed by Andrew Gaul
parent 6ec11fd6ec
commit fe13b07233
4 changed files with 16 additions and 17 deletions

View File

@ -24,7 +24,6 @@ import javax.inject.Singleton;
import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.domain.StorageType;
import org.jclouds.blobstore.domain.internal.PageSetImpl;
import org.jclouds.s3.domain.ListBucketResponse;
@ -60,10 +59,7 @@ public class BucketToResourceList implements
Map<String, StorageMetadata> nameToMd = Maps.uniqueIndex(contents, indexer);
for (String prefix : from.getCommonPrefixes()) {
prefix = prefix.endsWith("/") ? prefix.substring(0, prefix.lastIndexOf('/')) : prefix;
if (!nameToMd.containsKey(prefix)
|| nameToMd.get(prefix).getType() != StorageType.RELATIVE_PATH)
contents.add(prefix2ResourceMd.apply(prefix));
contents.add(prefix2ResourceMd.apply(prefix));
}
return new PageSetImpl<StorageMetadata>(contents, from.getNextMarker());
}

View File

@ -36,12 +36,22 @@ public class ContainerToBucketListOptions implements
ListBucketOptions httpOptions = new ListBucketOptions();
if (!from.isRecursive()) {
httpOptions.delimiter("/");
if (from.getDelimiter() != null) {
httpOptions.delimiter(from.getDelimiter().toString());
} else {
httpOptions.delimiter("/");
}
}
if (from.getDir() != null) {// TODO unit test
String path = from.getDir();
if (!path.endsWith("/"))
path = path + "/";
if (from.getDelimiter() != null) {
if (!path.endsWith(from.getDelimiter().toString())) {
path += from.getDelimiter();
}
} else {
if (!path.endsWith("/"))
path = path + "/";
}
httpOptions.withPrefix(path);
}
if (from.getPrefix() != null) {

View File

@ -30,8 +30,8 @@ public class BucketToContainerListOptions implements Function<ListBucketOptions[
if (optionsList.length != 0) {
if (optionsList[0].getDelimiter() == null) {
options.recursive();
} else if (!optionsList[0].getDelimiter().equals("/")) {
throw new IllegalArgumentException("only '/' is allowed as a blobstore delimiter");
} else {
options.delimiter(optionsList[0].getDelimiter());
}
if (optionsList[0].getMarker() != null) {
options.afterMarker(optionsList[0].getMarker());

View File

@ -18,7 +18,6 @@ package org.jclouds.s3.blobstore.integration;
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
import org.jclouds.blobstore.integration.internal.BaseContainerLiveTest;
import org.testng.SkipException;
import org.testng.annotations.Test;
@Test(groups = "live", testName = "S3ContainerLiveTest")
@ -28,10 +27,4 @@ public class S3ContainerLiveTest extends BaseContainerLiveTest {
provider = "s3";
BaseBlobStoreIntegrationTest.SANITY_CHECK_RETURNED_BUCKET_NAME = true;
}
@Override
@Test
public void testDelimiterList() {
throw new SkipException("not yet implemented");
}
}