Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/db.cpp
Show First 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | CDBEnv::VerifyResult CDBEnv::Verify(const std::string &strFile, | ||||
recoverFunc_type recoverFunc, | recoverFunc_type recoverFunc, | ||||
std::string &out_backup_filename) { | std::string &out_backup_filename) { | ||||
LOCK(cs_db); | LOCK(cs_db); | ||||
assert(mapFileUseCount.count(strFile) == 0); | assert(mapFileUseCount.count(strFile) == 0); | ||||
Db db(dbenv.get(), 0); | Db db(dbenv.get(), 0); | ||||
int result = db.verify(strFile.c_str(), nullptr, nullptr, 0); | int result = db.verify(strFile.c_str(), nullptr, nullptr, 0); | ||||
if (result == 0) { | if (result == 0) { | ||||
return VERIFY_OK; | return VerifyResult::VERIFY_OK; | ||||
} else if (recoverFunc == nullptr) { | } else if (recoverFunc == nullptr) { | ||||
return RECOVER_FAIL; | return VerifyResult::RECOVER_FAIL; | ||||
} | } | ||||
// Try to recover: | // Try to recover: | ||||
bool fRecovered = (*recoverFunc)(strFile, out_backup_filename); | bool fRecovered = (*recoverFunc)(strFile, out_backup_filename); | ||||
return (fRecovered ? RECOVER_OK : RECOVER_FAIL); | return (fRecovered ? VerifyResult::RECOVER_OK : VerifyResult::RECOVER_FAIL); | ||||
} | } | ||||
bool CDB::Recover(const std::string &filename, void *callbackDataIn, | bool CDB::Recover(const std::string &filename, void *callbackDataIn, | ||||
bool (*recoverKVcallback)(void *callbackData, | bool (*recoverKVcallback)(void *callbackData, | ||||
CDataStream ssKey, | CDataStream ssKey, | ||||
CDataStream ssValue), | CDataStream ssValue), | ||||
std::string &newFilename) { | std::string &newFilename) { | ||||
// Recovery procedure: | // Recovery procedure: | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | |||||
bool CDB::VerifyDatabaseFile(const std::string &walletFile, | bool CDB::VerifyDatabaseFile(const std::string &walletFile, | ||||
const fs::path &walletDir, std::string &warningStr, | const fs::path &walletDir, std::string &warningStr, | ||||
std::string &errorStr, | std::string &errorStr, | ||||
CDBEnv::recoverFunc_type recoverFunc) { | CDBEnv::recoverFunc_type recoverFunc) { | ||||
if (fs::exists(walletDir / walletFile)) { | if (fs::exists(walletDir / walletFile)) { | ||||
std::string backup_filename; | std::string backup_filename; | ||||
CDBEnv::VerifyResult r = | CDBEnv::VerifyResult r = | ||||
bitdb.Verify(walletFile, recoverFunc, backup_filename); | bitdb.Verify(walletFile, recoverFunc, backup_filename); | ||||
if (r == CDBEnv::RECOVER_OK) { | if (r == CDBEnv::VerifyResult::RECOVER_OK) { | ||||
warningStr = strprintf( | warningStr = strprintf( | ||||
_("Warning: Wallet file corrupt, data salvaged!" | _("Warning: Wallet file corrupt, data salvaged!" | ||||
" Original %s saved as %s in %s; if" | " Original %s saved as %s in %s; if" | ||||
" your balance or transactions are incorrect you should" | " your balance or transactions are incorrect you should" | ||||
" restore from a backup."), | " restore from a backup."), | ||||
walletFile, backup_filename, walletDir); | walletFile, backup_filename, walletDir); | ||||
} | } | ||||
if (r == CDBEnv::RECOVER_FAIL) { | if (r == CDBEnv::VerifyResult::RECOVER_FAIL) { | ||||
errorStr = strprintf(_("%s corrupt, salvage failed"), walletFile); | errorStr = strprintf(_("%s corrupt, salvage failed"), 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; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 449 Lines • Show Last 20 Lines |