I do not have reproducible code as it happens in our pipeline 1/3 times. But that is a very elaborate swift code generation library that for my client. But the code I use is very simple and based on GitHub - doozMen/Files: A nicer way to handle files & folders in Swift.
I have asked around about the files issue on the forum Task safe way to write a file asynchronously - #4 by Karl
Basically my code is
import ArgumentParser // https://github.com/apple/swift-argument-parser
import Files // https://github.com/doozMen/Files
struct Write: AsyncParsableCommand {
func run() async throws {
let files = try ["foo.swift", "bar.swift"]
.map { try Folder.current.createFileIfNeeded(withName: $0) }
try await withThrowingTaskGroup(of: Void.self) { group in
for file in files {
group.addTask {
try await Task {
try file.write("// some data")
}.value
}
}
try await group.waitForAll()
}
}
}
Basically if you use version of Files 4.2.1 that does not use @MainActor
for the file write you will get 1 out of 3 times on Ubuntu 22.04 arm64 one of the files that is empty. If you use the version on main from Files it is slower but I never have it.