mirror of https://github.com/apache/jclouds.git
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.
This commit is contained in:
parent
3757a64abf
commit
496e27f1af
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue