Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/db.cpp
Show First 20 Lines • Show All 419 Lines • ▼ Show 20 Lines | bool BerkeleyBatch::Recover(const fs::path &file_path, void *callbackDataIn, | ||||
} | } | ||||
ptxn->commit(0); | ptxn->commit(0); | ||||
pdbCopy->close(0); | pdbCopy->close(0); | ||||
return fSuccess; | return fSuccess; | ||||
} | } | ||||
bool BerkeleyBatch::VerifyEnvironment(const fs::path &file_path, | bool BerkeleyBatch::VerifyEnvironment(const fs::path &file_path, | ||||
std::string &errorStr) { | bilingual_str &errorStr) { | ||||
std::string walletFile; | std::string walletFile; | ||||
std::shared_ptr<BerkeleyEnvironment> env = | std::shared_ptr<BerkeleyEnvironment> env = | ||||
GetWalletEnv(file_path, walletFile); | GetWalletEnv(file_path, walletFile); | ||||
fs::path walletDir = env->Directory(); | fs::path walletDir = env->Directory(); | ||||
LogPrintf("Using BerkeleyDB version %s\n", | LogPrintf("Using BerkeleyDB version %s\n", | ||||
DbEnv::version(nullptr, nullptr, nullptr)); | DbEnv::version(nullptr, nullptr, nullptr)); | ||||
LogPrintf("Using wallet %s\n", file_path.string()); | LogPrintf("Using wallet %s\n", file_path.string()); | ||||
if (!env->Open(true /* retry */)) { | if (!env->Open(true /* retry */)) { | ||||
errorStr = strprintf( | errorStr = strprintf( | ||||
_("Error initializing wallet database environment %s!").translated, | _("Error initializing wallet database environment %s!"), walletDir); | ||||
walletDir); | |||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool BerkeleyBatch::VerifyDatabaseFile( | bool BerkeleyBatch::VerifyDatabaseFile( | ||||
const fs::path &file_path, std::vector<std::string> &warnings, | const fs::path &file_path, std::vector<bilingual_str> &warnings, | ||||
std::string &errorStr, BerkeleyEnvironment::recoverFunc_type recoverFunc) { | bilingual_str &errorStr, | ||||
BerkeleyEnvironment::recoverFunc_type recoverFunc) { | |||||
std::string walletFile; | std::string walletFile; | ||||
std::shared_ptr<BerkeleyEnvironment> env = | std::shared_ptr<BerkeleyEnvironment> env = | ||||
GetWalletEnv(file_path, walletFile); | GetWalletEnv(file_path, walletFile); | ||||
fs::path walletDir = env->Directory(); | fs::path walletDir = env->Directory(); | ||||
if (fs::exists(walletDir / walletFile)) { | if (fs::exists(walletDir / walletFile)) { | ||||
std::string backup_filename; | std::string backup_filename; | ||||
BerkeleyEnvironment::VerifyResult r = | BerkeleyEnvironment::VerifyResult r = | ||||
env->Verify(walletFile, recoverFunc, backup_filename); | env->Verify(walletFile, recoverFunc, backup_filename); | ||||
if (r == BerkeleyEnvironment::VerifyResult::RECOVER_OK) { | if (r == BerkeleyEnvironment::VerifyResult::RECOVER_OK) { | ||||
warnings.push_back(strprintf( | warnings.push_back( | ||||
_("Warning: Wallet file corrupt, data salvaged! Original %s " | strprintf(_("Warning: Wallet file corrupt, data salvaged!" | ||||
"saved as %s in %s; if your balance or transactions are " | " Original %s saved as %s in %s; if your balance " | ||||
"incorrect you should restore from a backup.") | "or transactions are incorrect you should restore " | ||||
.translated, | "from a backup."), | ||||
walletFile, backup_filename, walletDir)); | walletFile, backup_filename, walletDir)); | ||||
} | } | ||||
if (r == BerkeleyEnvironment::VerifyResult::RECOVER_FAIL) { | if (r == BerkeleyEnvironment::VerifyResult::RECOVER_FAIL) { | ||||
errorStr = strprintf(_("%s corrupt, salvage failed").translated, | errorStr = strprintf(_("%s corrupt, salvage failed"), walletFile); | ||||
walletFile); | |||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
// also return true if files does not exists | // also return true if files does not exists | ||||
return true; | return true; | ||||
} | } | ||||
/* End of headers, beginning of key/value data */ | /* End of headers, beginning of key/value data */ | ||||
▲ Show 20 Lines • Show All 536 Lines • Show Last 20 Lines |