You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ga...@apache.org on 2018/01/10 06:46:38 UTC

jclouds git commit: Handle "file" and "file/" collision

Repository: jclouds
Updated Branches:
  refs/heads/master 5ca4827d1 -> 18eb7f3d3


Handle "file" and "file/" collision

Fixes gaul/s3proxy#240.


Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/18eb7f3d
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/18eb7f3d
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/18eb7f3d

Branch: refs/heads/master
Commit: 18eb7f3d383a280f6dd8f8c24978f578c5e88780
Parents: 5ca4827
Author: Andrew Gaul <ga...@apache.org>
Authored: Sun Jan 7 23:06:32 2018 -0800
Committer: Andrew Gaul <ga...@apache.org>
Committed: Tue Jan 9 22:26:53 2018 -0800

----------------------------------------------------------------------
 .../internal/FilesystemStorageStrategyImpl.java |  7 ++++
 .../FilesystemStorageStrategyImplTest.java      | 37 ++++++++++++++++++++
 2 files changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds/blob/18eb7f3d/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java
----------------------------------------------------------------------
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 728958c..cf3b81b 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 {

http://git-wip-us.apache.org/repos/asf/jclouds/blob/18eb7f3d/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java
----------------------------------------------------------------------
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 3c0c948..7b4cb88 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
 
    /**