From 76c4dd904013e0f1016e3b57942781384d42a4a6 Mon Sep 17 00:00:00 2001 From: Kirs Date: Tue, 20 Jul 2021 11:41:49 +0800 Subject: [PATCH] [1.3.7-prepare#5476][Improvement][Api] Upload resource to remote failed, the local tmp file need to be cleared (#5848) pr #5476 issue #5475 --- .../dolphinscheduler/api/service/ResourcesService.java | 5 +++++ .../org/apache/dolphinscheduler/common/utils/FileUtils.java | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java index e61e7f50a2..ce430a1625 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java @@ -625,6 +625,11 @@ public class ResourcesService extends BaseService { org.apache.dolphinscheduler.api.utils.FileUtils.copyFile(file, localFilename); HadoopUtils.getInstance().copyLocalToHdfs(localFilename, hdfsFilename, true, true); } catch (Exception e) { + try { + FileUtils.deleteFile(localFilename); + } catch (IOException ex) { + logger.error("delete local tmp file:{} error", localFilename, ex); + } logger.error(e.getMessage(), e); return false; } diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java index bf47eb8bd4..e64c082f81 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java @@ -398,7 +398,10 @@ public class FileUtils { * @throws IOException in case deletion is unsuccessful */ public static void deleteFile(String filename) throws IOException { - org.apache.commons.io.FileUtils.forceDelete(new File(filename)); + File file = new File(filename); + if (file.exists()) { + org.apache.commons.io.FileUtils.forceDelete(file); + } } /**