mirror of https://github.com/apache/jclouds.git
Merge branch 'master' of github.com:jclouds/jclouds
* 'master' of github.com:jclouds/jclouds: Solved issue 409: Filesystem provider treats PROPERTY_BASEDIR pointing to an absolute dir
This commit is contained in:
commit
c77979c311
|
@ -335,12 +335,12 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
|||
* @return the resulting string
|
||||
*/
|
||||
protected String buildPathStartingFromBaseDir(String...pathTokens) {
|
||||
String normalizedToken = removeFileSeparatorFromBorders(normalize(baseDirectory));
|
||||
String normalizedToken = removeFileSeparatorFromBorders(normalize(baseDirectory), true);
|
||||
StringBuilder completePath = new StringBuilder(normalizedToken);
|
||||
if(pathTokens!=null && pathTokens.length>0) {
|
||||
for(int i=0; i<pathTokens.length; i++) {
|
||||
if(pathTokens[i]!=null) {
|
||||
normalizedToken = removeFileSeparatorFromBorders(normalize(pathTokens[i]));
|
||||
normalizedToken = removeFileSeparatorFromBorders(normalize(pathTokens[i]), false);
|
||||
completePath.append(File.separator).append(normalizedToken);
|
||||
}
|
||||
}
|
||||
|
@ -367,16 +367,19 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
|||
* Remove leading and trailing {@link File.separator} character from the
|
||||
* string.
|
||||
* @param pathToBeCleaned
|
||||
* @param remove only trailing separator char from path
|
||||
* @return
|
||||
*/
|
||||
private String removeFileSeparatorFromBorders(String pathToBeCleaned) {
|
||||
private String removeFileSeparatorFromBorders(String pathToBeCleaned, boolean onlyTrailing) {
|
||||
if (null == pathToBeCleaned || pathToBeCleaned.equals("")) return pathToBeCleaned;
|
||||
|
||||
int beginIndex = 0;
|
||||
int endIndex = pathToBeCleaned.length();
|
||||
|
||||
//search for separator chars
|
||||
if (!onlyTrailing) {
|
||||
if (pathToBeCleaned.substring(0, 1).equals(File.separator)) beginIndex = 1;
|
||||
}
|
||||
if (pathToBeCleaned.substring(pathToBeCleaned.length() - 1).equals(File.separator)) endIndex--;
|
||||
|
||||
return pathToBeCleaned.substring(beginIndex, endIndex);
|
||||
|
|
|
@ -185,16 +185,8 @@ public class FilesystemAsyncBlobStoreTest {
|
|||
/**
|
||||
* Test of list method, of class FilesystemAsyncBlobStore.
|
||||
*/
|
||||
public void testList_NoOptionSingleContainer() throws IOException {
|
||||
|
||||
// Testing list for a not existing container
|
||||
try {
|
||||
blobStore.list(CONTAINER_NAME);
|
||||
fail("Found a not existing container");
|
||||
} catch(ContainerNotFoundException e) {
|
||||
|
||||
}
|
||||
|
||||
public void testList_NoOptionSingleContainer()
|
||||
throws IOException {
|
||||
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
||||
// Testing list for an empty container
|
||||
checkForContainerContent(CONTAINER_NAME, null);
|
||||
|
@ -268,6 +260,29 @@ public class FilesystemAsyncBlobStoreTest {
|
|||
}
|
||||
|
||||
|
||||
public void testList_Subdirectory()
|
||||
throws IOException {
|
||||
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
||||
// Testing list for an empty container
|
||||
checkForContainerContent(CONTAINER_NAME, null);
|
||||
|
||||
//creates blobs in first container
|
||||
Set<String> blobsExpected = TestUtils.createBlobsInContainer(
|
||||
CONTAINER_NAME,
|
||||
new String[] {
|
||||
"bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg",
|
||||
"4rrr.jpg",
|
||||
"rrr" + File.separator + "sss" + File.separator + "788.jpg",
|
||||
"rrr" + File.separator + "wert.kpg" }
|
||||
);
|
||||
|
||||
//remove not expected values
|
||||
blobsExpected.remove("bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg");
|
||||
blobsExpected.remove("4rrr.jpg");
|
||||
|
||||
checkForContainerContent(CONTAINER_NAME, "rrr", blobsExpected);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* Should throws an exception?
|
||||
|
@ -809,12 +824,17 @@ public class FilesystemAsyncBlobStoreTest {
|
|||
* @param expectedBlobKeys
|
||||
*/
|
||||
private void checkForContainerContent(final String containerName, Set<String> expectedBlobKeys) {
|
||||
checkForContainerContent(containerName, null, expectedBlobKeys);
|
||||
}
|
||||
|
||||
private void checkForContainerContent(final String containerName, String inDirectory, Set<String> expectedBlobKeys) {
|
||||
ListContainerOptions options = ListContainerOptions.Builder.recursive();
|
||||
if (null != inDirectory && !"".equals(inDirectory)) options.inDirectory(inDirectory);
|
||||
|
||||
PageSet<? extends StorageMetadata> blobsRetrieved = blobStore.list(containerName, options);
|
||||
|
||||
//nothing expected
|
||||
if (null == expectedBlobKeys) {
|
||||
if (null == expectedBlobKeys || 0 == expectedBlobKeys.size()) {
|
||||
assertTrue(blobsRetrieved.isEmpty(), "Wrong blob number retrieved in the containter [" + containerName + "]");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -417,6 +417,38 @@ public class FilesystemStorageStrategyImplTest {
|
|||
}
|
||||
|
||||
|
||||
public void testGetFileForBlobKey_AbsolutePath()
|
||||
throws IOException {
|
||||
String absoluteBasePath = (new File(getAbsoluteDirectory(), "basedir")).getAbsolutePath() + FS;
|
||||
String absoluteContainerPath = absoluteBasePath + CONTAINER_NAME + FS;
|
||||
|
||||
//create storageStrategy with an absolute path
|
||||
FilesystemStorageStrategy storageStrategyAbsolute = new FilesystemStorageStrategyImpl(
|
||||
new Blob.Factory() {
|
||||
@Override
|
||||
public Blob create(MutableBlobMetadata metadata) {
|
||||
return new BlobImpl(metadata != null ? metadata : new MutableBlobMetadataImpl());
|
||||
}
|
||||
},
|
||||
absoluteBasePath,
|
||||
new FilesystemContainerNameValidatorImpl(),
|
||||
new FilesystemBlobKeyValidatorImpl());
|
||||
TestUtils.cleanDirectoryContent(absoluteContainerPath);
|
||||
|
||||
String blobKey;
|
||||
File fileForPayload;
|
||||
|
||||
blobKey = TestUtils.createRandomBlobKey("getFileForBlobKey-", ".img");
|
||||
fileForPayload = storageStrategyAbsolute.getFileForBlobKey(CONTAINER_NAME, blobKey);
|
||||
assertNotNull(fileForPayload, "Result File object is null");
|
||||
assertEquals(fileForPayload.getAbsolutePath(), absoluteContainerPath + blobKey, "Wrong file path");
|
||||
|
||||
blobKey = TestUtils.createRandomBlobKey("asd" + FS + "vmad" + FS + "andsnf" + FS + "getFileForBlobKey-", ".img");
|
||||
fileForPayload = storageStrategyAbsolute.getFileForBlobKey(CONTAINER_NAME, blobKey);
|
||||
assertEquals(fileForPayload.getAbsolutePath(), absoluteContainerPath + blobKey, "Wrong file path");
|
||||
}
|
||||
|
||||
|
||||
public void testBlobExists() throws IOException {
|
||||
String[] sourceBlobKeys = new String[]{
|
||||
TestUtils.createRandomBlobKey("blobExists-", ".jpg"),
|
||||
|
@ -530,5 +562,16 @@ public class FilesystemStorageStrategyImplTest {
|
|||
//---------------------------------------------------------- Private methods
|
||||
|
||||
|
||||
/**
|
||||
* Calculates an absolute directory path that depends on operative system
|
||||
* @return
|
||||
*/
|
||||
private String getAbsoluteDirectory() throws IOException {
|
||||
File tempFile = File.createTempFile("prefix", "suffix");
|
||||
String tempAbsolutePath = tempFile.getParent();
|
||||
|
||||
return tempAbsolutePath;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue