mirror of https://github.com/apache/jclouds.git
LocalBlobStore: list marker blobs with delimiters.
When the delimiter option is specified, local blob store should behave similarly to swift and return the directory marker blobs (directory blobs) and the common prefix. This undoes the filtering we were previously doing.
This commit is contained in:
parent
6d27fbb18a
commit
669feb4d0c
|
@ -353,7 +353,7 @@ public final class LocalBlobStore implements BlobStore {
|
|||
transform(contents, new CommonPrefixes(prefix, delimiter)));
|
||||
commonPrefixes.remove(CommonPrefixes.NO_PREFIX);
|
||||
|
||||
contents = newTreeSet(filter(contents, new DelimiterFilter(prefix, delimiter, commonPrefixes)));
|
||||
contents = newTreeSet(filter(contents, new DelimiterFilter(prefix, delimiter)));
|
||||
|
||||
for (String o : commonPrefixes) {
|
||||
MutableStorageMetadata md = new MutableStorageMetadataImpl();
|
||||
|
@ -457,20 +457,15 @@ public final class LocalBlobStore implements BlobStore {
|
|||
private static class DelimiterFilter implements Predicate<StorageMetadata> {
|
||||
private final String prefix;
|
||||
private final String delimiter;
|
||||
private final Set<String> commonPrefixes;
|
||||
|
||||
public DelimiterFilter(String prefix, String delimiter, final Set<String> commonPrefixes) {
|
||||
public DelimiterFilter(String prefix, String delimiter) {
|
||||
this.prefix = prefix;
|
||||
this.delimiter = delimiter;
|
||||
this.commonPrefixes = commonPrefixes;
|
||||
}
|
||||
|
||||
public boolean apply(StorageMetadata metadata) {
|
||||
String name = metadata.getName();
|
||||
if (prefix == null || prefix.isEmpty()) {
|
||||
if (commonPrefixes.contains(name)) {
|
||||
return false;
|
||||
}
|
||||
return name.indexOf(delimiter) == -1;
|
||||
}
|
||||
String prefixMatch;
|
||||
|
@ -482,7 +477,7 @@ public final class LocalBlobStore implements BlobStore {
|
|||
}
|
||||
if (name.matches(prefixMatch)) {
|
||||
String unprefixedName = name.replaceFirst(prefix, "");
|
||||
if (unprefixedName.equals("") || commonPrefixes.contains(unprefixedName)) {
|
||||
if (unprefixedName.equals("")) {
|
||||
// we are the prefix in this case, return false
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -73,11 +73,14 @@
|
|||
(create-directory blobstore-stub "container" "dir")
|
||||
(is (put-blob blobstore-stub "container"
|
||||
(blob "dir/blob2" :payload "blob2")))
|
||||
(is (= 3 (count-blobs blobstore-stub "container")))
|
||||
(is (= 3 (count (blobs blobstore-stub "container"))))
|
||||
(is (= 4 (count (blobs blobstore-stub "container" :recursive true))))
|
||||
(is (= 3 (count (blobs blobstore-stub "container" :with-details true))))
|
||||
(is (= 1 (count (blobs blobstore-stub "container" :in-directory "dir")))))
|
||||
(is (put-blob blobstore-stub "container"
|
||||
(blob "dir/blob3" :payload "blob3")))
|
||||
(is (= 4 (count-blobs blobstore-stub "container")))
|
||||
(is (= 4 (count (blobs blobstore-stub "container"))))
|
||||
(is (= 5 (count (blobs blobstore-stub "container" :recursive true))))
|
||||
(is (= 4 (count (blobs blobstore-stub "container" :with-details true))))
|
||||
;; jclouds will list dir and dir/
|
||||
(is (= 2 (count (blobs blobstore-stub "container" :in-directory "dir")))))
|
||||
|
||||
(deftest large-container-list-test
|
||||
(let [container-name "test"
|
||||
|
|
|
@ -123,8 +123,9 @@ public class ListContainerTest {
|
|||
blobStore.putBlob(containerName, blobStore.blobBuilder(directory + "/foo").payload("").build());
|
||||
blobStore.putBlob(containerName, blobStore.blobBuilder(directory + "/bar").payload("").build());
|
||||
Iterable<? extends StorageMetadata> results = concatter.execute(containerName, ListContainerOptions.NONE);
|
||||
assertThat(results).hasSize(1);
|
||||
assertThat(Iterables.get(results, 0).getName()).isEqualTo(directory + '/');
|
||||
assertThat(results).hasSize(2);
|
||||
assertThat(Iterables.get(results, 0).getName()).isEqualTo(directory);
|
||||
assertThat(Iterables.get(results, 1).getName()).isEqualTo(directory + '/');
|
||||
}
|
||||
|
||||
public void testListMarkers() {
|
||||
|
@ -153,8 +154,9 @@ public class ListContainerTest {
|
|||
blobStore.createDirectory(containerName, "dir/dir");
|
||||
|
||||
PageSet<? extends StorageMetadata> results = blobStore.list(containerName);
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
assertThat(Iterables.get(results, 0).getName()).isEqualTo("dir/");
|
||||
assertThat(results.size()).isEqualTo(2);
|
||||
assertThat(Iterables.get(results, 0).getName()).isEqualTo("dir");
|
||||
assertThat(Iterables.get(results, 1).getName()).isEqualTo("dir/");
|
||||
|
||||
results = blobStore.list(containerName, ListContainerOptions.Builder.inDirectory("dir"));
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
|
@ -162,7 +164,8 @@ public class ListContainerTest {
|
|||
|
||||
blobStore.putBlob(containerName, blobStore.blobBuilder("dir/dir/blob").payload("").build());
|
||||
results = blobStore.list(containerName, ListContainerOptions.Builder.inDirectory("dir"));
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
assertThat(Iterables.get(results, 0).getName()).isEqualTo("dir/dir/");
|
||||
assertThat(results.size()).isEqualTo(2);
|
||||
assertThat(Iterables.get(results, 0).getName()).isEqualTo("dir/dir");
|
||||
assertThat(Iterables.get(results, 1).getName()).isEqualTo("dir/dir/");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue