@@ -459,7 +459,7 @@ bool BlockManager::LoadBlockIndexDB()
459459 }
460460 for (std::set<int >::iterator it = setBlkDataFiles.begin (); it != setBlkDataFiles.end (); it++) {
461461 FlatFilePos pos (*it, 0 );
462- if (AutoFile{ OpenBlockFile (pos, true )} .IsNull ()) {
462+ if (OpenBlockFile (pos, true ).IsNull ()) {
463463 return false ;
464464 }
465465 }
@@ -592,7 +592,7 @@ CBlockFileInfo* BlockManager::GetBlockFileInfo(size_t n)
592592bool BlockManager::UndoWriteToDisk (const CBlockUndo& blockundo, FlatFilePos& pos, const uint256& hashBlock) const
593593{
594594 // Open history file to append
595- AutoFile fileout{OpenUndoFile (pos)};
595+ CAutoFile fileout{OpenUndoFile (pos)};
596596 if (fileout.IsNull ()) {
597597 return error (" %s: OpenUndoFile failed" , __func__);
598598 }
@@ -627,7 +627,7 @@ bool BlockManager::UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex& in
627627 }
628628
629629 // Open history file to read
630- AutoFile filein{OpenUndoFile (pos, true )};
630+ CAutoFile filein{OpenUndoFile (pos, true )};
631631 if (filein.IsNull ()) {
632632 return error (" %s: OpenUndoFile failed" , __func__);
633633 }
@@ -715,15 +715,15 @@ FlatFileSeq BlockManager::UndoFileSeq() const
715715 return FlatFileSeq (m_opts.blocks_dir , " rev" , UNDOFILE_CHUNK_SIZE);
716716}
717717
718- FILE* BlockManager::OpenBlockFile (const FlatFilePos& pos, bool fReadOnly ) const
718+ CAutoFile BlockManager::OpenBlockFile (const FlatFilePos& pos, bool fReadOnly ) const
719719{
720- return BlockFileSeq ().Open (pos, fReadOnly );
720+ return CAutoFile{ BlockFileSeq ().Open (pos, fReadOnly ), CLIENT_VERSION} ;
721721}
722722
723723/* * Open an undo file (rev?????.dat) */
724- FILE* BlockManager::OpenUndoFile (const FlatFilePos& pos, bool fReadOnly ) const
724+ CAutoFile BlockManager::OpenUndoFile (const FlatFilePos& pos, bool fReadOnly ) const
725725{
726- return UndoFileSeq ().Open (pos, fReadOnly );
726+ return CAutoFile{ UndoFileSeq ().Open (pos, fReadOnly ), CLIENT_VERSION} ;
727727}
728728
729729fs::path BlockManager::GetBlockPosFilename (const FlatFilePos& pos) const
@@ -824,7 +824,7 @@ bool BlockManager::FindUndoPos(BlockValidationState& state, int nFile, FlatFileP
824824bool BlockManager::WriteBlockToDisk (const CBlock& block, FlatFilePos& pos) const
825825{
826826 // Open history file to append
827- CAutoFile fileout{OpenBlockFile (pos), CLIENT_VERSION };
827+ CAutoFile fileout{OpenBlockFile (pos)};
828828 if (fileout.IsNull ()) {
829829 return error (" WriteBlockToDisk: OpenBlockFile failed" );
830830 }
@@ -880,7 +880,7 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos) cons
880880 block.SetNull ();
881881
882882 // Open history file to read
883- CAutoFile filein{OpenBlockFile (pos, true ), CLIENT_VERSION };
883+ CAutoFile filein{OpenBlockFile (pos, true )};
884884 if (filein.IsNull ()) {
885885 return error (" ReadBlockFromDisk: OpenBlockFile failed for %s" , pos.ToString ());
886886 }
@@ -923,7 +923,7 @@ bool BlockManager::ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatF
923923{
924924 FlatFilePos hpos = pos;
925925 hpos.nPos -= 8 ; // Seek back 8 bytes for meta header
926- AutoFile filein{OpenBlockFile (hpos, true )};
926+ CAutoFile filein{OpenBlockFile (hpos, true )};
927927 if (filein.IsNull ()) {
928928 return error (" %s: OpenBlockFile failed for %s" , __func__, pos.ToString ());
929929 }
@@ -1015,8 +1015,8 @@ void ImportBlocks(ChainstateManager& chainman, std::vector<fs::path> vImportFile
10151015 if (!fs::exists (chainman.m_blockman .GetBlockPosFilename (pos))) {
10161016 break ; // No block files left to reindex
10171017 }
1018- FILE* file = chainman.m_blockman .OpenBlockFile (pos, true );
1019- if (! file) {
1018+ CAutoFile file{ chainman.m_blockman .OpenBlockFile (pos, true )} ;
1019+ if (file. IsNull () ) {
10201020 break ; // This error is logged in OpenBlockFile
10211021 }
10221022 LogPrintf (" Reindexing block file blk%05u.dat...\n " , (unsigned int )nFile);
@@ -1036,8 +1036,8 @@ void ImportBlocks(ChainstateManager& chainman, std::vector<fs::path> vImportFile
10361036
10371037 // -loadblock=
10381038 for (const fs::path& path : vImportFiles) {
1039- FILE* file = fsbridge::fopen (path, " rb" );
1040- if (file) {
1039+ CAutoFile file{ fsbridge::fopen (path, " rb" ), CLIENT_VERSION} ;
1040+ if (! file. IsNull () ) {
10411041 LogPrintf (" Importing blocks file %s...\n " , fs::PathToString (path));
10421042 chainman.LoadExternalBlockFile (file);
10431043 if (chainman.m_interrupt ) {
0 commit comments