refactor: Drop unused fclose() from BufferedFile

This was only explicitly used in the tests, where it can be replaced by
wrapping the original raw file pointer into a CAutoFile on creation and
then calling CAutoFile::fclose().

Also, it was used in LoadExternalBlockFile(), where it can also be
replaced by the (implicit call to the) CAutoFile destructor after
wrapping the original raw file pointer in a CAutoFile.
This commit is contained in:
MarcoFalke
2023-07-04 18:59:49 +02:00
parent f608a409f7
commit fa389d902f
8 changed files with 42 additions and 57 deletions

View File

@@ -1015,12 +1015,12 @@ void ImportBlocks(ChainstateManager& chainman, std::vector<fs::path> vImportFile
if (!fs::exists(chainman.m_blockman.GetBlockPosFilename(pos))) {
break; // No block files left to reindex
}
FILE* file = chainman.m_blockman.OpenBlockFile(pos, true);
if (!file) {
CAutoFile file{chainman.m_blockman.OpenBlockFile(pos, true), CLIENT_VERSION};
if (file.IsNull()) {
break; // This error is logged in OpenBlockFile
}
LogPrintf("Reindexing block file blk%05u.dat...\n", (unsigned int)nFile);
chainman.LoadExternalBlockFile(file, &pos, &blocks_with_unknown_parent);
chainman.LoadExternalBlockFile(file.Get(), &pos, &blocks_with_unknown_parent);
if (chainman.m_interrupt) {
LogPrintf("Interrupt requested. Exit %s\n", __func__);
return;
@@ -1036,10 +1036,10 @@ void ImportBlocks(ChainstateManager& chainman, std::vector<fs::path> vImportFile
// -loadblock=
for (const fs::path& path : vImportFiles) {
FILE* file = fsbridge::fopen(path, "rb");
if (file) {
CAutoFile file{fsbridge::fopen(path, "rb"), CLIENT_VERSION};
if (!file.IsNull()) {
LogPrintf("Importing blocks file %s...\n", fs::PathToString(path));
chainman.LoadExternalBlockFile(file);
chainman.LoadExternalBlockFile(file.Get());
if (chainman.m_interrupt) {
LogPrintf("Interrupt requested. Exit %s\n", __func__);
return;