From 006d8e21a6638affd4e69b9b4b0c28704db2c70d Mon Sep 17 00:00:00 2001 From: insist777 <84278047+insist777@users.noreply.github.com> Date: Thu, 18 Aug 2022 09:38:06 +0800 Subject: [PATCH] [Improvement] File deletion logic optimization (#11519) * [Improvement] File deletion logic optimization --- .../org/apache/dolphinscheduler/api/enums/Status.java | 1 + .../api/service/impl/ResourcesServiceImpl.java | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java index 8dedcaac6a..dea5e79285 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java @@ -239,6 +239,7 @@ public enum Status { PARENT_RESOURCE_NOT_EXIST(20015, "parent resource not exist", "父资源文件不存在"), RESOURCE_NOT_EXIST_OR_NO_PERMISSION(20016, "resource not exist or no permission,please view the task node and remove error resource", "请检查任务节点并移除无权限或者已删除的资源"), RESOURCE_IS_AUTHORIZED(20017, "resource is authorized to user {0},suffix not allowed to be modified", "资源文件已授权其他用户[{0}],后缀不允许修改"), + RESOURCE_HAS_FOLDER(20018, "There are files or folders in the current directory:{0}", "当前目录下有文件或文件夹[{0}]"), USER_NO_OPERATION_PERM(30001, "user has no operation privilege", "当前用户没有操作权限"), USER_NO_OPERATION_PROJECT_PERM(30002, "user {0} is not has project {1} permission", "当前用户[{0}]没有[{1}]项目的操作权限"), diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java index 21dd5e0d51..74e093c299 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java @@ -828,8 +828,16 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe Set resourceIdSet = resourceProcessMap.keySet(); // get all children of the resource List allChildren = listAllChildren(resource, true); + Integer[] needDeleteResourceIdArray = allChildren.toArray(new Integer[allChildren.size()]); + + if (needDeleteResourceIdArray.length >= 2){ + logger.error("can't be deleted,because There are files or folders in the current directory:{}", resource); + putMsg(result, Status.RESOURCE_HAS_FOLDER, resource.getFileName()); + return result; + } + //if resource type is UDF,need check whether it is bound by UDF function if (resource.getType() == (ResourceType.UDF)) { List udfFuncs = udfFunctionMapper.listUdfByResourceId(needDeleteResourceIdArray); @@ -840,6 +848,8 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe } } + + if (resourceIdSet.contains(resource.getPid())) { logger.error("can't be deleted,because it is used of process definition"); putMsg(result, Status.RESOURCE_IS_USED);