From 72bfa9dd305258789b0d2e80f8af13962e5aac42 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 10 Apr 2026 20:22:35 +0100 Subject: Return path of parked lines log file from parkQueuedLogLines Or the last errno on failure. --- src/ingestor.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/ingestor.cpp') diff --git a/src/ingestor.cpp b/src/ingestor.cpp index c5cb8d8..0659f1f 100644 --- a/src/ingestor.cpp +++ b/src/ingestor.cpp @@ -275,11 +275,11 @@ namespace WebStat { } } - void + std::expected Ingestor::parkQueuedLogLines() { if (queuedLines.empty()) { - return; + return std::unexpected(0); } const std::filesystem::path path { settings.fallbackDir / std::format("parked-{}.short", crc32(queuedLines.front()))}; @@ -290,16 +290,19 @@ namespace WebStat { } if (fflush(parked.get()) == 0) { queuedLines.clear(); - auto finalPath = auto {path}.replace_extension(".log"); + auto finalPath = std::filesystem::path {path}.replace_extension(".log"); + parked.reset(); if (rename(path.c_str(), finalPath.c_str()) == 0) { - return; + return finalPath; } } } + const int err = errno; log(LOG_ERR, "Failed to park %zu queued lines:", queuedLines.size()); for (const auto & line : queuedLines) { log(LOG_ERR, "\t%.*s", static_cast(line.length()), line.data()); } + return std::unexpected(err); } void @@ -334,7 +337,7 @@ namespace WebStat { unsigned int count = 0; for (auto pathIter = std::filesystem::directory_iterator {settings.fallbackDir}; pathIter != std::filesystem::directory_iterator {}; ++pathIter) { - if (scn::scan(pathIter->path().filename().string(), "parked-{}.log")) { + if (scn::scan(pathIter->path().filename().string(), "parked-{:[a-zA-Z0-9]}.log")) { jobIngestParkedLines(pathIter->path()); count += 1; } -- cgit v1.3