mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-10-11 12:03:04 +02:00
validation: Refactor file flush logic into FlatFileSeq.
This commit is contained in:
@@ -72,3 +72,22 @@ size_t FlatFileSeq::Allocate(const CDiskBlockPos& pos, size_t add_size, bool& ou
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool FlatFileSeq::Flush(const CDiskBlockPos& pos, bool finalize)
|
||||
{
|
||||
FILE* file = Open(FlatFilePos(pos.nFile, 0)); // Avoid fseek to nPos
|
||||
if (!file) {
|
||||
return error("%s: failed to open file %d", __func__, pos.nFile);
|
||||
}
|
||||
if (finalize && !TruncateFile(file, pos.nPos)) {
|
||||
fclose(file);
|
||||
return error("%s: failed to truncate file %d", __func__, pos.nFile);
|
||||
}
|
||||
if (!FileCommit(file)) {
|
||||
fclose(file);
|
||||
return error("%s: failed to commit file %d", __func__, pos.nFile);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user