Skip to content

Commit c30c40a

Browse files
Fix parallel directory creation (#15)
1 parent d00585d commit c30c40a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Sources/SwiftAstGenLib/SwiftAstGenerator.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ public class SwiftAstGenerator {
77
private var prettyPrint: Bool
88
private let availableProcessors = ProcessInfo.processInfo.activeProcessorCount
99

10+
// Private serial queue for directory creation operations
11+
private let fileQueue = DispatchQueue(label: "io.joern.swiftastgen")
12+
1013
public init(srcDir: URL, outputDir: URL, prettyPrint: Bool) throws {
1114
self.srcDir = srcDir
1215
self.outputDir = outputDir
@@ -45,11 +48,13 @@ public class SwiftAstGenerator {
4548
let outfileDirUrl = outFileUrl.deletingLastPathComponent()
4649

4750
do {
48-
try FileManager.default.createDirectory(
49-
atPath: outfileDirUrl.path,
50-
withIntermediateDirectories: true,
51-
attributes: nil
52-
)
51+
try fileQueue.sync {
52+
try FileManager.default.createDirectory(
53+
atPath: outfileDirUrl.path,
54+
withIntermediateDirectories: true,
55+
attributes: nil
56+
)
57+
}
5358
} catch {}
5459

5560
try astJsonString.write(

0 commit comments

Comments
 (0)