Skip to content

Commit

Permalink
Optimize availability check code flow (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfed authored Jan 1, 2025
1 parent 2babda3 commit 8b32d54
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
5 changes: 2 additions & 3 deletions Plugins/SafeDIGenerator/SafeDIGenerateDependencyTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,10 @@ extension Data {
#if os(Linux)
try write(to: URL(fileURLWithPath: filePath))
#else
if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) {
try write(to: URL(filePath: filePath))
} else {
guard #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) else {
try write(to: URL(fileURLWithPath: filePath))
}
try write(to: URL(filePath: filePath))
#endif
}
}
Expand Down
9 changes: 4 additions & 5 deletions Sources/SafeDITool/SafeDITool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,12 @@ extension String {

fileprivate var asFileURL: URL {
#if os(Linux)
URL(fileURLWithPath: self)
return URL(fileURLWithPath: self)
#else
if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) {
URL(filePath: self)
} else {
URL(fileURLWithPath: self)
guard #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) else {
return URL(fileURLWithPath: self)
}
return URL(filePath: self)
#endif
}
}
Expand Down
9 changes: 4 additions & 5 deletions Tests/SafeDIToolTests/Helpers/SafeDIToolTestExecution.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,12 @@ struct TestOutput {
extension URL {
fileprivate static var temporaryFile: URL {
#if os(Linux)
FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
return FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
#else
if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) {
URL.temporaryDirectory.appending(path: UUID().uuidString)
} else {
FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
guard #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) else {
return FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
}
return URL.temporaryDirectory.appending(path: UUID().uuidString)
#endif
}
}
Expand Down

0 comments on commit 8b32d54

Please sign in to comment.