Skip to content

Commit ffd5e7a

Browse files
author
MarcoFalke
committed
Merge #20519: Handle rename failure in DumpMempool(...) by using the RenameOver(...) return value. Add [[nodiscard]] to RenameOver(...).
ce9dd45 Add [[nodiscard]] to RenameOver(...) (practicalswift) 9429a39 Handle rename failure in DumpMempool(...) by using RenameOver(...) return value (practicalswift) Pull request description: Handle rename failure in `DumpMempool(...)` by using the `RenameOver(...)` return value. Add `[[nodiscard]]` to `RenameOver(...)` to reduce the risk of similar rename issues in the future. ACKs for top commit: vasild: ACK ce9dd45 theStack: ACK ce9dd45 🏷️ Tree-SHA512: 1e63d7f3061e1f6ea2df5750dbc1547a39bd50b6c529812a0c8a0c11d3100c241afdf14094e69b69a38bade7e54a12b2a42888545874398eaf5d02421b57e874
2 parents 81d5af4 + ce9dd45 commit ffd5e7a

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/util/system.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ bool FileCommit(FILE *file);
6060
bool TruncateFile(FILE *file, unsigned int length);
6161
int RaiseFileDescriptorLimit(int nMinFD);
6262
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);
63-
bool RenameOver(fs::path src, fs::path dest);
63+
[[nodiscard]] bool RenameOver(fs::path src, fs::path dest);
6464
bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only=false);
6565
void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name);
6666
bool DirIsWritable(const fs::path& directory);

src/validation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5110,7 +5110,9 @@ bool DumpMempool(const CTxMemPool& pool)
51105110
if (!FileCommit(file.Get()))
51115111
throw std::runtime_error("FileCommit failed");
51125112
file.fclose();
5113-
RenameOver(GetDataDir() / "mempool.dat.new", GetDataDir() / "mempool.dat");
5113+
if (!RenameOver(GetDataDir() / "mempool.dat.new", GetDataDir() / "mempool.dat")) {
5114+
throw std::runtime_error("Rename failed");
5115+
}
51145116
int64_t last = GetTimeMicros();
51155117
LogPrintf("Dumped mempool: %gs to copy, %gs to dump\n", (mid-start)*MICRO, (last-mid)*MICRO);
51165118
} catch (const std::exception& e) {

0 commit comments

Comments
 (0)