From dd1397aaed9b498357c8e6f7fb2311ed61660630 Mon Sep 17 00:00:00 2001 From: Yao WANG Date: Thu, 24 Feb 2022 17:36:54 +0800 Subject: [PATCH] [Bug] [Task-plugin] ShellTask add the parentfolder exist check and create if not exit (#8526) * check the parent dir exist and create it * fix lint Co-authored-by: ywang46 --- .../dolphinscheduler/plugin/task/shell/ShellTask.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-shell/src/main/java/org/apache/dolphinscheduler/plugin/task/shell/ShellTask.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-shell/src/main/java/org/apache/dolphinscheduler/plugin/task/shell/ShellTask.java index 5d9fb80ce1..45ca6b66e1 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-shell/src/main/java/org/apache/dolphinscheduler/plugin/task/shell/ShellTask.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-shell/src/main/java/org/apache/dolphinscheduler/plugin/task/shell/ShellTask.java @@ -124,7 +124,8 @@ public class ShellTask extends AbstractTaskExecutor { taskExecutionContext.getExecutePath(), taskExecutionContext.getTaskAppId(), OSUtils.isWindows() ? "bat" : "sh"); - Path path = new File(fileName).toPath(); + File file = new File(fileName); + Path path = file.toPath(); if (Files.exists(path)) { return fileName; @@ -143,6 +144,9 @@ public class ShellTask extends AbstractTaskExecutor { if (OSUtils.isWindows()) { Files.createFile(path); } else { + if (!file.getParentFile().exists()){ + file.getParentFile().mkdirs(); + } Files.createFile(path, attr); }