diff --git a/src/init.cpp b/src/init.cpp index e7bc65e550..df80e21bc5 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -898,7 +898,9 @@ static void ThreadImport(std::vector vImportFiles) fs::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old"; LogPrintf("Importing bootstrap.dat...\n"); LoadExternalBlockFile(chainparams, file); - RenameOver(pathBootstrap, pathBootstrapOld); + if (!RenameOver(pathBootstrap, pathBootstrapOld)) { + throw std::runtime_error("Rename failed"); + } } else { LogPrintf("Warning: Could not open bootstrap file %s\n", pathBootstrap.string()); } diff --git a/src/util/system.h b/src/util/system.h index b832f1d73b..eace7b4eb1 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -90,7 +90,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); diff --git a/src/validation.cpp b/src/validation.cpp index 472d21a63e..07f5599ce4 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -5247,7 +5247,9 @@ bool DumpMempool() 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) {