spuru9 commented on code in PR #27964:
URL: https://github.com/apache/flink/pull/27964#discussion_r3104645687


##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/NativeS3FileSystem.java:
##########
@@ -257,14 +266,37 @@ public FileStatus getFileStatus(Path path) throws 
IOException {
         }
     }
 
+    /**
+     * Resolves the bucket root path (empty object key) to a directory {@link 
FileStatus} by
+     * verifying the bucket exists via {@link S3Client#headBucket}.
+     */
+    private FileStatus getBucketRootFileStatus(S3Client s3Client, Path path) 
throws IOException {
+        try {
+            
s3Client.headBucket(HeadBucketRequest.builder().bucket(bucketName).build());
+            LOG.debug("HeadBucket successful for s3://{}", bucketName);
+            return S3FileStatus.withDirectory(path);
+        } catch (NoSuchBucketException e) {
+            throw new FileNotFoundException("Bucket not found: " + path);
+        } catch (S3Exception e) {
+            LOG.error(
+                    "S3 error checking bucket root s3://{} - StatusCode: {}, 
ErrorCode: {}, Message: {}",
+                    bucketName,
+                    e.statusCode(),
+                    S3ExceptionUtils.errorCode(e),
+                    S3ExceptionUtils.errorMessage(e));
+            throw S3ExceptionUtils.toIOException(
+                    String.format("Failed to get file status for s3://%s", 
bucketName), e);
+        }
+    }
+
     /**
      * Checks if the given key represents a directory by listing objects with 
that prefix. Returns a
      * directory {@link FileStatus} if objects exist under the prefix, 
otherwise throws {@link
      * FileNotFoundException}.
      */
     private FileStatus getDirectoryStatus(S3Client s3Client, String key, Path 
path)
             throws FileNotFoundException {
-        final String prefix = key.endsWith("/") ? key : key + "/";
+        final String prefix = key.isEmpty() ? "" : (key.endsWith("/") ? key : 
key + "/");

Review Comment:
   nit: is this change need? if `key.isEmpty()`, getFileStatus returns at L202 
and getDirectoryStatus is not called in that case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to