-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
env::home_dir()
should use SHGetKnownFolderPath()
on windows.
#28940
Comments
Adding to this, |
By looking at the code, it seems that As for |
Relevant PR which contains some related discussion. |
@barosl Oops, you're right. In that case, I'd say this is bad documentation - not mentioning |
@FaultyRAM I sent a PR that resolves the documentation issue, please review it: #28960. |
This concern was raised by rust-lang#28940.
@barosl Looks good! |
Believe it or not, this behavior has been here since literally the beginning (dafd649) of this module. The fallback to I'll also note that this basically matches what python does as well as what ruby does. My personal opinion is that it's working as intended. |
And in every case it just makes the user experience worse on windows. The convention for getting the home directory on windows is (obviously) to use the helpfully provided OS functions to do so. That's what .net, java and other software does, that has a runtime which is actually written for windows, and is not just a barely functioning wrapper in order to provide a unix-like interface. At best, the python and ruby interpreters can be slightly let off the hook as they are scripting languages, and so you might expect behaviour to be a little "fuzzy" with respect to the environment. At worst, they're shoving unix-like conventions onto a platform where they don't work or belong. It's also one of the reasons why msys doesn't try to override the If you want a unix-like environment on windows, then target msys or cygwin - it's what they're there for after all... If you don't, then don't start looking for unix environment variables! |
I am personally in favor of disregarding the environment variables entirely and just calling the OS function directly and leaving it at that. |
nominating so libs can make a call on what's the right behavior here |
I believe this definition is incorrect as both cargo and rustup do not use it, because considering I think we should deprecate the current function and define a new one that cargo and rustup use, thus proving it is usable for real applications. |
I agree with @brson. Anyone want to take on making a PR for this? |
What name should the new one have? |
How about |
See also #40320 |
It seems a shame to have to pick slightly worse names for things each time we deprecate something. |
On the spectrum of acceptable breakage, how bad is changing |
My vote, for what it's worth, would be to just treat the current behavior on windows as a bug, and fix it. Is anyone aware of rust code that relies on the current Windows behavior? |
Let's get a PR that fixes the bug and go from there. |
We decided against making this change in #46799. #46799 (comment) proposes possible next steps for handling this better in an external crate. |
|
@soc - how is it broken on Linux? I'm trying to figure out why home_dir was deprecated when it's working great for me on Linux. |
At the moment, it first looks at
%HOME%
, and then at%USERPROFILE%
. This is bad for two reasons:The home directory will be different when run from an msys or cygwin terminal. Unless the program is specifically compiled to run in an msys/cygwin environment (they have their own target triples) then it should not be affected by
%HOME%
(only%USERPROFILE%
stores the home directory on windows).Environment variables may be overridden.
SHGetKnownFolderPath()
will always give the correct path to the user's home folder.The text was updated successfully, but these errors were encountered: