diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2019-07-02 13:55:10 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2019-07-02 13:55:27 +0200 |
commit | 3ccab6470a61af9b1840ef4d5f84279ca0845560 (patch) | |
tree | 70910a57a4facafb324aac4744827b025823d3f3 /src | |
parent | 1212808762f63185bbde980c154d3e1a6c6eb819 (diff) | |
parent | d9753383b9e1b61d19d98bcd1d66607f398c7e9f (diff) |
Merge #16212: addrdb: Avoid eating inodes - remove temporary files created by SerializeFileDB in case of errors
d9753383b9e1b61d19d98bcd1d66607f398c7e9f addrdb: Remove temporary files created in SerializeFileDB. Fixes non-determinism in unit tests. (practicalswift)
Pull request description:
Remove temporary files created in `SerializeFileDB` in case of errors.
_Edit: Previously this was hit non-deterministically from the tests: that is no longer the case but the cleanup issue remains :-)_
ACKs for top commit:
laanwj:
code-review ACK d9753383b9e1b61d19d98bcd1d66607f398c7e9f
Tree-SHA512: e72b74b8de411f433bd8bb354cacae07ab75a240db6232bc6a37802ccd8086bff5275ce3d196ddde033d8ab9e2794bb8f60eb83554af7ec2e9f91d6186cb4647
Diffstat (limited to 'src')
-rw-r--r-- | src/addrdb.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/addrdb.cpp b/src/addrdb.cpp index c6083f5554..db936486b6 100644 --- a/src/addrdb.cpp +++ b/src/addrdb.cpp @@ -44,18 +44,30 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data fs::path pathTmp = GetDataDir() / tmpfn; FILE *file = fsbridge::fopen(pathTmp, "wb"); CAutoFile fileout(file, SER_DISK, CLIENT_VERSION); - if (fileout.IsNull()) + if (fileout.IsNull()) { + fileout.fclose(); + remove(pathTmp); return error("%s: Failed to open file %s", __func__, pathTmp.string()); + } // Serialize - if (!SerializeDB(fileout, data)) return false; - if (!FileCommit(fileout.Get())) + if (!SerializeDB(fileout, data)) { + fileout.fclose(); + remove(pathTmp); + return false; + } + if (!FileCommit(fileout.Get())) { + fileout.fclose(); + remove(pathTmp); return error("%s: Failed to flush file %s", __func__, pathTmp.string()); + } fileout.fclose(); // replace existing file, if any, with new file - if (!RenameOver(pathTmp, path)) + if (!RenameOver(pathTmp, path)) { + remove(pathTmp); return error("%s: Rename-into-place failed", __func__); + } return true; } |