Introduce guarded filepath provider for file collection (#6435)

This commit is contained in:
Danny Mösch
2026-01-15 00:06:13 +01:00
committed by GitHub
parent 9a634bc8a0
commit faa5859155
8 changed files with 61 additions and 8 deletions
@@ -5,6 +5,18 @@ public extension URL {
withUnsafeFileSystemRepresentation { String(cString: $0!) }
}
var filepathGuarded: String? {
withUnsafeFileSystemRepresentation { ptr in
guard let ptr else {
Issue.genericError(
"File with URL '\(self)' cannot be represented as a file system path; skipping it"
).print()
return nil
}
return String(cString: ptr)
}
}
var isSwiftFile: Bool {
filepath.isFile && pathExtension == "swift"
}