Skip to content

Commit 5b92c82

Browse files
authored
Merge pull request #2286 from bnbarham/infinite-root
Use native root check on Windows
2 parents 56ca242 + ad69881 commit 5b92c82

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

Sources/SwiftExtensions/URLExtensions.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
package import Foundation
1414

15+
#if os(Windows)
16+
import WinSDK
17+
#endif
18+
1519
enum FilePathError: Error, CustomStringConvertible {
1620
case noFileSystemRepresentation(URL)
1721
case noFileURL(URL)
@@ -84,14 +88,14 @@ extension URL {
8488
}
8589

8690
package var isRoot: Bool {
87-
#if os(Windows)
88-
// FIXME: We should call into Windows' native check to check if this path is a root once https://github.com/swiftlang/swift-foundation/issues/976 is fixed.
89-
return self.pathComponents.count <= 1
90-
#else
91-
// On Linux, we may end up with an string for the path due to https://github.com/swiftlang/swift-foundation/issues/980
92-
// TODO: Remove the check for "" once https://github.com/swiftlang/swift-foundation/issues/980 is fixed.
93-
return self.path == "/" || self.path == ""
94-
#endif
91+
get throws {
92+
let checkPath = try filePath
93+
#if os(Windows)
94+
return checkPath.withCString(encodedAs: UTF16.self, PathCchIsRoot)
95+
#else
96+
return checkPath == "/"
97+
#endif
98+
}
9599
}
96100

97101
/// Returns true if the path of `self` starts with the path in `other`.

Sources/ToolchainRegistry/Toolchain.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ func containingXCToolchain(
370370
_ path: URL
371371
) -> (XCToolchainPlist, URL)? {
372372
var path = path
373-
while !path.isRoot {
373+
while !((try? path.isRoot) ?? true) {
374374
if path.pathExtension == "xctoolchain" {
375375
if let infoPlist = orLog("Loading information from xctoolchain", { try XCToolchainPlist(fromDirectory: path) }) {
376376
return (infoPlist, path)

0 commit comments

Comments
 (0)