diff --git a/src/common/FileSystem.cpp b/src/common/FileSystem.cpp index d1d45b7110..c7ee462a6a 100644 --- a/src/common/FileSystem.cpp +++ b/src/common/FileSystem.cpp @@ -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)) { @@ -2118,9 +2133,6 @@ std::string DefaultHomePath() } } } - - return xdgHomePath; -#endif #endif } #endif // BUILD_VM diff --git a/src/common/FileSystem.h b/src/common/FileSystem.h index 6bd5dd6078..7a225084b7 100644 --- a/src/common/FileSystem.h +++ b/src/common/FileSystem.h @@ -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& paths); #endif diff --git a/src/engine/framework/System.cpp b/src/engine/framework/System.cpp index 9ed3090b26..9e53db3cb3 100644 --- a/src/engine/framework/System.cpp +++ b/src/engine/framework/System.cpp @@ -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] == '+') { @@ -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")) { @@ -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