Skip to content

Commit

Permalink
Don't fail createDirectory if directory is created concurrently by …
Browse files Browse the repository at this point in the history
…another process (#490)
  • Loading branch information
ahoppen authored Oct 29, 2024
1 parent 21929be commit 4074f4d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Sources/TSCBasic/FileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,17 @@ private struct LocalFileSystem: FileSystem {
// Don't fail if path is already a directory.
if isDirectory(path) { return }

try FileManager.default.createDirectory(atPath: path.pathString, withIntermediateDirectories: recursive, attributes: [:])
do {
try FileManager.default.createDirectory(atPath: path.pathString, withIntermediateDirectories: recursive, attributes: [:])
} catch {
if isDirectory(path) {
// `createDirectory` failed but we have a directory now. This might happen if the directory is created
// by another process between the check above and the call to `createDirectory`.
// Since we have the expected end result, this is fine.
return
}
throw error
}
}

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

0 comments on commit 4074f4d

Please sign in to comment.