From cf1902b055731384a60072496c1520d2c1e9debc Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Tue, 17 Jul 2018 23:31:40 +0000 Subject: [PATCH] make owner optional when fetching attributes --- src/main/java/com/upplication/s3fs/util/S3Utils.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/upplication/s3fs/util/S3Utils.java b/src/main/java/com/upplication/s3fs/util/S3Utils.java index aff084f..63d8364 100644 --- a/src/main/java/com/upplication/s3fs/util/S3Utils.java +++ b/src/main/java/com/upplication/s3fs/util/S3Utils.java @@ -41,8 +41,14 @@ public S3ObjectSummary getS3ObjectSummary(S3Path s3Path) throws NoSuchFileExcept result.setKey(key); result.setLastModified(metadata.getLastModified()); result.setSize(metadata.getContentLength()); - AccessControlList objectAcl = client.getObjectAcl(bucketName, key); - result.setOwner(objectAcl.getOwner()); + try { + AccessControlList objectAcl = client.getObjectAcl(bucketName, key); + result.setOwner(objectAcl.getOwner()); + } catch (AmazonS3Exception e) { + // If we don't have permission to view the ACL, that's fine, we can leave `owner` empty + if (e.getStatusCode() != 403) + throw e; + } return result; } catch (AmazonS3Exception e) { if (e.getStatusCode() != 404) @@ -189,4 +195,4 @@ public S3BasicFileAttributes toS3FileAttributes(S3ObjectSummary objectSummary, S } return new S3BasicFileAttributes(resolvedKey, lastModifiedTime, size, directory, regularFile); } -} \ No newline at end of file +}