mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
Merge #13149: Handle unsuccessful fseek(...):s
20ce5af Print a log message if we fail to shrink the debug log file (practicalswift) 29c9bdc Handle unsuccessful fseek(...):s (practicalswift) Pull request description: Handle unsuccessful `fseek(...)`:s. **Note to reviewers:** What is the most appropriate course of actions for each of these unsuccessful `fseek(...)`:s? Tree-SHA512: 5b3d82dbdd15d434d3f08dcb4df62888da4df8541d2586f56a4e529083005f6782c39e10645acd1ec403da83061bbfd8dbf2dddc66e09268d410ad0918c61876
This commit is contained in:
parent
732697586f
commit
913079b535
@ -268,7 +268,9 @@ bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRe
|
|||||||
CBlockHeader header;
|
CBlockHeader header;
|
||||||
try {
|
try {
|
||||||
file >> header;
|
file >> header;
|
||||||
fseek(file.Get(), postx.nTxOffset, SEEK_CUR);
|
if (fseek(file.Get(), postx.nTxOffset, SEEK_CUR)) {
|
||||||
|
return error("%s: fseek(...) failed", __func__);
|
||||||
|
}
|
||||||
file >> tx;
|
file >> tx;
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
return error("%s: Deserialize or I/O error - %s", __func__, e.what());
|
return error("%s: Deserialize or I/O error - %s", __func__, e.what());
|
||||||
|
@ -308,7 +308,11 @@ void BCLog::Logger::ShrinkDebugFile()
|
|||||||
{
|
{
|
||||||
// Restart the file with some of the end
|
// Restart the file with some of the end
|
||||||
std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0);
|
std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0);
|
||||||
fseek(file, -((long)vch.size()), SEEK_END);
|
if (fseek(file, -((long)vch.size()), SEEK_END)) {
|
||||||
|
LogPrintf("Failed to shrink debug log file: fseek(...) failed\n");
|
||||||
|
fclose(file);
|
||||||
|
return;
|
||||||
|
}
|
||||||
int nBytes = fread(vch.data(), 1, vch.size(), file);
|
int nBytes = fread(vch.data(), 1, vch.size(), file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
|
@ -1024,7 +1024,9 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) {
|
|||||||
// Fallback version
|
// Fallback version
|
||||||
// TODO: just write one byte per block
|
// TODO: just write one byte per block
|
||||||
static const char buf[65536] = {};
|
static const char buf[65536] = {};
|
||||||
fseek(file, offset, SEEK_SET);
|
if (fseek(file, offset, SEEK_SET)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
while (length > 0) {
|
while (length > 0) {
|
||||||
unsigned int now = 65536;
|
unsigned int now = 65536;
|
||||||
if (length < now)
|
if (length < now)
|
||||||
|
Loading…
Reference in New Issue
Block a user