Skip to content

Commit 864c40b

Browse files
committed
do not migrate legacy homepath when using -homepath arg
1 parent 58db7c8 commit 864c40b

1 file changed

Lines changed: 31 additions & 10 deletions

File tree

src/common/FileSystem.cpp

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,18 +2067,40 @@ 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");
2074-
std::string xdgDataHome = _xdgDataHome == NULL ? "" : std::string(_xdgDataHome);
2071+
std::string xdgDataHome = _xdgDataHome == NULL ? Path::Build(Path::Build(std::string(home), ".local") ,"share") : std::string(_xdgDataHome);
20752072
std::string xdgHomePath;
20762073

2077-
if (xdgDataHome.empty()) {
2078-
xdgDataHome = Path::Build(Path::Build(std::string(home), ".local") ,"share");
2074+
xdgHomePath = Path::Build(xdgDataHome, PRODUCT_NAME_LOWER);
2075+
2076+
return xdgHomePath;
2077+
#endif
2078+
#endif
2079+
}
2080+
2081+
void MigrateHomePath(std::string cmdlineHomePath)
2082+
{
2083+
#if defined(__linux__)
2084+
std::string xdgHomePath = DefaultHomePath();
2085+
2086+
// if user set custom home path using -homepath arg, do nothing
2087+
if (! xdgHomePath.compare(cmdlineHomePath)) {
2088+
return;
2089+
}
2090+
2091+
const char* _xdgDataHome = getenv("XDG_DATA_HOME");
2092+
std::string xdgDataHome = _xdgDataHome == NULL ? Path::Build(Path::Build(std::string(home), ".local") ,"share") : std::string(_xdgDataHome);
2093+
2094+
const char* home = getenv("HOME");
2095+
if (!home) {
2096+
// in this case DefaultHomePath() returned "",
2097+
// hence homePath is neither the legacy one neither
2098+
// the xdg one, hence there is nothing we can do.
2099+
return;
20792100
}
20802101

2081-
xdgHomePath = Path::Build(xdgDataHome, PRODUCT_NAME_LOWER);
2102+
std::string legacyHomePath = Path::Build(std::string(home), "." PRODUCT_NAME_LOWER);
2103+
struct stat stl, stx;
20822104

20832105
if (lstat(legacyHomePath.c_str(), &stl) == 0) {
20842106
if (S_ISDIR(stl.st_mode) || S_ISLNK(stl.st_mode)) {
@@ -2118,9 +2140,6 @@ std::string DefaultHomePath()
21182140
}
21192141
}
21202142
}
2121-
2122-
return xdgHomePath;
2123-
#endif
21242143
#endif
21252144
}
21262145
#endif // BUILD_VM
@@ -2176,6 +2195,8 @@ static Util::optional<std::string> GetRealPath(Str::StringRef path, std::string&
21762195

21772196
void Initialize(Str::StringRef homePath, Str::StringRef libPath, const std::vector<std::string>& paths)
21782197
{
2198+
MigrateHomePath(homePath);
2199+
21792200
// Create the homepath and its pkg directory to avoid any issues later on
21802201
std::error_code err;
21812202
RawPath::CreatePathTo(FS::Path::Build(homePath, "pkg") + "/", err);

0 commit comments

Comments
 (0)