Merge pull request #1173 from andreabonel/fix_issue_1120

Fix location for default cookie path
This commit is contained in:
Pablo Greco 2022-10-05 22:57:29 -03:00 committed by GitHub
commit 285a18dbe9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 2 deletions

View file

@ -134,8 +134,7 @@ static fs::path GetMainchainAuthCookieFile()
if (gArgs.GetChainName() == "liquidv1") {
cookie_file = ".cookie";
}
std::string path = gArgs.GetArg("-mainchainrpccookiefile", cookie_file);
return AbsPathForConfigVal(fs::path(path));
return fsbridge::AbsPathJoin(GetMainchainDefaultDataDir(), gArgs.GetArg("-mainchainrpccookiefile", cookie_file));
}
bool GetMainchainAuthCookie(std::string *cookie_out)

View file

@ -827,6 +827,31 @@ fs::path GetDefaultDataDir()
}
#endif
fs::path GetMainchainDefaultDataDir()
{
// Windows: C:\Users\Username\AppData\Roaming\Bitcoin
// macOS: ~/Library/Application Support/Bitcoin
// Unix-like: ~/.bitcoin
#ifdef WIN32
// Windows
return GetSpecialFolderPath(CSIDL_APPDATA) / "Bitcoin";
#else
fs::path pathRet;
char* pszHome = getenv("HOME");
if (pszHome == nullptr || strlen(pszHome) == 0)
pathRet = fs::path("/");
else
pathRet = fs::path(pszHome);
#ifdef MAC_OSX
// macOS
return pathRet / "Library/Application Support/Bitcoin";
#else
// Unix-like
return pathRet / ".bitcoin";
#endif
#endif
}
bool CheckDataDirOption()
{
std::string datadir = gArgs.GetArg("-datadir", "");

View file

@ -90,6 +90,7 @@ void ReleaseDirectoryLocks();
bool TryCreateDirectories(const fs::path& p);
fs::path GetDefaultDataDir();
fs::path GetMainchainDefaultDataDir();
// Return true if -datadir option points to a valid directory or is not specified.
bool CheckDataDirOption();
fs::path GetConfigFile(const std::string& confPath);