This is an automated email from the ASF dual-hosted git repository.

wyk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git


The following commit(s) were added to refs/heads/master by this push:
     new f28a469ee4 [ASTERIXDB-3295][RT] Allow writing to empty S3 directory
f28a469ee4 is described below

commit f28a469ee41423c4e2fabaa273fa6b7ae021fe5f
Author: Wail Alkowaileet <[email protected]>
AuthorDate: Thu Nov 2 10:31:51 2023 -0700

    [ASTERIXDB-3295][RT] Allow writing to empty S3 directory
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    Details:
    Fix isEmptyPrefix to recognize empty directories.
    
    Change-Id: I9f222b32316256f47488185027d3be697c0d7aac
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17898
    Reviewed-by: Murtadha Hubail <[email protected]>
    Integration-Tests: Jenkins <[email protected]>
    Tested-by: Jenkins <[email protected]>
---
 .../asterix/cloud/clients/aws/s3/S3ClientUtils.java       | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git 
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/aws/s3/S3ClientUtils.java
 
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/aws/s3/S3ClientUtils.java
index fe475377fd..1855110744 100644
--- 
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/aws/s3/S3ClientUtils.java
+++ 
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/aws/s3/S3ClientUtils.java
@@ -66,8 +66,9 @@ public class S3ClientUtils {
     public static boolean isEmptyPrefix(S3Client s3Client, String bucket, 
String path) {
         ListObjectsV2Request.Builder listObjectsBuilder = 
ListObjectsV2Request.builder().bucket(bucket);
         listObjectsBuilder.prefix(toCloudPrefix(path));
+        List<S3Object> files = 
s3Client.listObjectsV2(listObjectsBuilder.build()).contents();
 
-        return 
s3Client.listObjectsV2(listObjectsBuilder.build()).contents().isEmpty();
+        return isEmptyFolder(files, path);
     }
 
     public static String encodeURI(String path) {
@@ -88,4 +89,16 @@ public class S3ClientUtils {
     private static String toCloudPrefix(String path) {
         return path.startsWith(File.separator) ? path.substring(1) : path;
     }
+
+    private static boolean isEmptyFolder(List<S3Object> files, String path) {
+        if (files.size() > 1) {
+            return false;
+        } else if (files.isEmpty()) {
+            return true;
+        }
+
+        S3Object s3Object = files.get(0);
+        String key = s3Object.key();
+        return s3Object.size() == 0 && key.charAt(key.length() - 1) == '/' && 
key.startsWith(path);
+    }
 }

Reply via email to