@@ -2067,9 +2067,6 @@ std::string DefaultHomePath()
20672067#ifdef __APPLE__
20682068 return std::string (home) + " /Library/Application Support/" PRODUCT_NAME;
20692069#else
2070- struct stat stl, stx;
2071-
2072- std::string legacyHomePath = Path::Build (std::string (home), " ." PRODUCT_NAME_LOWER);
20732070 const char * _xdgDataHome = getenv (" XDG_DATA_HOME" );
20742071 std::string xdgDataHome = _xdgDataHome == NULL ? " " : std::string (_xdgDataHome);
20752072 std::string xdgHomePath;
@@ -2080,6 +2077,32 @@ std::string DefaultHomePath()
20802077
20812078 xdgHomePath = Path::Build (xdgDataHome, PRODUCT_NAME_LOWER);
20822079
2080+ return xdgHomePath;
2081+ #endif
2082+ #endif
2083+ }
2084+
2085+ void MigrateHomePath (std::string cmdlineHomePath)
2086+ {
2087+ #if defined(__linux__)
2088+ std::string xdgHomePath = DefaultHomePath ();
2089+
2090+ // if user set custom home path using -homepath arg, do nothing
2091+ if (! xdgHomePath.compare (cmdlineHomePath)) {
2092+ return ;
2093+ }
2094+
2095+ const char * home = getenv (" HOME" );
2096+ if (!home) {
2097+ // in this case DefaultHomePath() returned "",
2098+ // hence homePath is neither the legacy one neither
2099+ // the xdg one, hence there is nothing we can do.
2100+ return ;
2101+ }
2102+
2103+ std::string legacyHomePath = Path::Build (std::string (home), " ." PRODUCT_NAME_LOWER);
2104+ struct stat stl, stx;
2105+
20832106 if (lstat (legacyHomePath.c_str (), &stl) == 0 ) {
20842107 if (S_ISDIR (stl.st_mode ) || S_ISLNK (stl.st_mode )) {
20852108 if (stat (xdgHomePath.c_str (), &stx) != 0 ) {
@@ -2118,9 +2141,6 @@ std::string DefaultHomePath()
21182141 }
21192142 }
21202143 }
2121-
2122- return xdgHomePath;
2123- #endif
21242144#endif
21252145}
21262146#endif // BUILD_VM
@@ -2176,6 +2196,8 @@ static Util::optional<std::string> GetRealPath(Str::StringRef path, std::string&
21762196
21772197void Initialize (Str::StringRef homePath, Str::StringRef libPath, const std::vector<std::string>& paths)
21782198{
2199+ MigrateHomePath (homePath);
2200+
21792201 // Create the homepath and its pkg directory to avoid any issues later on
21802202 std::error_code err;
21812203 RawPath::CreatePathTo (FS::Path::Build (homePath, " pkg" ) + " /" , err);
0 commit comments