aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2023-06-30 16:25:13 +0200
committerMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2023-09-15 14:34:24 +0200
commitfa56c421be04af846f479c30749b17e6663ab418 (patch)
tree26b3f14db47fb94a320da39e86eed7c5988ff654 /src/node
parent9999b89cd37fb2a23c5ebcd91d9cb31d69375933 (diff)
Return CAutoFile from BlockManager::Open*File()
This is a refactor.
Diffstat (limited to 'src/node')
-rw-r--r--src/node/blockstorage.cpp22
-rw-r--r--src/node/blockstorage.h5
2 files changed, 14 insertions, 13 deletions
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
index 0003a08257..ae63d12ef7 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -459,7 +459,7 @@ bool BlockManager::LoadBlockIndexDB()
}
for (std::set<int>::iterator it = setBlkDataFiles.begin(); it != setBlkDataFiles.end(); it++) {
FlatFilePos pos(*it, 0);
- if (AutoFile{OpenBlockFile(pos, true)}.IsNull()) {
+ if (OpenBlockFile(pos, true).IsNull()) {
return false;
}
}
@@ -592,7 +592,7 @@ CBlockFileInfo* BlockManager::GetBlockFileInfo(size_t n)
bool BlockManager::UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const uint256& hashBlock) const
{
// Open history file to append
- AutoFile fileout{OpenUndoFile(pos)};
+ CAutoFile fileout{OpenUndoFile(pos)};
if (fileout.IsNull()) {
return error("%s: OpenUndoFile failed", __func__);
}
@@ -627,7 +627,7 @@ bool BlockManager::UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex& in
}
// Open history file to read
- AutoFile filein{OpenUndoFile(pos, true)};
+ CAutoFile filein{OpenUndoFile(pos, true)};
if (filein.IsNull()) {
return error("%s: OpenUndoFile failed", __func__);
}
@@ -715,15 +715,15 @@ FlatFileSeq BlockManager::UndoFileSeq() const
return FlatFileSeq(m_opts.blocks_dir, "rev", UNDOFILE_CHUNK_SIZE);
}
-FILE* BlockManager::OpenBlockFile(const FlatFilePos& pos, bool fReadOnly) const
+CAutoFile BlockManager::OpenBlockFile(const FlatFilePos& pos, bool fReadOnly) const
{
- return BlockFileSeq().Open(pos, fReadOnly);
+ return CAutoFile{BlockFileSeq().Open(pos, fReadOnly), CLIENT_VERSION};
}
/** Open an undo file (rev?????.dat) */
-FILE* BlockManager::OpenUndoFile(const FlatFilePos& pos, bool fReadOnly) const
+CAutoFile BlockManager::OpenUndoFile(const FlatFilePos& pos, bool fReadOnly) const
{
- return UndoFileSeq().Open(pos, fReadOnly);
+ return CAutoFile{UndoFileSeq().Open(pos, fReadOnly), CLIENT_VERSION};
}
fs::path BlockManager::GetBlockPosFilename(const FlatFilePos& pos) const
@@ -824,7 +824,7 @@ bool BlockManager::FindUndoPos(BlockValidationState& state, int nFile, FlatFileP
bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const
{
// Open history file to append
- CAutoFile fileout{OpenBlockFile(pos), CLIENT_VERSION};
+ CAutoFile fileout{OpenBlockFile(pos)};
if (fileout.IsNull()) {
return error("WriteBlockToDisk: OpenBlockFile failed");
}
@@ -880,7 +880,7 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos) cons
block.SetNull();
// Open history file to read
- CAutoFile filein{OpenBlockFile(pos, true), CLIENT_VERSION};
+ CAutoFile filein{OpenBlockFile(pos, true)};
if (filein.IsNull()) {
return error("ReadBlockFromDisk: OpenBlockFile failed for %s", pos.ToString());
}
@@ -923,7 +923,7 @@ bool BlockManager::ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatF
{
FlatFilePos hpos = pos;
hpos.nPos -= 8; // Seek back 8 bytes for meta header
- AutoFile filein{OpenBlockFile(hpos, true)};
+ CAutoFile filein{OpenBlockFile(hpos, true)};
if (filein.IsNull()) {
return error("%s: OpenBlockFile failed for %s", __func__, pos.ToString());
}
@@ -1015,7 +1015,7 @@ void ImportBlocks(ChainstateManager& chainman, std::vector<fs::path> vImportFile
if (!fs::exists(chainman.m_blockman.GetBlockPosFilename(pos))) {
break; // No block files left to reindex
}
- CAutoFile file{chainman.m_blockman.OpenBlockFile(pos, true), CLIENT_VERSION};
+ CAutoFile file{chainman.m_blockman.OpenBlockFile(pos, true)};
if (file.IsNull()) {
break; // This error is logged in OpenBlockFile
}
diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h
index b251ece31f..a89fa7f76e 100644
--- a/src/node/blockstorage.h
+++ b/src/node/blockstorage.h
@@ -29,6 +29,7 @@
#include <vector>
class BlockValidationState;
+class CAutoFile;
class CBlock;
class CBlockFileInfo;
class CBlockUndo;
@@ -126,7 +127,7 @@ private:
FlatFileSeq BlockFileSeq() const;
FlatFileSeq UndoFileSeq() const;
- FILE* OpenUndoFile(const FlatFilePos& pos, bool fReadOnly = false) const;
+ CAutoFile OpenUndoFile(const FlatFilePos& pos, bool fReadOnly = false) const;
bool WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const;
bool UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const uint256& hashBlock) const;
@@ -278,7 +279,7 @@ public:
void UpdatePruneLock(const std::string& name, const PruneLockInfo& lock_info) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
/** Open a block file (blk?????.dat) */
- FILE* OpenBlockFile(const FlatFilePos& pos, bool fReadOnly = false) const;
+ CAutoFile OpenBlockFile(const FlatFilePos& pos, bool fReadOnly = false) const;
/** Translation to a filesystem path */
fs::path GetBlockPosFilename(const FlatFilePos& pos) const;