RPC dumpwallet and z_exportwallet updated to no longer allow

overwriting an existing file.
This commit is contained in:
Simon
2017-11-16 22:29:37 -08:00
parent c1282bebb8
commit ba1dbb3040
2 changed files with 15 additions and 2 deletions

View File

@@ -428,7 +428,7 @@ UniValue z_exportwallet(const UniValue& params, bool fHelp)
if (fHelp || params.size() != 1)
throw runtime_error(
"z_exportwallet \"filename\"\n"
"\nExports all wallet keys, for taddr and zaddr, in a human-readable format.\n"
"\nExports all wallet keys, for taddr and zaddr, in a human-readable format. Overwriting an existing file is not permitted.\n"
"\nArguments:\n"
"1. \"filename\" (string, required) The filename, saved in folder set by zcashd -exportdir option\n"
"\nResult:\n"
@@ -449,7 +449,7 @@ UniValue dumpwallet(const UniValue& params, bool fHelp)
if (fHelp || params.size() != 1)
throw runtime_error(
"dumpwallet \"filename\"\n"
"\nDumps taddr wallet keys in a human-readable format.\n"
"\nDumps taddr wallet keys in a human-readable format. Overwriting an existing file is not permitted.\n"
"\nArguments:\n"
"1. \"filename\" (string, required) The filename, saved in folder set by zcashd -exportdir option\n"
"\nResult:\n"
@@ -484,6 +484,10 @@ UniValue dumpwallet_impl(const UniValue& params, bool fHelp, bool fDumpZKeys)
}
boost::filesystem::path exportfilepath = exportdir / clean;
if (boost::filesystem::exists(exportfilepath)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot overwrite existing file " + exportfilepath.string());
}
ofstream file;
file.open(exportfilepath.string().c_str());
if (!file.is_open())