From 336b9c101ec09e1e9572c4e8ace5546a55f31fd3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 7 May 2026 09:31:41 +0000 Subject: [PATCH] refactor: use beast::uniqueRandomPath in SHAMapStoreImp makeBackendRotating Agent-Logs-Url: https://github.com/XRPLF/rippled/sessions/3807ab03-d6e1-4466-a2b9-b7512b943bba Co-authored-by: mathbunnyru <12270691+mathbunnyru@users.noreply.github.com> --- src/xrpld/app/misc/SHAMapStoreImp.cpp | 32 ++------------------------- 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/src/xrpld/app/misc/SHAMapStoreImp.cpp b/src/xrpld/app/misc/SHAMapStoreImp.cpp index 10d0fe23e6..2060ac9726 100644 --- a/src/xrpld/app/misc/SHAMapStoreImp.cpp +++ b/src/xrpld/app/misc/SHAMapStoreImp.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -26,21 +27,16 @@ #include #include -#include #include #include #include -#include #include #include #include #include #include -#include -#include #include #include -#include #include #include #include @@ -475,31 +471,7 @@ SHAMapStoreImp::makeBackendRotating(std::string path) } else { - std::filesystem::path const p = get(section, "path"); - std::random_device rd; - constexpr std::size_t kMAX_ATTEMPTS = 100; - for (std::size_t attempt = 0; attempt < kMAX_ATTEMPTS; ++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()); - std::error_code existsEc; - bool const candidateExists = std::filesystem::exists(candidate, existsEc); - if (existsEc) - { - Throw( - "Unable to check rotating backend path '" + candidate.string() + - "': " + existsEc.message()); - } - if (!candidateExists) - { - newPath = candidate; - break; - } - } - if (newPath.empty()) - Throw("Unable to generate a unique rotating backend path"); + newPath = beast::uniqueRandomPath(get(section, "path"), 100, dbPrefix_ + "."); } section.set("path", newPath.string());