Skip to content

Commit c0c0edd

Browse files
Safer out dir creation
1 parent 17d3594 commit c0c0edd

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

Sources/SwiftAstGenLib/SwiftAstGenerator.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ public class SwiftAstGenerator {
1010
self.srcDir = srcDir
1111
self.outputDir = outputDir
1212
self.prettyPrint = prettyPrint
13-
if FileManager.default.fileExists(atPath: outputDir.path) {
14-
try FileManager.default.removeItem(at: outputDir)
13+
if !FileManager.default.fileExists(atPath: outputDir.path) {
14+
try FileManager.default.createDirectory(
15+
atPath: outputDir.path,
16+
withIntermediateDirectories: true,
17+
attributes: nil
18+
)
1519
}
16-
try FileManager.default.createDirectory(
17-
atPath: outputDir.path,
18-
withIntermediateDirectories: true,
19-
attributes: nil
20-
)
2120
}
2221

2322
private func ignoreDirectory(name: String) -> Bool {

0 commit comments

Comments
 (0)