Skip to content

Commit

Permalink
Merge pull request #1173 from andreabonel/fix_issue_1120
Browse files Browse the repository at this point in the history
Fix location for default cookie path
  • Loading branch information
psgreco committed Oct 6, 2022
2 parents a7c455e + 86db1b7 commit 285a18d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/rpc/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions src/util/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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", "");
Expand Down
1 change: 1 addition & 0 deletions src/util/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 285a18d

Please sign in to comment.