mirror of
https://github.com/apache/jclouds.git
synced 2025-03-01 05:49:06 +00:00
JCLOUDS-992: LocalBlobStore - use FOLDER for DIR.
Changed the LocalBlobStore to use FOLDER, as opposed to RELATIVE_PATH when creating directories. Changed the delete keys strategy to treat FOLDER blobs as regular blobs.
This commit is contained in:
parent
0c5a3db9df
commit
3757a64abf
@ -477,8 +477,8 @@ public final class LocalBlobStore implements BlobStore {
|
||||
if (name.startsWith(prefix)) {
|
||||
String unprefixedName = name.replaceFirst(prefix, "");
|
||||
if (unprefixedName.equals("")) {
|
||||
// we are the prefix in this case, return false
|
||||
return false;
|
||||
// a blob that matches the prefix should also be returned
|
||||
return true;
|
||||
}
|
||||
return unprefixedName.indexOf(delimiter) == -1;
|
||||
}
|
||||
|
@ -241,6 +241,7 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
|
||||
|
||||
final ListenableFuture<Void> blobDelFuture;
|
||||
switch (md.getType()) {
|
||||
case FOLDER:
|
||||
case BLOB:
|
||||
blobDelFuture = executorService.submit(new Callable<Void>() {
|
||||
@Override
|
||||
@ -250,9 +251,6 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
|
||||
}
|
||||
});
|
||||
break;
|
||||
case FOLDER:
|
||||
blobDelFuture = deleteDirectory(options, containerName, fullPath);
|
||||
break;
|
||||
case RELATIVE_PATH:
|
||||
blobDelFuture = deleteDirectory(options, containerName,
|
||||
md.getName());
|
||||
@ -415,7 +413,7 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
|
||||
// TODO: Remove this retry loop.
|
||||
while (retries > 0) {
|
||||
deleteFailure.set(false);
|
||||
executeOneIteration(containerName, listOptions.clone(), semaphore,
|
||||
executeOneIteration(containerName, listOptions, semaphore,
|
||||
outstandingFutures, deleteFailure, /*blocking=*/ false);
|
||||
waitForCompletion(semaphore, outstandingFutures);
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class MarkerFileMkdirStrategy implements MkdirStrategy {
|
||||
public void execute(String containerName, String directory) {
|
||||
blobStore.putBlob(
|
||||
containerName,
|
||||
blobStore.blobBuilder(directory + directorySuffix).type(StorageType.RELATIVE_PATH)
|
||||
blobStore.blobBuilder(directory + directorySuffix).type(StorageType.FOLDER)
|
||||
.payload(newByteArrayPayload(new byte[] {})).contentType("application/directory").build());
|
||||
}
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||
// should have only the 2 level-deep directory above
|
||||
container = view.getBlobStore().list(containerName, inDirectory(directory));
|
||||
assert container.getNextMarker() == null;
|
||||
assert container.size() == 1 : container;
|
||||
assertThat(container).hasSize(0);
|
||||
|
||||
view.getBlobStore().createDirectory(containerName, directory + "/" + directory);
|
||||
|
||||
|
@ -18,9 +18,6 @@ package org.jclouds.blobstore.strategy.internal;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import org.jclouds.ContextBuilder;
|
||||
import org.jclouds.blobstore.BlobStore;
|
||||
import org.jclouds.blobstore.domain.PageSet;
|
||||
@ -32,6 +29,10 @@ import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.io.ByteSource;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
@Test(testName = "PrefixTest", singleThreaded = true)
|
||||
public class ListContainerTest {
|
||||
private BlobStore blobStore;
|
||||
@ -51,6 +52,16 @@ public class ListContainerTest {
|
||||
}
|
||||
}
|
||||
|
||||
public void testListBlobWithPrefixAndDelimiter() {
|
||||
String containerName = "test";
|
||||
String name = "asdf/";
|
||||
blobStore.createContainerInLocation(null, containerName);
|
||||
blobStore.putBlob(containerName, blobStore.blobBuilder(name).payload("").build());
|
||||
Iterable<? extends StorageMetadata> results = concatter.execute(containerName,
|
||||
ListContainerOptions.Builder.prefix(name).delimiter(name));
|
||||
assertThat(results).hasSize(1);
|
||||
}
|
||||
|
||||
public void testListWithPrefix() {
|
||||
String containerName = "prefix";
|
||||
String prefix = "foo";
|
||||
@ -125,7 +136,9 @@ public class ListContainerTest {
|
||||
Iterable<? extends StorageMetadata> results = concatter.execute(containerName, ListContainerOptions.NONE);
|
||||
assertThat(results).hasSize(2);
|
||||
assertThat(Iterables.get(results, 0).getName()).isEqualTo(directory);
|
||||
assertThat(Iterables.get(results, 0).getType()).isEqualTo(StorageType.FOLDER);
|
||||
assertThat(Iterables.get(results, 1).getName()).isEqualTo(directory + '/');
|
||||
assertThat(Iterables.get(results, 1).getType()).isEqualTo(StorageType.RELATIVE_PATH);
|
||||
}
|
||||
|
||||
public void testListMarkers() {
|
||||
@ -147,6 +160,17 @@ public class ListContainerTest {
|
||||
assertThat(results.getNextMarker()).isEqualTo(null);
|
||||
}
|
||||
|
||||
public void testListBlobEndsWithDelimiter() {
|
||||
String containerName = "testListBlobEndsWithDelimiter";
|
||||
blobStore.createContainerInLocation(null, containerName);
|
||||
blobStore.putBlob(containerName, blobStore.blobBuilder("foo/").payload(ByteSource.empty()).build());
|
||||
PageSet<? extends StorageMetadata> results = blobStore.list(containerName,
|
||||
ListContainerOptions.Builder.prefix("foo/"));
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
assertThat(Iterables.get(results, 0).getName()).isEqualTo("foo/");
|
||||
assertThat(Iterables.get(results, 0).getType()).isNotEqualTo(StorageType.RELATIVE_PATH);
|
||||
}
|
||||
|
||||
public void testDirectoryListing() {
|
||||
String containerName = "testDirectoryListing";
|
||||
blobStore.createContainerInLocation(null, containerName);
|
||||
@ -161,11 +185,14 @@ public class ListContainerTest {
|
||||
results = blobStore.list(containerName, ListContainerOptions.Builder.inDirectory("dir"));
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
assertThat(Iterables.get(results, 0).getName()).isEqualTo("dir/dir");
|
||||
assertThat(Iterables.get(results, 0).getType()).isEqualTo(StorageType.FOLDER);
|
||||
|
||||
blobStore.putBlob(containerName, blobStore.blobBuilder("dir/dir/blob").payload("").build());
|
||||
results = blobStore.list(containerName, ListContainerOptions.Builder.inDirectory("dir"));
|
||||
assertThat(results.size()).isEqualTo(2);
|
||||
assertThat(Iterables.get(results, 0).getName()).isEqualTo("dir/dir");
|
||||
assertThat(Iterables.get(results, 0).getType()).isEqualTo(StorageType.FOLDER);
|
||||
assertThat(Iterables.get(results, 1).getName()).isEqualTo("dir/dir/");
|
||||
assertThat(Iterables.get(results, 1).getType()).isEqualTo(StorageType.RELATIVE_PATH);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user