MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / read_serialised_sha_file

Function read_serialised_sha_file

tools/comdb2ar/increment.cpp:44–77  ·  view source on GitHub ↗

Read from STDIN a serialised text file with the SHA fingerprint

Source from the content-addressed store, hash-verified

42
43// Read from STDIN a serialised text file with the SHA fingerprint
44std::string read_serialised_sha_file() {
45 char fingerprint[40];
46
47 size_t bufsize = 4096;
48 uint8_t *buf;
49#if defined _HP_SOURCE || defined _SUN_SOURCE
50 buf = (uint8_t*) memalign(512, bufsize);
51#else
52 if (posix_memalign((void**) &buf, 512, bufsize))
53 throw Error("Failed to allocate output buffer");
54#endif
55 RIIA_malloc free_guard(buf);
56
57 if(readall(0, &fingerprint[0], 40) != 40){
58 std::ostringstream ss;
59 ss << "Could not read sha fingerprint file";
60 throw Error(ss);
61 }
62
63 // Read and discard the null padding
64 unsigned long long nblocks = (40 + 511ULL) >> 9;
65 unsigned long long padding_bytes = (nblocks << 9) - 40;
66 if(padding_bytes) {
67 if(readall(0, &buf[0], padding_bytes) != padding_bytes) {
68 std::ostringstream ss;
69
70 ss << "Error reading padding after in SHA file";
71 throw Error(ss);
72 }
73 }
74
75 std::clog << "Read SHA as: " << std::string(fingerprint, 40) << std::endl;
76 return std::string(fingerprint, 40);
77}
78
79// Determine whether the file has changed, ie if the page's current LSN + Checksum
80// is the same as it is in the .incr diff file

Callers 2

deserialise_databaseFunction · 0.85

Calls 2

ErrorClass · 0.85
readallFunction · 0.85

Tested by

no test coverage detected