Changeset View
Changeset View
Standalone View
Standalone View
src/addrdb.cpp
Show All 39 Lines | bool SerializeFileDB(const CChainParams &chainParams, const std::string &prefix, | ||||
unsigned short randv = 0; | unsigned short randv = 0; | ||||
GetRandBytes((uint8_t *)&randv, sizeof(randv)); | GetRandBytes((uint8_t *)&randv, sizeof(randv)); | ||||
std::string tmpfn = strprintf("%s.%04x", prefix, randv); | std::string tmpfn = strprintf("%s.%04x", prefix, randv); | ||||
// open temp output file, and associate with CAutoFile | // open temp output file, and associate with CAutoFile | ||||
fs::path pathTmp = GetDataDir() / tmpfn; | fs::path pathTmp = GetDataDir() / tmpfn; | ||||
FILE *file = fsbridge::fopen(pathTmp, "wb"); | FILE *file = fsbridge::fopen(pathTmp, "wb"); | ||||
CAutoFile fileout(file, SER_DISK, CLIENT_VERSION); | CAutoFile fileout(file, SER_DISK, CLIENT_VERSION); | ||||
if (fileout.IsNull()) { | if (fileout.IsNull()) | ||||
return error("%s: Failed to open file %s", __func__, pathTmp.string()); | return error("%s: Failed to open file %s", __func__, pathTmp.string()); | ||||
} | |||||
// Serialize | // Serialize | ||||
if (!SerializeDB(chainParams, fileout, data)) { | if (!SerializeDB(chainParams, fileout, data)) { | ||||
return false; | return false; | ||||
} | } | ||||
if (!FileCommit(fileout.Get())) { | if (!FileCommit(fileout.Get())) { | ||||
return error("%s: Failed to flush file %s", __func__, pathTmp.string()); | return error("%s: Failed to flush file %s", __func__, pathTmp.string()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines |