2020-04-16 09:18:19 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2017-2020 The Project X-Ray Authors.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a ISC-style
|
|
|
|
|
* license that can be found in the LICENSE file or at
|
|
|
|
|
* https://opensource.org/licenses/ISC
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: ISC
|
|
|
|
|
*/
|
2017-11-21 01:38:34 +01:00
|
|
|
#include <prjxray/database.h>
|
|
|
|
|
|
2026-07-30 16:18:36 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#else
|
2017-11-21 01:38:34 +01:00
|
|
|
#include <glob.h>
|
2026-07-30 16:18:36 +02:00
|
|
|
#endif
|
2017-11-21 01:38:34 +01:00
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
#include <absl/strings/str_cat.h>
|
|
|
|
|
|
|
|
|
|
namespace prjxray {
|
|
|
|
|
|
|
|
|
|
static constexpr const char kSegbitsGlobPattern[] = "segbits_*.db";
|
|
|
|
|
|
2018-01-08 22:30:02 +01:00
|
|
|
std::vector<std::unique_ptr<prjxray::SegbitsFileReader>> Database::segbits()
|
|
|
|
|
const {
|
2017-11-21 01:38:34 +01:00
|
|
|
std::vector<std::unique_ptr<prjxray::SegbitsFileReader>> segbits;
|
|
|
|
|
|
2026-07-30 16:18:36 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
const std::string pattern =
|
|
|
|
|
absl::StrCat(db_path_, "/", kSegbitsGlobPattern);
|
|
|
|
|
WIN32_FIND_DATAA find_data;
|
|
|
|
|
HANDLE handle = FindFirstFileA(pattern.c_str(), &find_data);
|
|
|
|
|
if (handle == INVALID_HANDLE_VALUE) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
auto this_segbit = SegbitsFileReader::InitWithFile(
|
|
|
|
|
absl::StrCat(db_path_, "/", find_data.cFileName));
|
|
|
|
|
if (this_segbit) {
|
|
|
|
|
segbits.emplace_back(std::move(this_segbit));
|
|
|
|
|
}
|
|
|
|
|
} while (FindNextFileA(handle, &find_data));
|
|
|
|
|
|
|
|
|
|
FindClose(handle);
|
|
|
|
|
#else
|
2017-11-21 01:38:34 +01:00
|
|
|
glob_t segbits_glob_results;
|
|
|
|
|
int ret = glob(absl::StrCat(db_path_, "/", kSegbitsGlobPattern).c_str(),
|
2018-01-08 22:30:02 +01:00
|
|
|
GLOB_NOSORT | GLOB_TILDE, NULL, &segbits_glob_results);
|
2017-11-21 01:38:34 +01:00
|
|
|
if (ret < 0) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 22:30:02 +01:00
|
|
|
for (size_t idx = 0; idx < segbits_glob_results.gl_pathc; idx++) {
|
2017-11-21 01:38:34 +01:00
|
|
|
auto this_segbit = SegbitsFileReader::InitWithFile(
|
2018-01-08 22:30:02 +01:00
|
|
|
segbits_glob_results.gl_pathv[idx]);
|
2017-11-21 01:38:34 +01:00
|
|
|
if (this_segbit) {
|
|
|
|
|
segbits.emplace_back(std::move(this_segbit));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
globfree(&segbits_glob_results);
|
2026-07-30 16:18:36 +02:00
|
|
|
#endif
|
2017-11-21 01:38:34 +01:00
|
|
|
|
|
|
|
|
return segbits;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace prjxray
|