mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 06:43:45 +01:00
validation: Refactor file flush logic into FlatFileSeq.
This commit is contained in:
@@ -1630,25 +1630,12 @@ void static FlushBlockFile(bool fFinalize = false)
|
||||
{
|
||||
LOCK(cs_LastBlockFile);
|
||||
|
||||
CDiskBlockPos posOld(nLastBlockFile, 0);
|
||||
CDiskBlockPos block_pos_old(nLastBlockFile, vinfoBlockFile[nLastBlockFile].nSize);
|
||||
CDiskBlockPos undo_pos_old(nLastBlockFile, vinfoBlockFile[nLastBlockFile].nUndoSize);
|
||||
|
||||
bool status = true;
|
||||
|
||||
FILE *fileOld = OpenBlockFile(posOld);
|
||||
if (fileOld) {
|
||||
if (fFinalize)
|
||||
status &= TruncateFile(fileOld, vinfoBlockFile[nLastBlockFile].nSize);
|
||||
status &= FileCommit(fileOld);
|
||||
fclose(fileOld);
|
||||
}
|
||||
|
||||
fileOld = OpenUndoFile(posOld);
|
||||
if (fileOld) {
|
||||
if (fFinalize)
|
||||
status &= TruncateFile(fileOld, vinfoBlockFile[nLastBlockFile].nUndoSize);
|
||||
status &= FileCommit(fileOld);
|
||||
fclose(fileOld);
|
||||
}
|
||||
|
||||
status &= BlockFileSeq().Flush(block_pos_old, fFinalize);
|
||||
status &= UndoFileSeq().Flush(undo_pos_old, fFinalize);
|
||||
if (!status) {
|
||||
AbortNode("Flushing block file to disk failed. This is likely the result of an I/O error.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user