Explicitly close all AutoFiles that have been written

There is no way to report a close error from `AutoFile` destructor.
Such an error could be serious if the file has been written to because
it may mean the file is now corrupted (same as if write fails).

So, change all users of `AutoFile` that use it to write data to
explicitly close the file and handle a possible error.
This commit is contained in:
Vasil Dimov
2024-01-24 15:03:55 +01:00
parent a69c4098b2
commit 8bb34f07df
15 changed files with 121 additions and 38 deletions

View File

@@ -4005,6 +4005,11 @@ static void CaptureMessageToFile(const CAddress& addr,
uint32_t size = data.size();
ser_writedata32(f, size);
f << data;
if (f.fclose() != 0) {
throw std::ios_base::failure(
strprintf("Error closing %s after write, file contents are likely incomplete", fs::PathToString(path)));
}
}
std::function<void(const CAddress& addr,