diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java index 728958c93e..cf3b81bbed 100644 --- a/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java +++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java @@ -334,6 +334,13 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy { ByteSource byteSource; if (getDirectoryBlobSuffix(key) != null) { + if (!file.isDirectory()) { + // filesystem blobstore does not allow the existence of "file" and + // "file/" and getDirectoryBlobSuffix normalizes "file/" to "file". + // Therefore we need to return null when the normalized file is not + // a directory. + return null; + } logger.debug("%s - %s is a directory", container, key); byteSource = ByteSource.empty(); } else { diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java index 3c0c948560..7b4cb88023 100644 --- a/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java +++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java @@ -16,6 +16,7 @@ */ package org.jclouds.filesystem.strategy.internal; +import static org.assertj.core.api.Assertions.assertThat; import static org.jclouds.filesystem.util.Utils.isMacOSX; import static org.jclouds.utils.TestUtils.NO_INVOCATIONS; import static org.jclouds.utils.TestUtils.SINGLE_NO_ARG_INVOCATION; @@ -696,6 +697,42 @@ public class FilesystemStorageStrategyImplTest { } } + @Test + public void testGetBlobTrailingSlash() throws Exception { + String key = "key"; + ByteSource byteSource = randomByteSource().slice(0, 1024); + Blob blob = new BlobBuilderImpl() + .name(key) + .payload(byteSource) + .contentLength(byteSource.size()) + .build(); + storageStrategy.putBlob(CONTAINER_NAME, blob); + + blob = storageStrategy.getBlob(CONTAINER_NAME, key); + assertThat(blob).isNotNull(); + + blob = storageStrategy.getBlob(CONTAINER_NAME, key + "/"); + assertThat(blob).isNull(); + } + + @Test + public void testPutBlobTrailingSlash() throws Exception { + String key = "key"; + ByteSource byteSource = ByteSource.empty(); + Blob blob = new BlobBuilderImpl() + .name(key + "/") + .payload(byteSource) + .contentLength(byteSource.size()) + .build(); + storageStrategy.putBlob(CONTAINER_NAME, blob); + + blob = storageStrategy.getBlob(CONTAINER_NAME, key); + assertThat(blob).isNull(); + + blob = storageStrategy.getBlob(CONTAINER_NAME, key + "/"); + assertThat(blob).isNotNull(); + } + // ---------------------------------------------------------- Private methods /**