Open ulrikstrid opened 6 years ago
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
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%.
I wouldn't fall back on
%USERPROFILE%
, though - better to fall back to the user's Documents folder, which is retrieved usingSHGetKnownFolderPath
withFOLDERID_Documents
(or, with Windows XP compatibility, the slightly olderSHGetFolderPath
withCSIDL_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\DocumentsFOLDERID_Profile
: C:\Users\username
The environment variable
HOME
is not standard on Windows and should probably fallback toUSERPROFILE
.