You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
// Prefer standard environment variable USERPROFILE
ifhome:=os.Getenv("USERPROFILE"); home!="" {
returnhome, nil
}
drive:=os.Getenv("HOMEDRIVE")
path:=os.Getenv("HOMEPATH")
home:=drive+path
ifdrive==""||path=="" {
return"", errors.New("HOMEDRIVE, HOMEPATH, or USERPROFILE are blank")
}
returnhome, nil
}
TL;DR, change code to
funcdirWindows() (string, error) {
home:=os.Getenv("LOCALAPPDATA")
ifhome=="" {
return"", errors.New("LOCALAPPDATA environment variable is missing or empty")
}
returnhome, nil
}
$HOME is non-standard on Windows, and likely references $USERPROFILE. $USERPROFILE is not meant to be a location that applications store files other than via a save dialog box or similar situation where the user is explicitly putting files there. The proper location to store data that should be automatically synced to a network or uploaded to the cloud is $APPDATA. For data that should be machine-local (e.g., caches, application data, etc.) it should be stored in $LOCALAPPDATA.
In this library, it doesn't appear that you distinguish between data types so $LOCALAPPDATA is the best location. If someone throws a cache in there you don't break the user's profile.
Note: $LOCALAPPDATA has been around since Windows XP/2003 while the fallback you were using of $HOMEDRIVE I think has been deprecated and $HOMEPATH is fairly new (and I think also deprecated), so this is not only more correct, but also more backward compatible than the code currently present.
The text was updated successfully, but these errors were encountered:
go-homedir/homedir.go
Lines 148 to 167 in af06845
TL;DR, change code to
$HOME
is non-standard on Windows, and likely references$USERPROFILE
.$USERPROFILE
is not meant to be a location that applications store files other than via a save dialog box or similar situation where the user is explicitly putting files there. The proper location to store data that should be automatically synced to a network or uploaded to the cloud is$APPDATA
. For data that should be machine-local (e.g., caches, application data, etc.) it should be stored in$LOCALAPPDATA
.In this library, it doesn't appear that you distinguish between data types so
$LOCALAPPDATA
is the best location. If someone throws a cache in there you don't break the user's profile.Note:
$LOCALAPPDATA
has been around since Windows XP/2003 while the fallback you were using of$HOMEDRIVE
I think has been deprecated and$HOMEPATH
is fairly new (and I think also deprecated), so this is not only more correct, but also more backward compatible than the code currently present.The text was updated successfully, but these errors were encountered: