-
Notifications
You must be signed in to change notification settings - Fork 1.2k
FileManager: repair homeDirectoryForCurrentUser
on Windows
#4695
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
Conversation
CC: @parkera |
@swift-ci please test |
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'd like to understand more about what is failing in homeDirectory(forUser:)
. It looks like it's going through the same steps as your fix here, with the exception of checking that the username isn't an empty string, and using a guard on the user directory URL (any safety gained by that is immediately lost by the force-unwrap at the upper layer, so I don't consider that to be all that different). Is NSUserName()
not working right for the current user?
It isn't By passing in the explicit |
We should probably fix For performance/inlining/fast-pathing, I'm fine with the direct |
0b95e12
to
f644506
Compare
@swift-ci please test |
`NetUserGetInfo` will not provide the home directory for the specified user most of the time, even if the user is the currently logged in user. Prefer to use the `CFCopyHomeDirectoryURLForUser` path which will provide the home directory for the current user. Fast-path that into the computed property and add a special case for `homeDirectory(forUser:)` to accommodate this behavioural difference.
f644506
to
0d37921
Compare
@swift-ci please test |
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'll accept it. It doesn't cause joy, but at least I can read it.
The
homeDirectory(forUser:)
is currently not functioning properly for users other than the current user. Switch to directly using the CoreFoundation API which simplifies the logic and makes the functionality work on Windows. This uses the forced unwrap for the return value, which was previously the case and resulted in a trap on Windows.