@@ -2069,7 +2069,6 @@ std::string DefaultHomePath()
20692069#else
20702070 struct stat stl, stx;
20712071
2072- std::string legacyHomePath = Path::Build (std::string (home), " ." PRODUCT_NAME_LOWER);
20732072 const char * _xdgDataHome = getenv (" XDG_DATA_HOME" );
20742073 std::string xdgDataHome = _xdgDataHome == NULL ? " " : std::string (_xdgDataHome);
20752074 std::string xdgHomePath;
@@ -2080,6 +2079,31 @@ std::string DefaultHomePath()
20802079
20812080 xdgHomePath = Path::Build (xdgDataHome, PRODUCT_NAME_LOWER);
20822081
2082+ return xdgHomePath;
2083+ #endif
2084+ #endif
2085+ }
2086+
2087+ void MigrateHomePath (std::StringRef cmdlineHomePath)
2088+ {
2089+ #if defined(__linux__)
2090+ std::string xdgHomePath = DefaultHomePath ();
2091+
2092+ // if user set custom home path using -homepath arg, do nothing
2093+ if (! xdgHomePath.compare (cmdlineHomePath)) {
2094+ return ;
2095+ }
2096+
2097+ const char * home = getenv (" HOME" );
2098+ if (!home) {
2099+ // in this case DefaultHomePath() returned "" earlier,
2100+ // hence homePath is neither the legacy one neither the
2101+ // xdg one, hence there is nothing to do.
2102+ return
2103+ }
2104+
2105+ std::string legacyHomePath = Path::Build (std::string (home), " ." PRODUCT_NAME_LOWER);
2106+
20832107 if (lstat (legacyHomePath.c_str (), &stl) == 0 ) {
20842108 if (S_ISDIR (stl.st_mode ) || S_ISLNK (stl.st_mode )) {
20852109 if (stat (xdgHomePath.c_str (), &stx) != 0 ) {
@@ -2118,9 +2142,6 @@ std::string DefaultHomePath()
21182142 }
21192143 }
21202144 }
2121-
2122- return xdgHomePath;
2123- #endif
21242145#endif
21252146}
21262147#endif // BUILD_VM
@@ -2176,6 +2197,8 @@ static Util::optional<std::string> GetRealPath(Str::StringRef path, std::string&
21762197
21772198void Initialize (Str::StringRef homePath, Str::StringRef libPath, const std::vector<std::string>& paths)
21782199{
2200+ MigrateHomePath (homePath);
2201+
21792202 // Create the homepath and its pkg directory to avoid any issues later on
21802203 std::error_code err;
21812204 RawPath::CreatePathTo (FS::Path::Build (homePath, " pkg" ) + " /" , err);
0 commit comments