Skip to content

Commit 45a3c8b

Browse files
authored
[Fix-17688] Resource validation error and duplicate folders when using Aliyun OSS storage (#17689)
1 parent e119b1d commit 45a3c8b

File tree

1 file changed

+10
-1
lines changed
  • dolphinscheduler-storage-plugin/dolphinscheduler-storage-oss/src/main/java/org/apache/dolphinscheduler/plugin/storage/oss

1 file changed

+10
-1
lines changed

dolphinscheduler-storage-plugin/dolphinscheduler-storage-oss/src/main/java/org/apache/dolphinscheduler/plugin/storage/oss/OssStorageOperator.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,21 @@ public List<StorageEntity> listStorageEntity(String resourceAbsolutePath) {
255255
.withPrefix(ossResourceAbsolutePath);
256256

257257
ListObjectsV2Result listObjectsV2Result = ossClient.listObjectsV2(listObjectsV2Request);
258+
259+
// Collect common prefixes (directories)
260+
Set<String> commonPrefixSet = new HashSet<>(listObjectsV2Result.getCommonPrefixes());
261+
258262
List<StorageEntity> storageEntities = new ArrayList<>();
259263
storageEntities.addAll(listObjectsV2Result.getCommonPrefixes()
260264
.stream()
261265
.map(this::transformCommonPrefixToStorageEntity)
262266
.collect(Collectors.toList()));
263267
storageEntities.addAll(
264268
listObjectsV2Result.getObjectSummaries().stream()
265-
.filter(s3ObjectSummary -> !s3ObjectSummary.getKey().equals(resourceAbsolutePath))
269+
// Filter out the current directory itself
270+
.filter(ossObjectSummary -> !ossObjectSummary.getKey().equals(ossResourceAbsolutePath))
271+
// Filter out directory marker objects that are already in commonPrefixes
272+
.filter(ossObjectSummary -> !commonPrefixSet.contains(ossObjectSummary.getKey()))
266273
.map(this::transformOSSObjectToStorageEntity)
267274
.collect(Collectors.toList()));
268275

@@ -363,11 +370,13 @@ private StorageEntity transformCommonPrefixToStorageEntity(String commonPrefix)
363370
StorageEntity entity = new StorageEntity();
364371
entity.setFileName(new File(absolutePath).getName());
365372
entity.setFullName(absolutePath);
373+
entity.setPfullName(resourceMetaData.getResourceParentAbsolutePath());
366374
entity.setDirectory(resourceMetaData.isDirectory());
367375
entity.setType(resourceMetaData.getResourceType());
368376
entity.setSize(0L);
369377
entity.setCreateTime(null);
370378
entity.setUpdateTime(null);
379+
entity.setRelativePath(resourceMetaData.getResourceRelativePath());
371380
return entity;
372381
}
373382

0 commit comments

Comments
 (0)