Denormalize path when removing subtree

This commit improves filesystem blobstore compatibility on Windows.
This partially reverts cfe3169.  Tested on Ubuntu 12.04 and Windows 7.
References #737.  Closes #912.
This commit is contained in:
Andrew Gaul 2012-07-30 14:38:22 -07:00 committed by Andrew Gaul
parent 00f5f0367d
commit 577cde0a02
3 changed files with 21 additions and 28 deletions

View File

@ -358,6 +358,15 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
return pathToBeNormalized; return pathToBeNormalized;
} }
private static String denormalize(String pathToDenormalize) {
if (null != pathToDenormalize && pathToDenormalize.contains("/")) {
if (BACK_SLASH.equals(File.separator)) {
return pathToDenormalize.replace("/", BACK_SLASH);
}
}
return pathToDenormalize;
}
/** /**
* Remove leading and trailing {@link File.separator} character from the string. * Remove leading and trailing {@link File.separator} character from the string.
* *
@ -392,7 +401,7 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
* @param normalizedKey * @param normalizedKey
*/ */
private void removeDirectoriesTreeOfBlobKey(String container, String blobKey) { private void removeDirectoriesTreeOfBlobKey(String container, String blobKey) {
String normalizedBlobKey = normalize(blobKey); String normalizedBlobKey = denormalize(blobKey);
// exists is no path is present in the blobkey // exists is no path is present in the blobkey
if (!normalizedBlobKey.contains(File.separator)) if (!normalizedBlobKey.contains(File.separator))
return; return;

View File

@ -121,12 +121,6 @@ public class FilesystemAsyncBlobStoreTest {
} }
} }
@DataProvider
public Object[][] ignoreOnWindows() {
return (TestUtils.isWindowsOs() ? TestUtils.NO_INVOCATIONS
: TestUtils.SINGLE_NO_ARG_INVOCATION);
}
/** /**
* Checks if context parameters are managed in the correct way * Checks if context parameters are managed in the correct way
*/ */
@ -407,7 +401,7 @@ public class FilesystemAsyncBlobStoreTest {
/** /**
* Test of removeBlob method, with only one blob with a complex path as key * Test of removeBlob method, with only one blob with a complex path as key
*/ */
@Test(dataProvider = "ignoreOnWindows", description = "see http://code.google.com/p/jclouds/issues/detail?id=737") @Test
public void testRemoveBlob_ComplexBlobKey() throws IOException { public void testRemoveBlob_ComplexBlobKey() throws IOException {
final String BLOB_KEY = TestUtils.createRandomBlobKey("aa/bb/cc/dd/", null); final String BLOB_KEY = TestUtils.createRandomBlobKey("aa/bb/cc/dd/", null);
boolean result; boolean result;
@ -438,7 +432,7 @@ public class FilesystemAsyncBlobStoreTest {
* when first blob is removed, not all of its key's path is removed, because * when first blob is removed, not all of its key's path is removed, because
* it is shared with the second blob's key * it is shared with the second blob's key
*/ */
@Test(dataProvider = "ignoreOnWindows", description = "see http://code.google.com/p/jclouds/issues/detail?id=737") @Test
public void testRemoveBlob_TwoComplexBlobKeys() throws IOException { public void testRemoveBlob_TwoComplexBlobKeys() throws IOException {
final String BLOB_KEY1 = TestUtils.createRandomBlobKey("aa/bb/cc/dd/", null); final String BLOB_KEY1 = TestUtils.createRandomBlobKey("aa/bb/cc/dd/", null);
final String BLOB_KEY2 = TestUtils.createRandomBlobKey("aa/bb/ee/ff/", null); final String BLOB_KEY2 = TestUtils.createRandomBlobKey("aa/bb/ee/ff/", null);
@ -720,35 +714,31 @@ public class FilesystemAsyncBlobStoreTest {
TestUtils.directoryExists(TARGET_CONTAINER_NAME2, false); TestUtils.directoryExists(TARGET_CONTAINER_NAME2, false);
} }
@Test(dataProvider = "ignoreOnWindows", description = "see http://code.google.com/p/jclouds/issues/detail?id=737") @Test
public void testInvalidContainerName() { public void testInvalidContainerName() {
String containerName = "file" + File.separator + "system";
try { try {
blobStore.createContainerInLocation(null, "file/system"); blobStore.createContainerInLocation(null, containerName);
fail("Wrong container name not recognized"); fail("Wrong container name not recognized");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
} }
try { try {
blobStore.containerExists("file/system"); blobStore.containerExists(containerName);
fail("Wrong container name not recognized"); fail("Wrong container name not recognized");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
} }
} }
public void testRanges() throws IOException { public void testRanges() throws IOException {
/* blobStore.createContainerInLocation(null, CONTAINER_NAME);
* Using CONTAINER_NAME here breaks tests on Windows because the container
* can't be deleted. See http://code.google.com/p/jclouds/issues/detail?id=737
*/
final String containerName = "containerWithRanges";
blobStore.createContainerInLocation(null, containerName);
String payload = "abcdefgh"; String payload = "abcdefgh";
InputStream is; InputStream is;
Blob blob = blobStore.blobBuilder("test").payload(new StringPayload(payload)).build(); Blob blob = blobStore.blobBuilder("test").payload(new StringPayload(payload)).build();
blobStore.putBlob(containerName, blob); blobStore.putBlob(CONTAINER_NAME, blob);
GetOptions getOptionsRangeStartAt = new GetOptions(); GetOptions getOptionsRangeStartAt = new GetOptions();
getOptionsRangeStartAt.startAt(1); getOptionsRangeStartAt.startAt(1);
Blob blobRangeStartAt = blobStore.getBlob(containerName, blob.getMetadata().getName(), getOptionsRangeStartAt); Blob blobRangeStartAt = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeStartAt);
is = blobRangeStartAt.getPayload().getInput(); is = blobRangeStartAt.getPayload().getInput();
try { try {
assertEquals("bcdefgh", IOUtils.toString(is)); assertEquals("bcdefgh", IOUtils.toString(is));
@ -758,7 +748,7 @@ public class FilesystemAsyncBlobStoreTest {
GetOptions getOptionsRangeTail = new GetOptions(); GetOptions getOptionsRangeTail = new GetOptions();
getOptionsRangeTail.tail(3); getOptionsRangeTail.tail(3);
Blob blobRangeTail = blobStore.getBlob(containerName, blob.getMetadata().getName(), getOptionsRangeTail); Blob blobRangeTail = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeTail);
is = blobRangeTail.getPayload().getInput(); is = blobRangeTail.getPayload().getInput();
try { try {
assertEquals("fgh", IOUtils.toString(is)); assertEquals("fgh", IOUtils.toString(is));
@ -768,7 +758,7 @@ public class FilesystemAsyncBlobStoreTest {
GetOptions getOptionsFragment = new GetOptions(); GetOptions getOptionsFragment = new GetOptions();
getOptionsFragment.range(4, 6); getOptionsFragment.range(4, 6);
Blob blobFragment = blobStore.getBlob(containerName, blob.getMetadata().getName(), getOptionsFragment); Blob blobFragment = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsFragment);
is = blobFragment.getPayload().getInput(); is = blobFragment.getPayload().getInput();
try { try {
assertEquals("efg", IOUtils.toString(is)); assertEquals("efg", IOUtils.toString(is));

View File

@ -95,12 +95,6 @@ public class FilesystemStorageStrategyImplTest {
TestUtils.cleanDirectoryContent(TestUtils.TARGET_BASE_DIR); TestUtils.cleanDirectoryContent(TestUtils.TARGET_BASE_DIR);
} }
@DataProvider
public Object[][] ignoreOnWindows() {
return (TestUtils.isWindowsOs() ? TestUtils.NO_INVOCATIONS
: TestUtils.SINGLE_NO_ARG_INVOCATION);
}
public void testCreateDirectory() { public void testCreateDirectory() {
storageStrategy.createDirectory(CONTAINER_NAME, null); storageStrategy.createDirectory(CONTAINER_NAME, null);
TestUtils.directoryExists(TARGET_CONTAINER_NAME, true); TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);