Skip to content

Commit c7aef3e

Browse files
authored
Merge pull request #59 from illwieckz/xdgfix
do not migrate legacy homepath when using -homepath arg
2 parents 0e6e741 + b31843c commit c7aef3e

3 files changed

Lines changed: 29 additions & 10 deletions

File tree

src/common/FileSystem.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,18 +2067,33 @@ 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()
2082+
{
2083+
#if defined(__linux__)
2084+
const char* home = getenv("HOME");
2085+
if (!home) {
2086+
// in this case DefaultHomePath() will return "",
2087+
// hence homePath will be neither the legacy one
2088+
// neither the xdg one, hence there is nothing we can do.
2089+
return;
20792090
}
20802091

2081-
xdgHomePath = Path::Build(xdgDataHome, PRODUCT_NAME_LOWER);
2092+
const char* _xdgDataHome = getenv("XDG_DATA_HOME");
2093+
std::string xdgDataHome = _xdgDataHome == NULL ? Path::Build(Path::Build(std::string(home), ".local") ,"share") : std::string(_xdgDataHome);
2094+
std::string xdgHomePath = DefaultHomePath();
2095+
std::string legacyHomePath = Path::Build(std::string(home), "." PRODUCT_NAME_LOWER);
2096+
struct stat stl, stx;
20822097

20832098
if (lstat(legacyHomePath.c_str(), &stl) == 0) {
20842099
if (S_ISDIR(stl.st_mode) || S_ISLNK(stl.st_mode)) {
@@ -2118,9 +2133,6 @@ std::string DefaultHomePath()
21182133
}
21192134
}
21202135
}
2121-
2122-
return xdgHomePath;
2123-
#endif
21242136
#endif
21252137
}
21262138
#endif // BUILD_VM

src/common/FileSystem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ void Initialize();
485485
#else
486486
std::string DefaultBasePath();
487487
std::string DefaultHomePath();
488+
void MigrateHomePath();
488489
void Initialize(Str::StringRef homePath, Str::StringRef libPath, const std::vector<std::string>& paths);
489490
#endif
490491

src/engine/framework/System.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ static void ParseCmdline(int argc, char** argv, cmdlineArgs_t& cmdlineArgs)
418418
#endif
419419

420420
bool foundCommands = false;
421+
bool foundHomePathCommand = false;
421422
for (int i = 1; i < argc; i++) {
422423
// A + indicate the start of a command that should be run on startup
423424
if (argv[i][0] == '+') {
@@ -489,6 +490,7 @@ static void ParseCmdline(int argc, char** argv, cmdlineArgs_t& cmdlineArgs)
489490
Log::Warn("Missing argument for -homepath");
490491
continue;
491492
}
493+
foundHomePathCommand = true;
492494
cmdlineArgs.homePath = argv[i + 1];
493495
i++;
494496
} else if (!strcmp(argv[i], "-resetconfig")) {
@@ -504,6 +506,10 @@ static void ParseCmdline(int argc, char** argv, cmdlineArgs_t& cmdlineArgs)
504506
continue;
505507
}
506508
}
509+
510+
if (!foundHomePathCommand) {
511+
FS::MigrateHomePath();
512+
}
507513
}
508514

509515
// Apply a -set argument early, before the configuration files are loaded

0 commit comments

Comments
 (0)