@@ -87,27 +87,30 @@ public S3BasicFileAttributes getS3FileAttributes(S3Path s3Path) throws NoSuchFil
8787 * @return S3PosixFileAttributes never null
8888 * @throws NoSuchFileException if the Path doesnt exists
8989 */
90- public S3PosixFileAttributes getS3PosixFileAttributes (S3Path s3Path ) throws NoSuchFileException {
91- S3ObjectSummary objectSummary = getS3ObjectSummary (s3Path );
92-
93- String key = s3Path .getKey ();
94- String bucketName = s3Path .getFileStore ().name ();
95-
96- S3BasicFileAttributes attrs = toS3FileAttributes (objectSummary , key );
97- S3UserPrincipal userPrincipal = null ;
98- Set <PosixFilePermission > permissions = null ;
99-
100- if (!attrs .isDirectory ()) {
101- AmazonS3 client = s3Path .getFileSystem ().getClient ();
102- AccessControlList acl = client .getObjectAcl (bucketName , key );
103- Owner owner = acl .getOwner ();
104-
105- userPrincipal = new S3UserPrincipal (owner .getId () + ":" + owner .getDisplayName ());
106- permissions = toPosixFilePermissions (acl .getGrantsAsList ());
107- }
108-
109- return new S3PosixFileAttributes ((String )attrs .fileKey (), attrs .lastModifiedTime (),
110- attrs .size (), attrs .isDirectory (), attrs .isRegularFile (), userPrincipal , null , permissions );
90+ public S3PosixFileAttributes getS3PosixFileAttributes (final S3Path s3Path ) throws NoSuchFileException {
91+ final String key = s3Path .getKey ();
92+ final String bucketName = s3Path .getFileStore ().name ();
93+ final S3ObjectSummary objectSummary = getS3ObjectSummary (s3Path );
94+ final S3BasicFileAttributes attrs = toS3FileAttributes (objectSummary , key );
95+ final AmazonS3 client = s3Path .getFileSystem ().getClient ();
96+ final AccessControlList acl = (!attrs .isDirectory ())
97+ ? client .getObjectAcl (bucketName , key )
98+ : client .getBucketAcl (bucketName );
99+
100+ final Owner owner = acl .getOwner ();
101+ final Set <PosixFilePermission > permissions = toPosixFilePermissions (acl .getGrantsAsList ());
102+ final S3UserPrincipal userPrincipal = new S3UserPrincipal (owner .getId () + ":" + owner .getDisplayName ());
103+
104+ return new S3PosixFileAttributes (
105+ (String ) attrs .fileKey (),
106+ attrs .lastModifiedTime (),
107+ attrs .size (),
108+ attrs .isDirectory (),
109+ attrs .isRegularFile (),
110+ userPrincipal ,
111+ null ,
112+ permissions
113+ );
111114 }
112115
113116
@@ -189,4 +192,4 @@ public S3BasicFileAttributes toS3FileAttributes(S3ObjectSummary objectSummary, S
189192 }
190193 return new S3BasicFileAttributes (resolvedKey , lastModifiedTime , size , directory , regularFile );
191194 }
192- }
195+ }
0 commit comments