@@ -379,7 +379,7 @@ bool BlockManager::LoadBlockIndexDB()
379379 }
380380 for (std::set<int >::iterator it = setBlkDataFiles.begin (); it != setBlkDataFiles.end (); it++) {
381381 FlatFilePos pos (*it, 0 );
382- if (CAutoFile ( OpenBlockFile (pos, true ), SER_DISK, CLIENT_VERSION) .IsNull ()) {
382+ if (AutoFile{ OpenBlockFile (pos, true )} .IsNull ()) {
383383 return false ;
384384 }
385385 }
@@ -487,13 +487,13 @@ CBlockFileInfo* BlockManager::GetBlockFileInfo(size_t n)
487487static bool UndoWriteToDisk (const CBlockUndo& blockundo, FlatFilePos& pos, const uint256& hashBlock, const CMessageHeader::MessageStartChars& messageStart)
488488{
489489 // Open history file to append
490- CAutoFile fileout ( OpenUndoFile (pos), SER_DISK, CLIENT_VERSION) ;
490+ AutoFile fileout{ OpenUndoFile (pos)} ;
491491 if (fileout.IsNull ()) {
492492 return error (" %s: OpenUndoFile failed" , __func__);
493493 }
494494
495495 // Write index header
496- unsigned int nSize = GetSerializeSize (blockundo, fileout. GetVersion () );
496+ unsigned int nSize = GetSerializeSize (blockundo, CLIENT_VERSION );
497497 fileout << messageStart << nSize;
498498
499499 // Write undo data
@@ -522,14 +522,14 @@ bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex)
522522 }
523523
524524 // Open history file to read
525- CAutoFile filein ( OpenUndoFile (pos, true ), SER_DISK, CLIENT_VERSION) ;
525+ AutoFile filein{ OpenUndoFile (pos, true )} ;
526526 if (filein.IsNull ()) {
527527 return error (" %s: OpenUndoFile failed" , __func__);
528528 }
529529
530530 // Read block
531531 uint256 hashChecksum;
532- CHashVerifier<CAutoFile > verifier (&filein); // We need a CHashVerifier as reserializing may lose data
532+ CHashVerifier<AutoFile > verifier (&filein); // We need a CHashVerifier as reserializing may lose data
533533 try {
534534 verifier << pindex->pprev ->GetBlockHash ();
535535 verifier >> blockundo;
@@ -597,15 +597,15 @@ static FlatFileSeq UndoFileSeq()
597597 return FlatFileSeq (gArgs .GetBlocksDirPath (), " rev" , UNDOFILE_CHUNK_SIZE);
598598}
599599
600- FILE* OpenBlockFile (const FlatFilePos& pos, bool fReadOnly )
600+ AutoFile OpenBlockFile (const FlatFilePos& pos, bool fReadOnly )
601601{
602- return BlockFileSeq ().Open (pos, fReadOnly );
602+ return AutoFile{ BlockFileSeq ().Open (pos, fReadOnly )} ;
603603}
604604
605605/* * Open an undo file (rev?????.dat) */
606- static FILE* OpenUndoFile (const FlatFilePos& pos, bool fReadOnly )
606+ static AutoFile OpenUndoFile (const FlatFilePos& pos, bool fReadOnly )
607607{
608- return UndoFileSeq ().Open (pos, fReadOnly );
608+ return AutoFile{ UndoFileSeq ().Open (pos, fReadOnly )} ;
609609}
610610
611611fs::path GetBlockPosFilename (const FlatFilePos& pos)
@@ -693,13 +693,13 @@ bool BlockManager::FindUndoPos(BlockValidationState& state, int nFile, FlatFileP
693693static bool WriteBlockToDisk (const CBlock& block, FlatFilePos& pos, const CMessageHeader::MessageStartChars& messageStart)
694694{
695695 // Open history file to append
696- CAutoFile fileout ( OpenBlockFile (pos), SER_DISK, CLIENT_VERSION) ;
696+ AutoFile fileout{ OpenBlockFile (pos)} ;
697697 if (fileout.IsNull ()) {
698698 return error (" WriteBlockToDisk: OpenBlockFile failed" );
699699 }
700700
701701 // Write index header
702- unsigned int nSize = GetSerializeSize (block, fileout. GetVersion () );
702+ unsigned int nSize = GetSerializeSize (block, CLIENT_VERSION );
703703 fileout << messageStart << nSize;
704704
705705 // Write block
@@ -748,7 +748,7 @@ bool ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos, const Consensus::P
748748 block.SetNull ();
749749
750750 // Open history file to read
751- CAutoFile filein ( OpenBlockFile (pos, true ), SER_DISK, CLIENT_VERSION) ;
751+ AutoFile filein{ OpenBlockFile (pos, true )} ;
752752 if (filein.IsNull ()) {
753753 return error (" ReadBlockFromDisk: OpenBlockFile failed for %s" , pos.ToString ());
754754 }
@@ -840,8 +840,8 @@ void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFile
840840 if (!fs::exists (GetBlockPosFilename (pos))) {
841841 break ; // No block files left to reindex
842842 }
843- FILE* file = OpenBlockFile (pos, true );
844- if (! file) {
843+ AutoFile file{ OpenBlockFile (pos, true )} ;
844+ if (file. IsNull () ) {
845845 break ; // This error is logged in OpenBlockFile
846846 }
847847 LogPrintf (" Reindexing block file blk%05u.dat...\n " , (unsigned int )nFile);
@@ -861,8 +861,8 @@ void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFile
861861
862862 // -loadblock=
863863 for (const fs::path& path : vImportFiles) {
864- FILE * file = fsbridge::fopen (path, " rb" );
865- if (file) {
864+ AutoFile file{ fsbridge::fopen (path, " rb" )} ;
865+ if (! file. IsNull () ) {
866866 LogPrintf (" Importing blocks file %s...\n " , fs::PathToString (path));
867867 chainman.ActiveChainstate ().LoadExternalBlockFile (file);
868868 if (ShutdownRequested ()) {
0 commit comments