updated build system
Some checks failed
BlockStorage/repertory/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
2024-10-12 13:06:42 -05:00
parent 989d14072d
commit 66305c3c86
6 changed files with 143 additions and 77 deletions

View File

@@ -30,9 +30,14 @@ namespace {
auto traverse_directory(
std::string_view path,
std::function<bool(repertory::utils::file::directory)> directory_action,
std::function<bool(repertory::utils::file::file)> file_action) -> bool {
std::function<bool(repertory::utils::file::file)> file_action,
repertory::stop_type *stop_requested) -> bool {
auto res{true};
const auto is_stop_requested = [&stop_requested]() -> bool {
return (stop_requested != nullptr && !*stop_requested);
};
#if defined(_WIN32)
WIN32_FIND_DATAA fd{};
auto search = repertory::utils::path::combine(path, {"*.*"});
@@ -48,13 +53,15 @@ auto traverse_directory(
if ((std::string_view(fd.cFileName) != ".") &&
(std::string_view(fd.cFileName) != "..")) {
res = directory_action(repertory::utils::file::directory{
repertory::utils::path::combine(path, {fd.cFileName})});
repertory::utils::path::combine(path, {fd.cFileName}),
stop_requested_,
});
}
} else {
res = file_action(repertory::utils::file::file(
repertory::utils::path::combine(path, {fd.cFileName})));
}
} while (res && (::FindNextFileA(find, &fd) != 0));
} while (res && (::FindNextFileA(find, &fd) != 0) && !is_stop_requested());
::FindClose(find);
#else // !defined(_WIN32)
@@ -66,7 +73,7 @@ auto traverse_directory(
}
struct dirent *de{nullptr};
while (res && (de = readdir(root))) {
while (res && (de = readdir(root)) && !is_stop_requested()) {
if (de->d_type == DT_DIR) {
if ((std::string_view(de->d_name) != ".") &&
(std::string_view(de->d_name) != "..")) {
@@ -127,7 +134,8 @@ auto directory::count(bool recursive) const -> std::uint64_t {
[&ret](auto /* file_item */) -> bool {
++ret;
return true;
});
},
stop_requested_);
return ret;
} catch (const std::exception &e) {
@@ -147,7 +155,7 @@ auto directory::create_directory(std::string_view path) const
try {
auto abs_path = utils::path::combine(path_, {path});
if (directory{abs_path}.exists()) {
if (directory{abs_path, stop_requested_}.exists()) {
return std::make_unique<directory>(abs_path);
}
@@ -165,7 +173,8 @@ auto directory::create_directory(std::string_view path) const
utils::string::split(abs_path, utils::path::directory_seperator, false);
std::string current_path;
for (std::size_t idx = 0U; ret && (idx < paths.size()); ++idx) {
for (std::size_t idx = 0U;
!is_stop_requested() && ret && (idx < paths.size()); ++idx) {
if (paths.at(idx).empty()) {
current_path = utils::path::directory_seperator;
continue;
@@ -206,7 +215,9 @@ auto directory::get_directory(std::string_view path) const -> fs_directory_t {
try {
auto dir_path = utils::path::combine(path_, {path});
return fs_directory_t{
directory{dir_path}.exists() ? new directory{dir_path} : nullptr,
directory{dir_path, stop_requested_}.exists()
? new directory(dir_path, stop_requested_)
: nullptr,
};
} catch (const std::exception &e) {
utils::error::handle_exception(function_name, e);
@@ -227,14 +238,14 @@ auto directory::get_directories() const -> std::vector<fs_directory_t> {
traverse_directory(
path_,
[&ret](auto dir_item) -> bool {
[this, &ret](auto dir_item) -> bool {
ret.emplace_back(fs_directory_t{
new directory(dir_item.get_path()),
new directory(dir_item.get_path(), stop_requested_),
});
return true;
},
[](auto /* file_item */) -> bool { return true; });
[](auto /* file_item */) -> bool { return true; }, stop_requested_);
return ret;
} catch (const std::exception &e) {
@@ -298,7 +309,8 @@ auto directory::get_files() const -> std::vector<fs_file_t> {
new file(file_item.get_path()),
});
return true;
});
},
stop_requested_);
return ret;
} catch (const std::exception &e) {
@@ -320,9 +332,9 @@ auto directory::get_items() const -> std::vector<fs_item_t> {
traverse_directory(
path_,
[&ret](auto dir_item) -> bool {
[this, &ret](auto dir_item) -> bool {
ret.emplace_back(fs_item_t{
new directory(dir_item.get_path()),
new directory(dir_item.get_path(), stop_requested_),
});
return true;
},
@@ -331,7 +343,8 @@ auto directory::get_items() const -> std::vector<fs_item_t> {
new file(file_item.get_path()),
});
return true;
});
},
stop_requested_);
return ret;
} catch (const std::exception &e) {
@@ -343,6 +356,10 @@ auto directory::get_items() const -> std::vector<fs_item_t> {
return {};
}
auto directory::is_stop_requested() const -> bool {
return (stop_requested_ != nullptr) && *stop_requested_;
}
auto directory::is_symlink() const -> bool {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
@@ -415,7 +432,8 @@ auto directory::remove_recursively() -> bool {
if (not traverse_directory(
path_,
[](auto dir_item) -> bool { return dir_item.remove_recursively(); },
[](auto file_item) -> bool { return file_item.remove(); })) {
[](auto file_item) -> bool { return file_item.remove(); },
stop_requested_)) {
return false;
}
@@ -452,7 +470,8 @@ auto directory::size(bool recursive) const -> std::uint64_t {
ret += cur_size.value();
}
return true;
});
},
stop_requested_);
return ret;
} catch (const std::exception &e) {