mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-02 23:42:33 +02:00
Diff-minimise
This commit is contained in:
parent
d2ea6ab60b
commit
eddc01a795
@ -63,18 +63,19 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data
|
||||
FILE *file = fsbridge::fopen(pathTmp, "wb");
|
||||
AutoFile fileout{file};
|
||||
if (fileout.IsNull()) {
|
||||
fileout.fclose();
|
||||
remove(pathTmp);
|
||||
return error("%s: Failed to open file %s", __func__, fs::PathToString(pathTmp));
|
||||
}
|
||||
|
||||
// Serialize
|
||||
if (!SerializeDB(fileout, data)) {
|
||||
(void)fileout.fclose();
|
||||
fileout.fclose();
|
||||
remove(pathTmp);
|
||||
return false;
|
||||
}
|
||||
if (!FileCommit(fileout.Get())) {
|
||||
(void)fileout.fclose();
|
||||
fileout.fclose();
|
||||
remove(pathTmp);
|
||||
return error("%s: Failed to flush file %s", __func__, fs::PathToString(pathTmp));
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ static void FindByte(benchmark::Bench& bench)
|
||||
});
|
||||
|
||||
// Cleanup
|
||||
(void)file.fclose();
|
||||
file.fclose();
|
||||
fs::remove("streams_tmp");
|
||||
}
|
||||
|
||||
|
@ -169,8 +169,7 @@ bool DumpMempool(const CTxMemPool& pool, const fs::path& dump_path, FopenFn mock
|
||||
|
||||
auto mid = SteadyClock::now();
|
||||
|
||||
const fs::path file_fspath{dump_path + ".new"};
|
||||
AutoFile file{mockable_fopen_function(file_fspath, "wb")};
|
||||
AutoFile file{mockable_fopen_function(dump_path + ".new", "wb")};
|
||||
if (file.IsNull()) {
|
||||
return false;
|
||||
}
|
||||
@ -202,6 +201,7 @@ bool DumpMempool(const CTxMemPool& pool, const fs::path& dump_path, FopenFn mock
|
||||
if (!skip_file_commit && !FileCommit(file.Get()))
|
||||
throw std::runtime_error("FileCommit failed");
|
||||
if (file.fclose() != 0) {
|
||||
const fs::path file_fspath{dump_path + ".new"};
|
||||
throw std::runtime_error(
|
||||
strprintf("Error closing %s: %s", fs::PathToString(file_fspath), SysErrorString(errno)));
|
||||
}
|
||||
|
@ -384,13 +384,7 @@ public:
|
||||
*
|
||||
* Will automatically close the file when it goes out of scope if not null.
|
||||
* If you're returning the file pointer, return file.release().
|
||||
* If you need to close the file early, use autofile.fclose() instead of fclose(underlying_FILE).
|
||||
*
|
||||
* @note If the file has been written to, then the caller must close it
|
||||
* explicitly with the `fclose()` method, check if it returns an error and treat
|
||||
* such an error as if the `write()` method failed. The OS's `fclose(3)` may
|
||||
* fail to flush to disk data that has been previously written, rendering the
|
||||
* file corrupt.
|
||||
* If you need to close the file early, use file.fclose() instead of fclose(file).
|
||||
*/
|
||||
class AutoFile
|
||||
{
|
||||
@ -422,7 +416,7 @@ public:
|
||||
|
||||
bool feof() const { return std::feof(m_file); }
|
||||
|
||||
[[nodiscard]] int fclose()
|
||||
int fclose()
|
||||
{
|
||||
if (auto rel{release()}) return std::fclose(rel);
|
||||
return 0;
|
||||
|
@ -47,7 +47,7 @@ FUZZ_TARGET(autofile)
|
||||
}
|
||||
},
|
||||
[&] {
|
||||
(void)auto_file.fclose();
|
||||
auto_file.fclose();
|
||||
},
|
||||
[&] {
|
||||
ReadFromStream(fuzzed_data_provider, auto_file);
|
||||
|
@ -48,7 +48,7 @@ CreateAndActivateUTXOSnapshot(
|
||||
AutoFile auto_outfile{outfile};
|
||||
|
||||
UniValue result = CreateUTXOSnapshot(
|
||||
node, node.chainman->ActiveChainstate(), auto_outfile, snapshot_path, snapshot_path); // Will close auto_outfile.
|
||||
node, node.chainman->ActiveChainstate(), auto_outfile, snapshot_path, snapshot_path);
|
||||
LogPrintf(
|
||||
"Wrote UTXO snapshot to %s: %s\n", fs::PathToString(snapshot_path.make_preferred()), result.write());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user