mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-19 09:53:47 +01:00
streams: remove AutoFile::Get() entirely
Co-Authored-By: David Gumberg <davidzgumberg@gmail.com>
This commit is contained in:
parent
e624a9bef1
commit
a240e150e8
@ -73,7 +73,7 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data
|
||||
remove(pathTmp);
|
||||
return false;
|
||||
}
|
||||
if (!FileCommit(fileout.Get())) {
|
||||
if (!fileout.Commit()) {
|
||||
fileout.fclose();
|
||||
remove(pathTmp);
|
||||
LogError("%s: Failed to flush file %s\n", __func__, fs::PathToString(pathTmp));
|
||||
|
@ -151,7 +151,7 @@ bool BlockFilterIndex::CustomCommit(CDBBatch& batch)
|
||||
LogError("%s: Failed to open filter file %d\n", __func__, pos.nFile);
|
||||
return false;
|
||||
}
|
||||
if (!FileCommit(file.Get())) {
|
||||
if (!file.Commit()) {
|
||||
LogError("%s: Failed to commit filter file %d\n", __func__, pos.nFile);
|
||||
return false;
|
||||
}
|
||||
@ -201,11 +201,11 @@ size_t BlockFilterIndex::WriteFilterToDisk(FlatFilePos& pos, const BlockFilter&
|
||||
LogPrintf("%s: Failed to open filter file %d\n", __func__, pos.nFile);
|
||||
return 0;
|
||||
}
|
||||
if (!TruncateFile(last_file.Get(), pos.nPos)) {
|
||||
if (!last_file.Truncate(pos.nPos)) {
|
||||
LogPrintf("%s: Failed to truncate filter file %d\n", __func__, pos.nFile);
|
||||
return 0;
|
||||
}
|
||||
if (!FileCommit(last_file.Get())) {
|
||||
if (!last_file.Commit()) {
|
||||
LogPrintf("%s: Failed to commit filter file %d\n", __func__, pos.nFile);
|
||||
return 0;
|
||||
}
|
||||
|
@ -199,8 +199,8 @@ bool DumpMempool(const CTxMemPool& pool, const fs::path& dump_path, FopenFn mock
|
||||
LogInfo("Writing %d unbroadcast transactions to file.\n", unbroadcast_txids.size());
|
||||
file << unbroadcast_txids;
|
||||
|
||||
if (!skip_file_commit && !FileCommit(file.Get()))
|
||||
throw std::runtime_error("FileCommit failed");
|
||||
if (!skip_file_commit && !file.Commit())
|
||||
throw std::runtime_error("Commit failed");
|
||||
file.fclose();
|
||||
if (!RenameOver(dump_path + ".new", dump_path)) {
|
||||
throw std::runtime_error("Rename failed");
|
||||
|
@ -77,7 +77,7 @@ std::optional<uint256> ReadSnapshotBaseBlockhash(fs::path chaindir)
|
||||
afile.seek(0, SEEK_END);
|
||||
if (position != afile.tell()) {
|
||||
LogPrintf("[snapshot] warning: unexpected trailing data in %s\n", read_from_str);
|
||||
} else if (std::ferror(afile.Get())) {
|
||||
} else if (afile.IsError()) {
|
||||
LogPrintf("[snapshot] warning: i/o error reading %s\n", read_from_str);
|
||||
}
|
||||
return base_blockhash;
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <span.h>
|
||||
#include <streams.h>
|
||||
#include <util/fs_helpers.h>
|
||||
|
||||
#include <array>
|
||||
|
||||
@ -99,3 +100,18 @@ void AutoFile::write(Span<const std::byte> src)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool AutoFile::Commit()
|
||||
{
|
||||
return ::FileCommit(m_file);
|
||||
}
|
||||
|
||||
bool AutoFile::IsError()
|
||||
{
|
||||
return ferror(m_file);
|
||||
}
|
||||
|
||||
bool AutoFile::Truncate(unsigned size)
|
||||
{
|
||||
return ::TruncateFile(m_file, size);
|
||||
}
|
||||
|
@ -420,12 +420,6 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** Get wrapped FILE* without transfer of ownership.
|
||||
* @note Ownership of the FILE* will remain with this class. Use this only if the scope of the
|
||||
* AutoFile outlives use of the passed pointer.
|
||||
*/
|
||||
std::FILE* Get() const { return m_file; }
|
||||
|
||||
/** Return true if the wrapped FILE* is nullptr, false otherwise.
|
||||
*/
|
||||
bool IsNull() const { return m_file == nullptr; }
|
||||
@ -459,6 +453,10 @@ public:
|
||||
::Unserialize(*this, obj);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Commit();
|
||||
bool IsError();
|
||||
bool Truncate(unsigned size);
|
||||
};
|
||||
|
||||
/** Wrapper around an AutoFile& that implements a ring buffer to
|
||||
|
@ -56,7 +56,6 @@ FUZZ_TARGET(autofile)
|
||||
WriteToStream(fuzzed_data_provider, auto_file);
|
||||
});
|
||||
}
|
||||
(void)auto_file.Get();
|
||||
(void)auto_file.IsNull();
|
||||
if (fuzzed_data_provider.ConsumeBool()) {
|
||||
FILE* f = auto_file.release();
|
||||
|
Loading…
Reference in New Issue
Block a user