Skip to content

Commit 285a18d

Browse files
authored
Merge pull request #1173 from andreabonel/fix_issue_1120
Fix location for default cookie path
2 parents a7c455e + 86db1b7 commit 285a18d

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/rpc/request.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ static fs::path GetMainchainAuthCookieFile()
134134
if (gArgs.GetChainName() == "liquidv1") {
135135
cookie_file = ".cookie";
136136
}
137-
std::string path = gArgs.GetArg("-mainchainrpccookiefile", cookie_file);
138-
return AbsPathForConfigVal(fs::path(path));
137+
return fsbridge::AbsPathJoin(GetMainchainDefaultDataDir(), gArgs.GetArg("-mainchainrpccookiefile", cookie_file));
139138
}
140139

141140
bool GetMainchainAuthCookie(std::string *cookie_out)

src/util/system.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,31 @@ fs::path GetDefaultDataDir()
827827
}
828828
#endif
829829

830+
fs::path GetMainchainDefaultDataDir()
831+
{
832+
// Windows: C:\Users\Username\AppData\Roaming\Bitcoin
833+
// macOS: ~/Library/Application Support/Bitcoin
834+
// Unix-like: ~/.bitcoin
835+
#ifdef WIN32
836+
// Windows
837+
return GetSpecialFolderPath(CSIDL_APPDATA) / "Bitcoin";
838+
#else
839+
fs::path pathRet;
840+
char* pszHome = getenv("HOME");
841+
if (pszHome == nullptr || strlen(pszHome) == 0)
842+
pathRet = fs::path("/");
843+
else
844+
pathRet = fs::path(pszHome);
845+
#ifdef MAC_OSX
846+
// macOS
847+
return pathRet / "Library/Application Support/Bitcoin";
848+
#else
849+
// Unix-like
850+
return pathRet / ".bitcoin";
851+
#endif
852+
#endif
853+
}
854+
830855
bool CheckDataDirOption()
831856
{
832857
std::string datadir = gArgs.GetArg("-datadir", "");

src/util/system.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ void ReleaseDirectoryLocks();
9090

9191
bool TryCreateDirectories(const fs::path& p);
9292
fs::path GetDefaultDataDir();
93+
fs::path GetMainchainDefaultDataDir();
9394
// Return true if -datadir option points to a valid directory or is not specified.
9495
bool CheckDataDirOption();
9596
fs::path GetConfigFile(const std::string& confPath);

0 commit comments

Comments
 (0)