refactor
This commit is contained in:
@ -58,7 +58,7 @@ public:
|
||||
|
||||
virtual void enumerate_api_path_list(
|
||||
std::function<void(const std::vector<i_file_db::file_info> &)> callback,
|
||||
const stop_type &stop_requested) const = 0;
|
||||
stop_type &stop_requested) const = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_api_path(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
@ -84,8 +84,7 @@ public:
|
||||
get_file_source_path(const std::string &api_path,
|
||||
std::string &source_path) const -> api_error = 0;
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
get_item_list(const stop_type &stop_requested) const
|
||||
[[nodiscard]] virtual auto get_item_list(stop_type &stop_requested) const
|
||||
-> std::vector<file_info> = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_source_path(const std::string &api_path,
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
|
||||
virtual void enumerate_api_path_list(
|
||||
std::function<void(const std::vector<std::string> &)> callback,
|
||||
const stop_type &stop_requested) const = 0;
|
||||
stop_type &stop_requested) const = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_api_path(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
|
@ -80,7 +80,7 @@ public:
|
||||
|
||||
void enumerate_api_path_list(
|
||||
std::function<void(const std::vector<i_file_db::file_info> &)> callback,
|
||||
const stop_type &stop_requested) const override;
|
||||
stop_type &stop_requested) const override;
|
||||
|
||||
[[nodiscard]] auto get_api_path(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
@ -106,7 +106,7 @@ public:
|
||||
std::string &source_path) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_item_list(const stop_type &stop_requested) const
|
||||
[[nodiscard]] auto get_item_list(stop_type &stop_requested) const
|
||||
-> std::vector<i_file_db::file_info> override;
|
||||
|
||||
[[nodiscard]] auto get_source_path(const std::string &api_path,
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
|
||||
void enumerate_api_path_list(
|
||||
std::function<void(const std::vector<std::string> &)> callback,
|
||||
const stop_type &stop_requested) const override;
|
||||
stop_type &stop_requested) const override;
|
||||
|
||||
[[nodiscard]] auto get_api_path(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
|
@ -55,7 +55,7 @@ public:
|
||||
|
||||
void enumerate_api_path_list(
|
||||
std::function<void(const std::vector<i_file_db::file_info> &)> callback,
|
||||
const stop_type &stop_requested) const override;
|
||||
stop_type &stop_requested) const override;
|
||||
|
||||
[[nodiscard]] auto get_api_path(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
@ -81,7 +81,7 @@ public:
|
||||
std::string &source_path) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_item_list(const stop_type &stop_requested) const
|
||||
[[nodiscard]] auto get_item_list(stop_type &stop_requested) const
|
||||
-> std::vector<i_file_db::file_info> override;
|
||||
|
||||
[[nodiscard]] auto get_source_path(const std::string &api_path,
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
|
||||
void enumerate_api_path_list(
|
||||
std::function<void(const std::vector<std::string> &)> callback,
|
||||
const stop_type &stop_requested) const override;
|
||||
stop_type &stop_requested) const override;
|
||||
|
||||
[[nodiscard]] auto get_api_path(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
|
@ -53,19 +53,19 @@ private:
|
||||
i_file_manager *fm_{};
|
||||
|
||||
private:
|
||||
void add_all_items(const stop_type &stop_requested);
|
||||
void add_all_items(stop_type &stop_requested);
|
||||
|
||||
void process_removed_directories(std::deque<removed_item> removed_list,
|
||||
const stop_type &stop_requested);
|
||||
stop_type &stop_requested);
|
||||
|
||||
void process_removed_files(std::deque<removed_item> removed_list,
|
||||
const stop_type &stop_requested);
|
||||
stop_type &stop_requested);
|
||||
|
||||
void process_removed_items(const stop_type &stop_requested);
|
||||
void process_removed_items(stop_type &stop_requested);
|
||||
|
||||
void remove_deleted_items(const stop_type &stop_requested);
|
||||
void remove_deleted_items(stop_type &stop_requested);
|
||||
|
||||
void remove_unmatched_source_files(const stop_type &stop_requested);
|
||||
void remove_unmatched_source_files(stop_type &stop_requested);
|
||||
|
||||
protected:
|
||||
[[nodiscard]] static auto create_api_file(std::string path, std::string key,
|
||||
|
@ -82,7 +82,7 @@ private:
|
||||
const encrypt_config &cfg,
|
||||
std::string &api_path) const -> bool;
|
||||
|
||||
void remove_deleted_files(const stop_type &stop_requested);
|
||||
void remove_deleted_files(stop_type &stop_requested);
|
||||
|
||||
public:
|
||||
[[nodiscard]] auto create_directory(const std::string &api_path,
|
||||
|
@ -40,7 +40,7 @@ public:
|
||||
struct polling_item final {
|
||||
std::string name;
|
||||
frequency freq;
|
||||
std::function<void(const stop_type &stop_requested)> action;
|
||||
std::function<void(stop_type &stop_requested)> action;
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -30,7 +30,7 @@ class app_config;
|
||||
class tasks final {
|
||||
public:
|
||||
struct task final {
|
||||
std::function<void(const stop_type &task_stopped)> action;
|
||||
std::function<void(stop_type &task_stopped)> action;
|
||||
};
|
||||
|
||||
class i_task {
|
||||
|
@ -151,16 +151,12 @@ auto rdb_file_db::count() const -> std::uint64_t {
|
||||
|
||||
void rdb_file_db::enumerate_api_path_list(
|
||||
std::function<void(const std::vector<i_file_db::file_info> &)> callback,
|
||||
const stop_type &stop_requested) const {
|
||||
stop_type &stop_requested) const {
|
||||
std::vector<i_file_db::file_info> list;
|
||||
{
|
||||
auto iter = create_iterator(file_family_);
|
||||
for (iter->SeekToFirst(); not stop_requested && iter->Valid();
|
||||
iter->Next()) {
|
||||
if (stop_requested) {
|
||||
break;
|
||||
}
|
||||
|
||||
auto json_data = json::parse(iter->value().ToString());
|
||||
list.emplace_back(i_file_db::file_info{
|
||||
iter->key().ToString(),
|
||||
@ -315,16 +311,13 @@ auto rdb_file_db::get_file_source_path(const std::string &api_path,
|
||||
return result;
|
||||
}
|
||||
|
||||
auto rdb_file_db::get_item_list(const stop_type &stop_requested) const
|
||||
auto rdb_file_db::get_item_list(stop_type &stop_requested) const
|
||||
-> std::vector<i_file_db::file_info> {
|
||||
std::vector<i_file_db::file_info> ret{};
|
||||
{
|
||||
auto iter = create_iterator(directory_family_);
|
||||
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
|
||||
if (stop_requested) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (iter->SeekToFirst(); not stop_requested && iter->Valid();
|
||||
iter->Next()) {
|
||||
ret.emplace_back(i_file_db::file_info{
|
||||
iter->key().ToString(),
|
||||
true,
|
||||
@ -335,11 +328,8 @@ auto rdb_file_db::get_item_list(const stop_type &stop_requested) const
|
||||
|
||||
{
|
||||
auto iter = create_iterator(file_family_);
|
||||
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
|
||||
if (stop_requested) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (iter->SeekToFirst(); not stop_requested && iter->Valid();
|
||||
iter->Next()) {
|
||||
auto json_data = json::parse(iter->value().ToString());
|
||||
ret.emplace_back(i_file_db::file_info{
|
||||
iter->key().ToString(),
|
||||
|
@ -66,7 +66,7 @@ auto rdb_meta_db::create_iterator(rocksdb::ColumnFamilyHandle *family) const
|
||||
|
||||
void rdb_meta_db::enumerate_api_path_list(
|
||||
std::function<void(const std::vector<std::string> &)> callback,
|
||||
const stop_type &stop_requested) const {
|
||||
stop_type &stop_requested) const {
|
||||
std::vector<std::string> list{};
|
||||
|
||||
auto iter = create_iterator(meta_family_);
|
||||
|
@ -135,11 +135,11 @@ auto sqlite_file_db::count() const -> std::uint64_t {
|
||||
|
||||
void sqlite_file_db::enumerate_api_path_list(
|
||||
std::function<void(const std::vector<i_file_db::file_info> &)> callback,
|
||||
const stop_type &stop_requested) const {
|
||||
stop_type &stop_requested) const {
|
||||
std::vector<i_file_db::file_info> list;
|
||||
|
||||
auto result = utils::db::sqlite::db_select{*db_, file_table}.go();
|
||||
while (result.has_row() && not stop_requested) {
|
||||
while (not stop_requested && result.has_row()) {
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
list.emplace_back(i_file_db::file_info{
|
||||
@ -309,12 +309,12 @@ auto sqlite_file_db::get_file_source_path(const std::string &api_path,
|
||||
return api_error::item_not_found;
|
||||
}
|
||||
|
||||
auto sqlite_file_db::get_item_list(const stop_type &stop_requested) const
|
||||
auto sqlite_file_db::get_item_list(stop_type &stop_requested) const
|
||||
-> std::vector<i_file_db::file_info> {
|
||||
std::vector<i_file_db::file_info> ret;
|
||||
|
||||
auto result = utils::db::sqlite::db_select{*db_, file_table}.go();
|
||||
while (result.has_row() && not stop_requested) {
|
||||
while (not stop_requested && result.has_row()) {
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
ret.emplace_back(i_file_db::file_info{
|
||||
|
@ -77,12 +77,12 @@ void sqlite_meta_db::clear() {
|
||||
|
||||
void sqlite_meta_db::enumerate_api_path_list(
|
||||
std::function<void(const std::vector<std::string> &)> callback,
|
||||
const stop_type &stop_requested) const {
|
||||
stop_type &stop_requested) const {
|
||||
auto result =
|
||||
utils::db::sqlite::db_select{*db_, table_name}.column("api_path").go();
|
||||
|
||||
std::vector<std::string> list{};
|
||||
while (result.has_row() && not stop_requested) {
|
||||
while (not stop_requested && result.has_row()) {
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
list.push_back(row->get_column("api_path").get_value<std::string>());
|
||||
|
@ -36,7 +36,7 @@
|
||||
#include "utils/time.hpp"
|
||||
|
||||
namespace repertory {
|
||||
void base_provider::add_all_items(const stop_type &stop_requested) {
|
||||
void base_provider::add_all_items(stop_type &stop_requested) {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
api_file_list list{};
|
||||
@ -437,7 +437,7 @@ auto base_provider::is_file_writeable(const std::string &api_path) const
|
||||
}
|
||||
|
||||
void base_provider::process_removed_directories(
|
||||
std::deque<removed_item> removed_list, const stop_type &stop_requested) {
|
||||
std::deque<removed_item> removed_list, stop_type &stop_requested) {
|
||||
for (const auto &item : removed_list) {
|
||||
if (stop_requested) {
|
||||
return;
|
||||
@ -454,7 +454,7 @@ void base_provider::process_removed_directories(
|
||||
}
|
||||
|
||||
void base_provider::process_removed_files(std::deque<removed_item> removed_list,
|
||||
const stop_type &stop_requested) {
|
||||
stop_type &stop_requested) {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto orphaned_directory =
|
||||
@ -513,7 +513,7 @@ void base_provider::process_removed_files(std::deque<removed_item> removed_list,
|
||||
}
|
||||
}
|
||||
|
||||
void base_provider::process_removed_items(const stop_type &stop_requested) {
|
||||
void base_provider::process_removed_items(stop_type &stop_requested) {
|
||||
db3_->enumerate_api_path_list(
|
||||
[this, &stop_requested](auto &&list) {
|
||||
[[maybe_unused]] auto res =
|
||||
@ -544,7 +544,7 @@ void base_provider::process_removed_items(const stop_type &stop_requested) {
|
||||
{
|
||||
removed_item{api_path, true, ""},
|
||||
},
|
||||
stop_requested2);
|
||||
task_stopped);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -572,7 +572,7 @@ void base_provider::process_removed_items(const stop_type &stop_requested) {
|
||||
stop_requested);
|
||||
}
|
||||
|
||||
void base_provider::remove_deleted_items(const stop_type &stop_requested) {
|
||||
void base_provider::remove_deleted_items(stop_type &stop_requested) {
|
||||
add_all_items(stop_requested);
|
||||
if (stop_requested) {
|
||||
return;
|
||||
@ -668,8 +668,7 @@ auto base_provider::remove_item_meta(const std::string &api_path,
|
||||
return db3_->remove_item_meta(api_path, key);
|
||||
}
|
||||
|
||||
void base_provider::remove_unmatched_source_files(
|
||||
const stop_type &stop_requested) {
|
||||
void base_provider::remove_unmatched_source_files(stop_type &stop_requested) {
|
||||
if (is_read_only()) {
|
||||
return;
|
||||
}
|
||||
|
@ -805,7 +805,7 @@ auto encrypt_provider::read_file_bytes(const std::string &api_path,
|
||||
return res == 0 ? api_error::os_error : api_error::success;
|
||||
}
|
||||
|
||||
void encrypt_provider::remove_deleted_files(const stop_type &stop_requested) {
|
||||
void encrypt_provider::remove_deleted_files(stop_type &stop_requested) {
|
||||
db_->enumerate_api_path_list(
|
||||
[this, &stop_requested](auto &&list) {
|
||||
std::vector<i_file_db::file_info> removed_list{};
|
||||
|
Reference in New Issue
Block a user