Skip to content

Commit 955ca11

Browse files
authored
Merge pull request #1416 from jamescowens/fixdumpwallet
Change dumpwallet to use appropriate data directory
2 parents 5438271 + edc0855 commit 955ca11

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/rpcdump.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <boost/date_time/posix_time/posix_time.hpp>
1515
#include <boost/variant/get.hpp>
1616
#include <boost/algorithm/string.hpp>
17+
#include <boost/filesystem.hpp>
1718

1819
using namespace std;
1920

@@ -305,12 +306,20 @@ UniValue dumpwallet(const UniValue& params, bool fHelp)
305306
"\n"
306307
"<filename> -> filename to dump wallet to\n"
307308
"\n"
308-
"Dumps all wallet keys in a human-readable format\n");
309+
"Dumps all wallet keys in a human-readable format into the specified file.\n"
310+
"If a path is not specified in the filename, the data directory is used.");
309311

310312
EnsureWalletIsUnlocked();
311313

314+
boost::filesystem::path PathForDump = boost::filesystem::path(params[0].get_str());
315+
boost::filesystem::path DefaultPathDataDir = GetDataDir();
316+
317+
// If provided filename does not have a path, then append parent path, otherwise leave alone.
318+
if (PathForDump.parent_path().empty())
319+
PathForDump = DefaultPathDataDir / PathForDump;
320+
312321
ofstream file;
313-
file.open(params[0].get_str().c_str());
322+
file.open(PathForDump.string().c_str());
314323
if (!file.is_open())
315324
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file");
316325

0 commit comments

Comments
 (0)