summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-08-31 12:53:29 +0200
committerGitHub <noreply@github.com>2023-08-31 12:53:29 +0200
commitf46d67c5976e77e270002267996a559b1cb6d2c1 (patch)
tree4d74731f0ae48852431f7a68d9652f031e4be713 /searchlib
parenta3f84a6c0d6c176be909c545c3070087782c9844 (diff)
parent6d81508c64a1c6967d125e75743feb543ae22c84 (diff)
Merge pull request #28311 from vespa-engine/toregge/use-std-filesystem-directory-iterator-in-search-transactionlog-domain
Use std::filesystem::directory_iterator in search::transactionlog::Do…
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/transactionlog/domain.cpp36
1 files changed, 15 insertions, 21 deletions
diff --git a/searchlib/src/vespa/searchlib/transactionlog/domain.cpp b/searchlib/src/vespa/searchlib/transactionlog/domain.cpp
index 6d8cd5b206c..e0e910fb53f 100644
--- a/searchlib/src/vespa/searchlib/transactionlog/domain.cpp
+++ b/searchlib/src/vespa/searchlib/transactionlog/domain.cpp
@@ -14,6 +14,7 @@
#include <algorithm>
#include <thread>
#include <cassert>
+#include <filesystem>
#include <future>
#include <vespa/log/log.h>
@@ -485,27 +486,20 @@ Domain::SerialNumList
Domain::scanDir()
{
SerialNumList res;
-
- FastOS_DirectoryScan dirScan(dir().c_str());
-
- const char *wantPrefix = _name.c_str();
- size_t wantPrefixLen = strlen(wantPrefix);
-
- while (dirScan.ReadNext()) {
- const char *ename = dirScan.GetName();
- if (strcmp(ename, ".") == 0 ||
- strcmp(ename, "..") == 0)
- continue;
- if (strncmp(ename, wantPrefix, wantPrefixLen) != 0)
- continue;
- if (ename[wantPrefixLen] != '-')
- continue;
- const char *p = ename + wantPrefixLen + 1;
- uint64_t num = strtoull(p, nullptr, 10);
- string checkName = fmt("%s-%016" PRIu64, _name.c_str(), num);
- if (strcmp(checkName.c_str(), ename) != 0)
- continue;
- res.push_back(static_cast<SerialNum>(num));
+ std::filesystem::directory_iterator dir_scan{std::filesystem::path(dir())};
+ vespalib::string prefix = _name + "-";
+ for (auto& entry : dir_scan) {
+ if (entry.is_regular_file()) {
+ vespalib::string ename = entry.path().filename().string();
+ if (ename.substr(0, prefix.size()) == prefix) {
+ const char *p = &ename[prefix.size()];
+ uint64_t num = strtoull(p, nullptr, 10);
+ string check_name = fmt("%s-%016" PRIu64, _name.c_str(), num);
+ if (check_name == ename) {
+ res.push_back(static_cast<SerialNum>(num));
+ }
+ }
+ }
}
std::sort(res.begin(), res.end());
return res;