Skip to content

Commit

Permalink
[JENKINS-67624] FileAlreadyExistsException on startup (#7027)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Aug 24, 2022
1 parent 5779757 commit 6b0dc18
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions core/src/main/java/hudson/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -1778,15 +1778,32 @@ 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;
}
}
}
}

Path child = parent;
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;
}
}
}
}

Expand Down

0 comments on commit 6b0dc18

Please sign in to comment.