refactor: Add FlatFileSeq member variables in BlockManager

Instead of constructing a new class every time a file operation is done,
construct them once for each of the undo and block file when a new
BlockManager is created.

In future, this might make it easier to introduce an abstract block
store.
This commit is contained in:
TheCharlatan
2024-07-23 22:18:15 +02:00
parent 910d38b22f
commit 7aa8994c6f
4 changed files with 20 additions and 28 deletions

View File

@@ -63,7 +63,7 @@ public:
fs::path FileName(const FlatFilePos& pos) const;
/** Open a handle to the file at the given position. */
FILE* Open(const FlatFilePos& pos, bool read_only = false);
FILE* Open(const FlatFilePos& pos, bool read_only = false) const;
/**
* Allocate additional space in a file after the given starting position. The amount allocated
@@ -74,7 +74,7 @@ public:
* @param[out] out_of_space Whether the allocation failed due to insufficient disk space.
* @return The number of bytes successfully allocated.
*/
size_t Allocate(const FlatFilePos& pos, size_t add_size, bool& out_of_space);
size_t Allocate(const FlatFilePos& pos, size_t add_size, bool& out_of_space) const;
/**
* Commit a file to disk, and optionally truncate off extra pre-allocated bytes if final.
@@ -83,7 +83,7 @@ public:
* @param[in] finalize True if no more data will be written to this file.
* @return true on success, false on failure.
*/
bool Flush(const FlatFilePos& pos, bool finalize = false);
bool Flush(const FlatFilePos& pos, bool finalize = false) const;
};
#endif // BITCOIN_FLATFILE_H