MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / SerializeFileDB

Function SerializeFileDB

src/addrdb.cpp:36–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34
35template <typename Data>
36bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data& data)
37{
38 // Generate random temporary filename
39 unsigned short randv = 0;
40 GetRandBytes((unsigned char*)&randv, sizeof(randv));
41 std::string tmpfn = strprintf("%s.%04x", prefix, randv);
42
43 // open temp output file, and associate with CAutoFile
44 fs::path pathTmp = GetDataDir() / tmpfn;
45 FILE *file = fsbridge::fopen(pathTmp, "wb");
46 CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
47 if (fileout.IsNull())
48 return error("%s: Failed to open file %s", __func__, pathTmp.string());
49
50 // Serialize
51 if (!SerializeDB(fileout, data)) return false;
52 if (!FileCommit(fileout.Get()))
53 return error("%s: Failed to flush file %s", __func__, pathTmp.string());
54 fileout.fclose();
55
56 // replace existing file, if any, with new file
57 if (!RenameOver(pathTmp, path))
58 return error("%s: Rename-into-place failed", __func__);
59
60 return true;
61}
62
63template <typename Stream, typename Data>
64bool DeserializeDB(Stream& stream, Data& data, bool fCheckSum = true)

Callers 1

WriteMethod · 0.85

Calls 9

GetRandBytesFunction · 0.85
fopenFunction · 0.85
errorFunction · 0.85
SerializeDBFunction · 0.85
FileCommitFunction · 0.85
RenameOverFunction · 0.85
IsNullMethod · 0.45
GetMethod · 0.45
fcloseMethod · 0.45

Tested by

no test coverage detected