| 37 | } |
| 38 | |
| 39 | std::filesystem::path capture_utils::makeDatedCaptureOutputPath(const std::filesystem::path& outputDirectory, |
| 40 | std::string_view extension) { |
| 41 | const auto now = std::chrono::system_clock::now(); |
| 42 | const std::string datePrefix = std::format("{:%Y-%m-%d}", std::chrono::floor<std::chrono::days>(now)); |
| 43 | |
| 44 | uint32_t nextIndex = 1; |
| 45 | std::error_code fsError; |
| 46 | for (std::filesystem::directory_iterator it(outputDirectory, fsError), end; !fsError && it != end; it.increment(fsError)) { |
| 47 | if (fsError || !it->is_regular_file(fsError)) { |
| 48 | continue; |
| 49 | } |
| 50 | if (const std::optional<uint32_t> index = parseDailyCaptureIndex(it->path(), datePrefix, extension)) { |
| 51 | nextIndex = std::max(nextIndex, *index + 1); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | return outputDirectory / std::format("{}_{}{}", datePrefix, nextIndex, extension); |
| 56 | } |
nothing calls this directly
no test coverage detected