From f210283cacf5a36e9d5cc303523f5730b95aae39 Mon Sep 17 00:00:00 2001 From: Geert Vanheusden Date: Tue, 28 Feb 2017 19:30:20 +0100 Subject: [PATCH] JCLOUDS-1218: filesystem get blob without xattrs Some filesystems, notably Docker and Mac OS X, do not support xattr which causes an IOException when getting a blob. --- .../FilesystemStorageStrategyImpl.java | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 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 e6209ba70d..577c6930fd 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 @@ -346,33 +346,37 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy { UserDefinedFileAttributeView view = getUserDefinedFileAttributeView(file.toPath()); if (view != null) { - Set attributes = ImmutableSet.copyOf(view.list()); + try { + Set attributes = ImmutableSet.copyOf(view.list()); - cacheControl = readStringAttributeIfPresent(view, attributes, XATTR_CACHE_CONTROL); - contentDisposition = readStringAttributeIfPresent(view, attributes, XATTR_CONTENT_DISPOSITION); - contentEncoding = readStringAttributeIfPresent(view, attributes, XATTR_CONTENT_ENCODING); - contentLanguage = readStringAttributeIfPresent(view, attributes, XATTR_CONTENT_LANGUAGE); - contentType = readStringAttributeIfPresent(view, attributes, XATTR_CONTENT_TYPE); - if (contentType == null && autoDetectContentType) { - contentType = probeContentType(file.toPath()); - } - if (attributes.contains(XATTR_CONTENT_MD5)) { - ByteBuffer buf = ByteBuffer.allocate(view.size(XATTR_CONTENT_MD5)); - view.read(XATTR_CONTENT_MD5, buf); - hashCode = HashCode.fromBytes(buf.array()); - } - if (attributes.contains(XATTR_EXPIRES)) { - ByteBuffer buf = ByteBuffer.allocate(view.size(XATTR_EXPIRES)); - view.read(XATTR_EXPIRES, buf); - buf.flip(); - expires = new Date(buf.asLongBuffer().get()); - } - for (String attribute : attributes) { - if (!attribute.startsWith(XATTR_USER_METADATA_PREFIX)) { - continue; + cacheControl = readStringAttributeIfPresent(view, attributes, XATTR_CACHE_CONTROL); + contentDisposition = readStringAttributeIfPresent(view, attributes, XATTR_CONTENT_DISPOSITION); + contentEncoding = readStringAttributeIfPresent(view, attributes, XATTR_CONTENT_ENCODING); + contentLanguage = readStringAttributeIfPresent(view, attributes, XATTR_CONTENT_LANGUAGE); + contentType = readStringAttributeIfPresent(view, attributes, XATTR_CONTENT_TYPE); + if (contentType == null && autoDetectContentType) { + contentType = probeContentType(file.toPath()); } - String value = readStringAttributeIfPresent(view, attributes, attribute); - userMetadata.put(attribute.substring(XATTR_USER_METADATA_PREFIX.length()), value); + if (attributes.contains(XATTR_CONTENT_MD5)) { + ByteBuffer buf = ByteBuffer.allocate(view.size(XATTR_CONTENT_MD5)); + view.read(XATTR_CONTENT_MD5, buf); + hashCode = HashCode.fromBytes(buf.array()); + } + if (attributes.contains(XATTR_EXPIRES)) { + ByteBuffer buf = ByteBuffer.allocate(view.size(XATTR_EXPIRES)); + view.read(XATTR_EXPIRES, buf); + buf.flip(); + expires = new Date(buf.asLongBuffer().get()); + } + for (String attribute : attributes) { + if (!attribute.startsWith(XATTR_USER_METADATA_PREFIX)) { + continue; + } + String value = readStringAttributeIfPresent(view, attributes, attribute); + userMetadata.put(attribute.substring(XATTR_USER_METADATA_PREFIX.length()), value); + } + } catch (IOException e) { + logger.debug("xattrs not supported on %s", file.toPath()); } builder.payload(byteSource)