Repository: jclouds Updated Branches: refs/heads/master 3757a64ab -> 496e27f1a
Always return ETag from filesystem object store If the Content-MD5 extended attribute is missing for an object, recompute it and return as the ETag. Primarily affects OS X. Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/496e27f1 Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/496e27f1 Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/496e27f1 Branch: refs/heads/master Commit: 496e27f1afa32b90d0656c3f21387cf68a30cb31 Parents: 3757a64 Author: Nate Rosenblum <[email protected]> Authored: Thu Aug 20 14:16:11 2015 -0700 Committer: Andrew Gaul <[email protected]> Committed: Thu Aug 20 14:46:17 2015 -0700 ---------------------------------------------------------------------- .../internal/FilesystemStorageStrategyImpl.java | 5 ++++ .../FilesystemStorageStrategyImplTest.java | 30 ++++++++++++++++++++ 2 files changed, 35 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds/blob/496e27f1/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 3c9c2ce..4781ab1 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 @@ -362,6 +362,11 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy { userMetadata.put(attribute.substring(XATTR_USER_METADATA_PREFIX.length()), value); } + if (hashCode == null) { + // content-md5 xattr not found; recompute + hashCode = byteSource.hash(Hashing.md5()); + } + builder.payload(byteSource) .contentDisposition(contentDisposition) .contentEncoding(contentEncoding) http://git-wip-us.apache.org/repos/asf/jclouds/blob/496e27f1/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 1ab8325..af0f67d 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 com.google.common.io.BaseEncoding.base16; import static org.jclouds.utils.TestUtils.randomByteSource; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; @@ -50,6 +51,8 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import com.google.common.hash.HashCode; +import com.google.common.hash.Hashing; import com.google.common.io.ByteSource; import com.google.common.io.Files; @@ -647,6 +650,27 @@ public class FilesystemStorageStrategyImplTest { assertFalse(blob.getMetadata().getUserMetadata().containsKey("key1")); } + // This test will become irrelevant if the JVM starts supporting + // user extended attributes on HFS+. Nobody will complain. + @Test(dataProvider = "onlyOnMacOSX") + public void testEtagReturnedWithoutXattrSupport() throws Exception { + String blobKey = TestUtils.createRandomBlobKey(); + ByteSource content = randomByteSource().slice(0, 1024); + HashCode expectedHash = content.hash(Hashing.md5()); + + // write blob + Blob blob = new BlobBuilderImpl() + .name(blobKey) + .payload(content) + .build(); + String etag = storageStrategy.putBlob(CONTAINER_NAME, blob); + + // read blob & check etag + blob = storageStrategy.getBlob(CONTAINER_NAME, blobKey); + assertEquals(blob.getMetadata().getContentMetadata().getContentMD5AsHashCode(), expectedHash); + assertEquals(blob.getMetadata().getETag(), base16().lowerCase().encode(expectedHash.asBytes())); + } + // ---------------------------------------------------------- Private methods /** @@ -666,4 +690,10 @@ public class FilesystemStorageStrategyImplTest { return org.jclouds.utils.TestUtils.isMacOSX() ? TestUtils.NO_INVOCATIONS : TestUtils.SINGLE_NO_ARG_INVOCATION; } + + @DataProvider + public Object[][] onlyOnMacOSX() { + return org.jclouds.utils.TestUtils.isMacOSX() ? + TestUtils.SINGLE_NO_ARG_INVOCATION : TestUtils.NO_INVOCATIONS; + } }
