From 5edd5de38c01f3a1ea962dd9f0a4bd6d060f32de Mon Sep 17 00:00:00 2001 From: Ka-Hing Cheung Date: Fri, 9 Jan 2015 14:11:46 -0800 Subject: [PATCH] make xattr work in docker volume when you bind a host volume into docker, java does not correctly detect that and checks the xattr support on the root fs instead of the host fs. The root fs often does not support xattr, so the check would fail even if the target really does support xattr. the fix is just try setting the xattrs anyway, and let them fail if there really isn't xattrs support --- .../FilesystemStorageStrategyImpl.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) 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 3790e16d10..1642527e63 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 @@ -17,7 +17,6 @@ package org.jclouds.filesystem.strategy.internal; import static java.nio.file.Files.getFileAttributeView; -import static java.nio.file.Files.getFileStore; import static java.nio.file.Files.readAttributes; import static com.google.common.base.Preconditions.checkNotNull; @@ -260,8 +259,8 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy { Date expires = null; ImmutableMap.Builder userMetadata = ImmutableMap.builder(); - if (getFileStore(file.toPath()).supportsFileAttributeView(UserDefinedFileAttributeView.class)) { - UserDefinedFileAttributeView view = getFileAttributeView(path, UserDefinedFileAttributeView.class); + UserDefinedFileAttributeView view = getUserDefinedFileAttributeView(file.toPath()); + if (view != null) { Set attributes = ImmutableSet.copyOf(view.list()); contentDisposition = readStringAttributeIfPresent(view, attributes, XATTR_CONTENT_DISPOSITION); @@ -346,8 +345,12 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy { UserDefinedFileAttributeView view = getUserDefinedFileAttributeView(outputPath); if (view != null) { - view.write(XATTR_CONTENT_MD5, ByteBuffer.wrap(DIRECTORY_MD5)); - writeCommonMetadataAttr(view, blob); + try { + view.write(XATTR_CONTENT_MD5, ByteBuffer.wrap(DIRECTORY_MD5)); + writeCommonMetadataAttr(view, blob); + } catch (IOException e) { + logger.debug("xattrs not supported on %s", outputPath); + } } else { logger.warn("xattr not supported on %s", blobKey); } @@ -380,10 +383,14 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy { } payload.getContentMetadata().setContentMD5(actualHashCode); - if (getFileStore(outputPath).supportsFileAttributeView(UserDefinedFileAttributeView.class)) { - UserDefinedFileAttributeView view = getFileAttributeView(outputPath, UserDefinedFileAttributeView.class); - view.write(XATTR_CONTENT_MD5, ByteBuffer.wrap(actualHashCode.asBytes())); - writeCommonMetadataAttr(view, blob); + UserDefinedFileAttributeView view = getUserDefinedFileAttributeView(outputPath); + if (view != null) { + try { + view.write(XATTR_CONTENT_MD5, ByteBuffer.wrap(actualHashCode.asBytes())); + writeCommonMetadataAttr(view, blob); + } catch (IOException e) { + logger.debug("xattrs not supported on %s", outputPath); + } } return base16().lowerCase().encode(actualHashCode.asBytes()); } catch (IOException ex) { @@ -526,10 +533,7 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy { } private UserDefinedFileAttributeView getUserDefinedFileAttributeView(Path path) throws IOException { - if (getFileStore(path).supportsFileAttributeView(UserDefinedFileAttributeView.class)) { - return getFileAttributeView(path, UserDefinedFileAttributeView.class); - } - return null; + return getFileAttributeView(path, UserDefinedFileAttributeView.class); } /**