Skip to content

Commit 4074f4d

Browse files
authored
Don't fail createDirectory if directory is created concurrently by another process (#490)
1 parent 21929be commit 4074f4d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Diff for: Sources/TSCBasic/FileSystem.swift

+11-1
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,17 @@ private struct LocalFileSystem: FileSystem {
494494
// Don't fail if path is already a directory.
495495
if isDirectory(path) { return }
496496

497-
try FileManager.default.createDirectory(atPath: path.pathString, withIntermediateDirectories: recursive, attributes: [:])
497+
do {
498+
try FileManager.default.createDirectory(atPath: path.pathString, withIntermediateDirectories: recursive, attributes: [:])
499+
} catch {
500+
if isDirectory(path) {
501+
// `createDirectory` failed but we have a directory now. This might happen if the directory is created
502+
// by another process between the check above and the call to `createDirectory`.
503+
// Since we have the expected end result, this is fine.
504+
return
505+
}
506+
throw error
507+
}
498508
}
499509

500510
func createSymbolicLink(_ path: AbsolutePath, pointingAt destination: AbsolutePath, relative: Bool) throws {

0 commit comments

Comments
 (0)