Skip to content
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

HOME is usually not set on Windows #77

Open
ulrikstrid opened this issue Aug 23, 2018 · 3 comments
Open

HOME is usually not set on Windows #77

ulrikstrid opened this issue Aug 23, 2018 · 3 comments

Comments

@ulrikstrid
Copy link

The environment variable HOME is not standard on Windows and should probably fallback to USERPROFILE.

@dbuenzli
Copy link
Owner

Thanks for the report. The current full logic for windows is here.

Could you please suggest the best logic for it ? Simply lookup the USERPROFILE env var ?

/cc @dra27

@dra27
Copy link

dra27 commented Aug 24, 2018

I would certainly read HOME first (i.e. read something from the environment) since, as with Unix, it allows you to temporarily tell one program to use a different directory. Regardless of what node does, I wouldn't fall back on %USERPROFILE%, though - better to fall back to the user's Documents folder, which is retrieved using SHGetKnownFolderPath with FOLDERID_Documents (or, with Windows XP compatibility, the slightly older SHGetFolderPath with CSIDL_PERSONAL - see the stub in opam.

The reason for preferring that is that %USERPROFILE% will almost never be roaming, where the Documents folder will either be set for roaming or using folder redirection (which is very, very loosely the Windows equivalent of having an NFS-mounted home directory).

As an aside, if you expressly wanted the data not to roam (for example, for caches generated on a per-machine basis), you'd be better using %LOCALAPPDATA% or the CSIDL_LOCAL_APPDATA/FOLDERID_LocalAppData rather than %USERPROFILE%.

@dbuenzli dbuenzli added enhancement and removed bug labels Aug 24, 2018
@favonia
Copy link

favonia commented Apr 27, 2022

I wouldn't fall back on %USERPROFILE%, though - better to fall back to the user's Documents folder, which is retrieved using SHGetKnownFolderPath with FOLDERID_Documents (or, with Windows XP compatibility, the slightly older SHGetFolderPath with CSIDL_PERSONAL - see the stub in opam.

@dra27 OPAM might have good reasons to use FOLDERID_Documents (especially if it's going to create something directly under that folder), but for a general library such as bos, I think FOLDERID_Profile (or CSIDL_PROFILE on Windows XP) is more appropriate. This is what %USERPROFILE% corresponds to.

PS: Programs should not create new stuff directly under FOLDERID_Profile---there are many other folders for specific purposes, one of them mentioned by @dra27 for local application data. In a sense it's like the XDG standard discouraging people from creating ~/.foo.

PPS: For people who are less familiar with the Windows API, here are the typical values of the two folders:

  • FOLDERID_Documents: C:\Users\username\Documents
  • FOLDERID_Profile: C:\Users\username

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants