Skip to content

Commit 1830afd

Browse files
committed
Tolerate Gradle symlink creation race condition
1 parent 3f10627 commit 1830afd

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

Sources/SkipDrive/GradleHarness.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,16 @@ extension GradleHarness {
8383
let linkFrom = localModuleLink.path, linkTo = outputFolder.path
8484
if (try? FileManager.default.destinationOfSymbolicLink(atPath: linkFrom)) != linkTo {
8585
try? FileManager.default.removeItem(atPath: linkFrom) // if it exists
86-
try FileManager.default.createSymbolicLink(atPath: linkFrom, withDestinationPath: linkTo)
86+
do {
87+
try FileManager.default.createSymbolicLink(atPath: linkFrom, withDestinationPath: linkTo)
88+
} catch {
89+
// Concurrent test targets in the same package race to create the same symlink
90+
// (same linkFrom, same linkTo). If another target won the race, the link will
91+
// already point where we want — treat that as success.
92+
if (try? FileManager.default.destinationOfSymbolicLink(atPath: linkFrom)) != linkTo {
93+
throw error
94+
}
95+
}
8796
}
8897

8998
let localTranspilerOut = URL(fileURLWithPath: outputFolder.lastPathComponent, isDirectory: true, relativeTo: localModuleLink)

0 commit comments

Comments
 (0)