mirror of
https://github.com/meganz/MEGAcmd
synced 2025-08-29 04:47:42 +00:00
Merge branch 'CMD-433-dev-runtimedirpath-posix-fix' into 'develop'
CMD-433 - Fix PosixDirectory::runtimeDirPath prematurely returning a /tmp/ based path. See merge request apps/MEGAcmd!705
This commit is contained in:
commit
db60ef033d
@ -714,6 +714,10 @@ void ConfigurationManager::loadConfiguration(bool debug)
|
||||
|
||||
// Check if version has been updated.
|
||||
stringstream versionionfile;
|
||||
if (mConfigFolder.empty())
|
||||
{
|
||||
loadConfigDir();
|
||||
}
|
||||
versionionfile << mConfigFolder << "/" << VERSION_FILE_NAME;
|
||||
|
||||
// Get latest version if any.
|
||||
|
@ -1566,18 +1566,21 @@ std::string PosixDirectories::homeDirPath()
|
||||
|
||||
std::string PosixDirectories::runtimeDirPath()
|
||||
{
|
||||
std::string dir = PosixDirectories::configDirPath();
|
||||
struct stat path_stat = {};
|
||||
bool exists = !stat(dir.c_str(), &path_stat) && S_ISDIR(path_stat.st_mode);
|
||||
|
||||
return (dir.empty() || !exists) ? std::string("/tmp/megacmd-").append(std::to_string(getuid()))
|
||||
: dir;
|
||||
return PosixDirectories::configDirPath();
|
||||
}
|
||||
|
||||
std::string PosixDirectories::configDirPath()
|
||||
{
|
||||
std::string home = homeDirPath();
|
||||
return home.empty() ? std::string() : home.append("/.megaCmd");
|
||||
if (home.empty())
|
||||
{
|
||||
return std::string("/tmp/megacmd-").append(std::to_string(getuid()));
|
||||
}
|
||||
|
||||
struct stat path_stat = {};
|
||||
bool exists = !stat(home.c_str(), &path_stat) && S_ISDIR(path_stat.st_mode);
|
||||
|
||||
return !exists ? std::string("/tmp/megacmd-").append(std::to_string(getuid())) : home.append("/.megaCmd");
|
||||
}
|
||||
|
||||
bool PosixDirectories::legacyConfigDirExists()
|
||||
|
@ -59,8 +59,14 @@ TEST(PlatformDirectoriesTest, configDirPath)
|
||||
{
|
||||
G_SUBTEST << "Without $XDG_CONFIG_HOME";
|
||||
auto guard = TestInstrumentsUnsetEnvVarGuard("XDG_CONFIG_HOME");
|
||||
auto homeGuard= TestInstrumentsEnvVarGuard("HOME", "/home/test");
|
||||
EXPECT_EQ(dirs->configDirPath(), "/home/test/.megaCmd");
|
||||
{
|
||||
auto homeGuard = TestInstrumentsEnvVarGuard("HOME", "/tmp");
|
||||
EXPECT_EQ(dirs->configDirPath(), "/tmp/.megaCmd");
|
||||
}
|
||||
{
|
||||
auto homeGuard = TestInstrumentsEnvVarGuard("HOME", "/non-existent-dir");
|
||||
EXPECT_EQ(dirs->configDirPath(), std::string("/tmp/megacmd-").append(std::to_string(getuid())));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
@ -93,9 +99,15 @@ TEST(PlatformDirectoriesTest, cacheDirPath)
|
||||
}
|
||||
{
|
||||
G_SUBTEST << "Without $XDG_CACHE_HOME";
|
||||
auto homeGuard = TestInstrumentsEnvVarGuard("HOME", "/home/test");
|
||||
auto guard = TestInstrumentsUnsetEnvVarGuard("XDG_CACHE_HOME");
|
||||
EXPECT_EQ(dirs->cacheDirPath(), "/home/test/.megaCmd");
|
||||
{
|
||||
auto homeGuard = TestInstrumentsEnvVarGuard("HOME", "/tmp");
|
||||
EXPECT_EQ(dirs->cacheDirPath(), "/tmp/.megaCmd");
|
||||
}
|
||||
{
|
||||
auto homeGuard = TestInstrumentsEnvVarGuard("HOME", "/non-existent-dir");
|
||||
EXPECT_EQ(dirs->configDirPath(), std::string("/tmp/megacmd-").append(std::to_string(getuid())));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user