Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions src/common/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2067,18 +2067,33 @@ std::string DefaultHomePath()
#ifdef __APPLE__
return std::string(home) + "/Library/Application Support/" PRODUCT_NAME;
#else
struct stat stl, stx;

std::string legacyHomePath = Path::Build(std::string(home), "." PRODUCT_NAME_LOWER);
const char* _xdgDataHome = getenv("XDG_DATA_HOME");
std::string xdgDataHome = _xdgDataHome == NULL ? "" : std::string(_xdgDataHome);
std::string xdgDataHome = _xdgDataHome == NULL ? Path::Build(Path::Build(std::string(home), ".local") ,"share") : std::string(_xdgDataHome);
std::string xdgHomePath;

if (xdgDataHome.empty()) {
xdgDataHome = Path::Build(Path::Build(std::string(home), ".local") ,"share");
xdgHomePath = Path::Build(xdgDataHome, PRODUCT_NAME_LOWER);

return xdgHomePath;
#endif
#endif
}

void MigrateHomePath()
{
#if defined(__linux__)
const char* home = getenv("HOME");
if (!home) {
// in this case DefaultHomePath() will return "",
// hence homePath will be neither the legacy one
// neither the xdg one, hence there is nothing we can do.
return;
}

xdgHomePath = Path::Build(xdgDataHome, PRODUCT_NAME_LOWER);
const char* _xdgDataHome = getenv("XDG_DATA_HOME");
std::string xdgDataHome = _xdgDataHome == NULL ? Path::Build(Path::Build(std::string(home), ".local") ,"share") : std::string(_xdgDataHome);
std::string xdgHomePath = DefaultHomePath();
std::string legacyHomePath = Path::Build(std::string(home), "." PRODUCT_NAME_LOWER);
struct stat stl, stx;

if (lstat(legacyHomePath.c_str(), &stl) == 0) {
if (S_ISDIR(stl.st_mode) || S_ISLNK(stl.st_mode)) {
Expand Down Expand Up @@ -2118,9 +2133,6 @@ std::string DefaultHomePath()
}
}
}

return xdgHomePath;
#endif
#endif
}
#endif // BUILD_VM
Expand Down
1 change: 1 addition & 0 deletions src/common/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ void Initialize();
#else
std::string DefaultBasePath();
std::string DefaultHomePath();
void MigrateHomePath();
void Initialize(Str::StringRef homePath, Str::StringRef libPath, const std::vector<std::string>& paths);
#endif

Expand Down
6 changes: 6 additions & 0 deletions src/engine/framework/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ static void ParseCmdline(int argc, char** argv, cmdlineArgs_t& cmdlineArgs)
#endif

bool foundCommands = false;
bool foundHomePathCommand = false;
for (int i = 1; i < argc; i++) {
// A + indicate the start of a command that should be run on startup
if (argv[i][0] == '+') {
Expand Down Expand Up @@ -489,6 +490,7 @@ static void ParseCmdline(int argc, char** argv, cmdlineArgs_t& cmdlineArgs)
Log::Warn("Missing argument for -homepath");
continue;
}
foundHomePathCommand = true;
cmdlineArgs.homePath = argv[i + 1];
i++;
} else if (!strcmp(argv[i], "-resetconfig")) {
Expand All @@ -504,6 +506,10 @@ static void ParseCmdline(int argc, char** argv, cmdlineArgs_t& cmdlineArgs)
continue;
}
}

if (!foundHomePathCommand) {
FS::MigrateHomePath();
}
}

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