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.
This commit is contained in:
Andrew Gaul 2017-10-30 12:44:25 -07:00
parent b95809046a
commit c61e8bc28b
3 changed files with 10 additions and 8 deletions

View File

@ -220,8 +220,15 @@ public class AtmosBlobStore extends BaseBlobStore {
@Override
public PageSet<? extends StorageMetadata> 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<? extends StorageMetadata> list = container2ResourceList.apply(sync.listDirectory(container,

View File

@ -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");
}
}

View File

@ -310,7 +310,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
add15UnderRoot(containerName);
awaitConsistency();
PageSet<? extends StorageMetadata> 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 {