-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PathCchIsRoot Updated isRoot extension. #892
Conversation
We can’t switch this unconditionally yet because those fixes aren’t in Swift 6.0 toolchains. I think we need to guard this by |
4413e7c
to
39bd050
Compare
OK, I gated the new behavior behind a check for >=6.1. Below that the old code is still in place. The Mac behavior isn't gated as it most certainly isn't new. 😄 |
#if os(Windows) | ||
// 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. | ||
return self.path.withCString(encodedAs: UTF16.self, PathCchIsRoot) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path
will be the URL path components. We should use filePath
or withUnsafeFileSystemRepresentation
instead.
#if os(Windows) | ||
// 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. | ||
return self.path.withCString(encodedAs: UTF16.self, PathCchIsRoot) | ||
#elseif os(Linux) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be #else
. Otherwise this function doesn’t have a return value eg. on platforms that are neither macOS, Linux, nor Windows, like Android.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had that thought and will fix it.
#endif | ||
|
||
#if compiler(>=6.1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change this to #elseif compiler(>=6.1)
to ensure we don’t get any of the returns below for macOS
39bd050
to
5c78f86
Compare
OK. I updated with the suggested changes, but note that I don't have my Windows setup with me right now. If someone can run the tests on Windows it would be great. |
Now that swiftlang/swift-foundation#976 and swiftlang/swift-foundation#980 are fixed we can clean this code up a bit by removing the empty path check on Linux and by using the native `PathCchIsRoot` on Windows. Existing code is retained for toolchains <6.1
5c78f86
to
f077071
Compare
I updated your branch make it build on Windows. I also removed the macOS-specific call to |
Now that swiftlang/swift-foundation#976 and swiftlang/swift-foundation#980 are fixed we can clean this code up a bit by removing the empty path check on Linux and by using the native
PathCchIsRoot
on Windows.The
isRoot
extension now uses native Windows and macOS API and has the Linux tests cleaned up.NSOpenStepRootDirectory()
PathCchIsRoot
"/"
Fixes: #844
All tests pass on macOS and Windows 11.