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

zhongjiajie pushed a commit to branch 3.2.1-prepare
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git

commit eff7364ee1b58e17abb8526950561915cf3dda0c
Author: Wenjun Ruan <wen...@apache.org>
AuthorDate: Tue Feb 6 11:59:07 2024 +0800

    Fix create parent directory will cause FileAlreadyExistsException (#15576)
    
    Co-authored-by: Rick Cheng <rickche...@gmail.com>
    (cherry picked from commit 4541e74e531eccc4141865cf44433753a4ed0b17)
---
 .../org/apache/dolphinscheduler/common/utils/FileUtils.java    | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

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 1f3ccfed3d..fee1d9a95c 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
@@ -35,6 +35,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.FileAlreadyExistsException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.attribute.PosixFilePermission;
@@ -287,8 +288,13 @@ public class FileUtils {
                 createDirectoryWith755(parent);
             }
 
-            Files.createDirectory(path);
-            Files.setPosixFilePermissions(path, PERMISSION_755);
+            try {
+                Files.createDirectory(path);
+                Files.setPosixFilePermissions(path, PERMISSION_755);
+            } catch (FileAlreadyExistsException fileAlreadyExistsException) {
+                // Catch the FileAlreadyExistsException here to avoid create 
the same parent directory in parallel
+                log.debug("The directory: {} already exists", path);
+            }
 
         }
     }

Reply via email to