From 9a221d1291bb540117e0264b750ca97037d2d29c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Apr 2026 18:42:23 +0000 Subject: [PATCH] Address code review feedback: retry loop, comment cleanup, error code improvements Agent-Logs-Url: https://github.com/XRPLF/rippled/sessions/629eace2-9c23-40d9-89f5-9ef3099cdf14 Co-authored-by: mvadari <8029314+mvadari@users.noreply.github.com> --- src/libxrpl/basics/FileUtilities.cpp | 4 ++-- src/test/basics/FileUtilities_test.cpp | 2 +- src/xrpld/app/misc/SHAMapStoreImp.cpp | 18 +++++++++++++++--- src/xrpld/core/Config.h | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/libxrpl/basics/FileUtilities.cpp b/src/libxrpl/basics/FileUtilities.cpp index 9ef5fe58cf..53e401dc97 100644 --- a/src/libxrpl/basics/FileUtilities.cpp +++ b/src/libxrpl/basics/FileUtilities.cpp @@ -35,7 +35,7 @@ getFileContents( if (!fileStream) { - ec = make_error_code(static_cast(errno)); + ec.assign(errno, std::generic_category()); return {}; } @@ -44,7 +44,7 @@ getFileContents( if (fileStream.bad()) { - ec = make_error_code(static_cast(errno)); + ec.assign(errno, std::generic_category()); return {}; } diff --git a/src/test/basics/FileUtilities_test.cpp b/src/test/basics/FileUtilities_test.cpp index 18545a2544..4c688b63b5 100644 --- a/src/test/basics/FileUtilities_test.cpp +++ b/src/test/basics/FileUtilities_test.cpp @@ -44,7 +44,7 @@ public: { // Test with small max auto const bad = getFileContents(ec, path, 16); - BEAST_EXPECT(ec && ec.value() == static_cast(std::errc::file_too_large)); + BEAST_EXPECT(ec && ec == std::errc::file_too_large); BEAST_EXPECT(bad.empty()); } } diff --git a/src/xrpld/app/misc/SHAMapStoreImp.cpp b/src/xrpld/app/misc/SHAMapStoreImp.cpp index ce90bd1483..335165d5e2 100644 --- a/src/xrpld/app/misc/SHAMapStoreImp.cpp +++ b/src/xrpld/app/misc/SHAMapStoreImp.cpp @@ -475,9 +475,21 @@ SHAMapStoreImp::makeBackendRotating(std::string path) { std::filesystem::path const p = get(section, "path"); std::random_device rd; - std::ostringstream oss; - oss << std::hex << std::setfill('0') << std::setw(8) << rd() << std::setw(8) << rd(); - newPath = (p / dbPrefix_).string() + "." + oss.str(); + constexpr std::size_t maxAttempts = 100; + for (std::size_t attempt = 0; attempt < maxAttempts; ++attempt) + { + std::ostringstream oss; + oss << std::hex << std::setfill('0') << std::setw(8) << rd() << std::setw(8) << rd(); + auto const candidate = + std::filesystem::path((p / dbPrefix_).string() + "." + oss.str()); + if (!std::filesystem::exists(candidate)) + { + newPath = candidate; + break; + } + } + if (newPath.empty()) + Throw("Unable to generate a unique rotating backend path"); } section.set("path", newPath.string()); diff --git a/src/xrpld/core/Config.h b/src/xrpld/core/Config.h index d63ee2e73b..d984100af7 100644 --- a/src/xrpld/core/Config.h +++ b/src/xrpld/core/Config.h @@ -10,7 +10,7 @@ #include #include -#include // VFALCO FIX: This include should not be here +#include #include #include #include