Skip to content

Commit f094a0e

Browse files
basilNotMyFault
authored andcommitted
[JENKINS-67624] FileAlreadyExistsException on startup (jenkinsci#7027)
(cherry picked from commit 6b0dc18)
1 parent 10740f9 commit f094a0e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

core/src/main/java/hudson/Util.java

+19-2
Original file line numberDiff line numberDiff line change
@@ -1778,15 +1778,32 @@ public static Path createDirectories(@NonNull Path dir, FileAttribute<?>... attr
17781778
if (Files.isDirectory(dir)) {
17791779
return dir;
17801780
} else {
1781-
return Files.createDirectory(dir, attrs);
1781+
try {
1782+
return Files.createDirectory(dir, attrs);
1783+
} catch (FileAlreadyExistsException e) {
1784+
if (Files.isDirectory(dir)) {
1785+
// a concurrent caller won the race
1786+
return dir;
1787+
} else {
1788+
throw e;
1789+
}
1790+
}
17821791
}
17831792
}
17841793

17851794
Path child = parent;
17861795
for (Path name : parent.relativize(dir)) {
17871796
child = child.resolve(name);
17881797
if (!Files.isDirectory(child)) {
1789-
Files.createDirectory(child, attrs);
1798+
try {
1799+
Files.createDirectory(child, attrs);
1800+
} catch (FileAlreadyExistsException e) {
1801+
if (Files.isDirectory(child)) {
1802+
// a concurrent caller won the race
1803+
} else {
1804+
throw e;
1805+
}
1806+
}
17901807
}
17911808
}
17921809

0 commit comments

Comments
 (0)