From 6b0dc184bf7c6b229915b98170db65c48e956dc0 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Wed, 24 Aug 2022 10:45:13 -0700 Subject: [PATCH] [JENKINS-67624] `FileAlreadyExistsException` on startup (#7027) --- core/src/main/java/hudson/Util.java | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/hudson/Util.java b/core/src/main/java/hudson/Util.java index 51abbf86a1aa..2f88c274972e 100644 --- a/core/src/main/java/hudson/Util.java +++ b/core/src/main/java/hudson/Util.java @@ -1778,7 +1778,16 @@ public static Path createDirectories(@NonNull Path dir, FileAttribute... attr if (Files.isDirectory(dir)) { return dir; } else { - return Files.createDirectory(dir, attrs); + try { + return Files.createDirectory(dir, attrs); + } catch (FileAlreadyExistsException e) { + if (Files.isDirectory(dir)) { + // a concurrent caller won the race + return dir; + } else { + throw e; + } + } } } @@ -1786,7 +1795,15 @@ public static Path createDirectories(@NonNull Path dir, FileAttribute... attr for (Path name : parent.relativize(dir)) { child = child.resolve(name); if (!Files.isDirectory(child)) { - Files.createDirectory(child, attrs); + try { + Files.createDirectory(child, attrs); + } catch (FileAlreadyExistsException e) { + if (Files.isDirectory(child)) { + // a concurrent caller won the race + } else { + throw e; + } + } } }