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

zihaoxiang pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new a5296d6189 [Fix-17177]  Fix cos resource can not list (#17178)
a5296d6189 is described below

commit a5296d618945eb2f8cf035fab89c4a59140f5016
Author: gaoyan <[email protected]>
AuthorDate: Thu May 22 13:42:07 2025 +0800

    [Fix-17177]  Fix cos resource can not list (#17178)
---
 .../plugin/storage/cos/CosStorageOperator.java     | 37 +++++++++++++++++++---
 1 file changed, 32 insertions(+), 5 deletions(-)

diff --git 
a/dolphinscheduler-storage-plugin/dolphinscheduler-storage-cos/src/main/java/org/apache/dolphinscheduler/plugin/storage/cos/CosStorageOperator.java
 
b/dolphinscheduler-storage-plugin/dolphinscheduler-storage-cos/src/main/java/org/apache/dolphinscheduler/plugin/storage/cos/CosStorageOperator.java
index c4d1468260..037fcbeea3 100644
--- 
a/dolphinscheduler-storage-plugin/dolphinscheduler-storage-cos/src/main/java/org/apache/dolphinscheduler/plugin/storage/cos/CosStorageOperator.java
+++ 
b/dolphinscheduler-storage-plugin/dolphinscheduler-storage-cos/src/main/java/org/apache/dolphinscheduler/plugin/storage/cos/CosStorageOperator.java
@@ -221,8 +221,21 @@ public class CosStorageOperator extends 
AbstractStorageOperator implements Close
     }
 
     @Override
-    public List<StorageEntity> listStorageEntity(String resourceAbsolutePath) {
-        resourceAbsolutePath = 
transformCOSKeyToAbsolutePath(resourceAbsolutePath);
+    public List<StorageEntity> listStorageEntity(String path) {
+        /*
+         * If the incoming path ends with File.separator, it is assumed that 
the incoming intent is to access the
+         * directory and direct query If the incoming path does not end with 
`File.separator`, it is considered that the
+         * incoming intent could be either a file or a directory, and a 
determination needs to be made. If the object is
+         * queried as a file, return the file; otherwise, query it as a 
directory.
+         */
+        if (!path.endsWith(File.separator)) {
+            boolean objectExists = cosClient.doesObjectExist(bucketName, path);
+            if (!objectExists) {
+                path = path + File.separator;
+            }
+        }
+
+        String resourceAbsolutePath = path;
 
         ListObjectsRequest request = new ListObjectsRequest();
         request.setBucketName(bucketName);
@@ -230,9 +243,22 @@ public class CosStorageOperator extends 
AbstractStorageOperator implements Close
         request.setDelimiter(File.separator);
 
         ObjectListing result = cosClient.listObjects(request);
-
-        return result.getObjectSummaries()
+        List<StorageEntity> storageEntitys = new ArrayList<>();
+        // add directories
+        storageEntitys.addAll(result.getCommonPrefixes()
+                .stream()
+                .filter(x -> !resourceAbsolutePath.equals(x))
+                .map(key -> {
+                    ObjectMetadata metadata = new ObjectMetadata();
+                    COSObject object = new COSObject();
+                    object.setObjectMetadata(metadata);
+                    object.setKey(key);
+                    return transformCOSObjectToStorageEntity(object);
+                }).collect(Collectors.toList()));
+        // add files
+        storageEntitys.addAll(result.getObjectSummaries()
                 .stream()
+                .filter(x -> !x.getKey().endsWith(File.separator))
                 .map((COSObjectSummary summary) -> {
                     ObjectMetadata metadata = new ObjectMetadata();
                     metadata.setContentLength(summary.getSize());
@@ -242,7 +268,8 @@ public class CosStorageOperator extends 
AbstractStorageOperator implements Close
                     object.setKey(summary.getKey());
                     return transformCOSObjectToStorageEntity(object);
                 })
-                .collect(Collectors.toList());
+                .collect(Collectors.toList()));
+        return storageEntitys;
     }
 
     @Override

Reply via email to