GHOST/Unix: always use getpwuid for home directory access
getpwuid for accessing home wasn't used when looking up the path for older Blender versions. There is no reason for the code-paths to differ. Use a shared utility function to access home.
This commit is contained in:
@@ -42,6 +42,17 @@ const char *GHOST_SystemPathsUnix::getSystemDir(int /*version*/, const char *ver
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static const char *home_dir_get()
|
||||
{
|
||||
const char *home_dir = getenv("HOME");
|
||||
if (home_dir == nullptr) {
|
||||
if (const passwd *pwuser = getpwuid(getuid())) {
|
||||
home_dir = pwuser->pw_dir;
|
||||
}
|
||||
}
|
||||
return home_dir;
|
||||
}
|
||||
|
||||
const char *GHOST_SystemPathsUnix::getUserDir(int version, const char *versionstr) const
|
||||
{
|
||||
static string user_path = "";
|
||||
@@ -51,7 +62,7 @@ const char *GHOST_SystemPathsUnix::getUserDir(int version, const char *versionst
|
||||
* operator works we give a different path depending on the requested version */
|
||||
if (version < 264) {
|
||||
if (user_path.empty() || last_version != version) {
|
||||
const char *home = getenv("HOME");
|
||||
const char *home = home_dir_get();
|
||||
|
||||
last_version = version;
|
||||
|
||||
@@ -73,13 +84,7 @@ const char *GHOST_SystemPathsUnix::getUserDir(int version, const char *versionst
|
||||
user_path = string(home) + "/blender/" + versionstr;
|
||||
}
|
||||
else {
|
||||
home = getenv("HOME");
|
||||
if (home == nullptr) {
|
||||
if (const passwd *pwuser = getpwuid(getuid())) {
|
||||
home = pwuser->pw_dir;
|
||||
}
|
||||
}
|
||||
|
||||
const char *home = home_dir_get();
|
||||
if (home) {
|
||||
user_path = string(home) + "/.config/blender/" + versionstr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user