From 9429a398e291a1b5edcfc657b94fcaf52cd1d8f9 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Fri, 27 Nov 2020 12:41:07 +0000 Subject: [PATCH 1/2] Handle rename failure in DumpMempool(...) by using RenameOver(...) return value --- src/validation.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/validation.cpp b/src/validation.cpp index 71402ef2630..9197daec801 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -5110,7 +5110,9 @@ bool DumpMempool(const CTxMemPool& pool) if (!FileCommit(file.Get())) throw std::runtime_error("FileCommit failed"); file.fclose(); - RenameOver(GetDataDir() / "mempool.dat.new", GetDataDir() / "mempool.dat"); + if (!RenameOver(GetDataDir() / "mempool.dat.new", GetDataDir() / "mempool.dat")) { + throw std::runtime_error("Rename failed"); + } int64_t last = GetTimeMicros(); LogPrintf("Dumped mempool: %gs to copy, %gs to dump\n", (mid-start)*MICRO, (last-mid)*MICRO); } catch (const std::exception& e) { From ce9dd45422e1f4ecce6df68da086b8bfc2100756 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Fri, 27 Nov 2020 12:41:26 +0000 Subject: [PATCH 2/2] Add [[nodiscard]] to RenameOver(...) --- src/util/system.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/system.h b/src/util/system.h index 1df194ca84d..36a6170a177 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -60,7 +60,7 @@ bool FileCommit(FILE *file); bool TruncateFile(FILE *file, unsigned int length); int RaiseFileDescriptorLimit(int nMinFD); void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length); -bool RenameOver(fs::path src, fs::path dest); +[[nodiscard]] bool RenameOver(fs::path src, fs::path dest); bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only=false); void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name); bool DirIsWritable(const fs::path& directory);