From 743281497ce680038cbadb6492ee7050d4466b6d Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Thu, 2 Jan 2025 14:14:21 -0600 Subject: [PATCH] refactor --- .../librepertory/include/db/i_file_db.hpp | 5 ++--- .../librepertory/include/db/i_meta_db.hpp | 2 +- .../include/db/impl/rdb_file_db.hpp | 4 ++-- .../include/db/impl/rdb_meta_db.hpp | 2 +- .../include/db/impl/sqlite_file_db.hpp | 4 ++-- .../include/db/impl/sqlite_meta_db.hpp | 2 +- .../include/providers/base_provider.hpp | 12 +++++----- .../providers/encrypt/encrypt_provider.hpp | 2 +- .../librepertory/include/utils/polling.hpp | 2 +- .../librepertory/include/utils/tasks.hpp | 2 +- .../librepertory/src/db/impl/rdb_file_db.cpp | 22 +++++-------------- .../librepertory/src/db/impl/rdb_meta_db.cpp | 2 +- .../src/db/impl/sqlite_file_db.cpp | 8 +++---- .../src/db/impl/sqlite_meta_db.cpp | 4 ++-- .../src/providers/base_provider.cpp | 15 ++++++------- .../providers/encrypt/encrypt_provider.cpp | 2 +- 16 files changed, 39 insertions(+), 51 deletions(-) diff --git a/repertory/librepertory/include/db/i_file_db.hpp b/repertory/librepertory/include/db/i_file_db.hpp index e1779ce9..61fe7524 100644 --- a/repertory/librepertory/include/db/i_file_db.hpp +++ b/repertory/librepertory/include/db/i_file_db.hpp @@ -58,7 +58,7 @@ public: virtual void enumerate_api_path_list( std::function &)> 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 = 0; [[nodiscard]] virtual auto get_source_path(const std::string &api_path, diff --git a/repertory/librepertory/include/db/i_meta_db.hpp b/repertory/librepertory/include/db/i_meta_db.hpp index 2f6f0da8..7379577d 100644 --- a/repertory/librepertory/include/db/i_meta_db.hpp +++ b/repertory/librepertory/include/db/i_meta_db.hpp @@ -33,7 +33,7 @@ public: virtual void enumerate_api_path_list( std::function &)> 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 diff --git a/repertory/librepertory/include/db/impl/rdb_file_db.hpp b/repertory/librepertory/include/db/impl/rdb_file_db.hpp index e9955db3..b90c2d02 100644 --- a/repertory/librepertory/include/db/impl/rdb_file_db.hpp +++ b/repertory/librepertory/include/db/impl/rdb_file_db.hpp @@ -80,7 +80,7 @@ public: void enumerate_api_path_list( std::function &)> 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 override; [[nodiscard]] auto get_source_path(const std::string &api_path, diff --git a/repertory/librepertory/include/db/impl/rdb_meta_db.hpp b/repertory/librepertory/include/db/impl/rdb_meta_db.hpp index 83dc7b95..b18696cf 100644 --- a/repertory/librepertory/include/db/impl/rdb_meta_db.hpp +++ b/repertory/librepertory/include/db/impl/rdb_meta_db.hpp @@ -82,7 +82,7 @@ public: void enumerate_api_path_list( std::function &)> 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 diff --git a/repertory/librepertory/include/db/impl/sqlite_file_db.hpp b/repertory/librepertory/include/db/impl/sqlite_file_db.hpp index 8e6d2c30..4aa29f61 100644 --- a/repertory/librepertory/include/db/impl/sqlite_file_db.hpp +++ b/repertory/librepertory/include/db/impl/sqlite_file_db.hpp @@ -55,7 +55,7 @@ public: void enumerate_api_path_list( std::function &)> 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 override; [[nodiscard]] auto get_source_path(const std::string &api_path, diff --git a/repertory/librepertory/include/db/impl/sqlite_meta_db.hpp b/repertory/librepertory/include/db/impl/sqlite_meta_db.hpp index c895d20f..4857ce8b 100644 --- a/repertory/librepertory/include/db/impl/sqlite_meta_db.hpp +++ b/repertory/librepertory/include/db/impl/sqlite_meta_db.hpp @@ -52,7 +52,7 @@ public: void enumerate_api_path_list( std::function &)> 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 diff --git a/repertory/librepertory/include/providers/base_provider.hpp b/repertory/librepertory/include/providers/base_provider.hpp index be0d7339..292e4a58 100644 --- a/repertory/librepertory/include/providers/base_provider.hpp +++ b/repertory/librepertory/include/providers/base_provider.hpp @@ -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_list, - const stop_type &stop_requested); + stop_type &stop_requested); void process_removed_files(std::deque 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, diff --git a/repertory/librepertory/include/providers/encrypt/encrypt_provider.hpp b/repertory/librepertory/include/providers/encrypt/encrypt_provider.hpp index cb053709..db4b4a3e 100644 --- a/repertory/librepertory/include/providers/encrypt/encrypt_provider.hpp +++ b/repertory/librepertory/include/providers/encrypt/encrypt_provider.hpp @@ -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, diff --git a/repertory/librepertory/include/utils/polling.hpp b/repertory/librepertory/include/utils/polling.hpp index 1af1b895..fcfd3cd8 100644 --- a/repertory/librepertory/include/utils/polling.hpp +++ b/repertory/librepertory/include/utils/polling.hpp @@ -40,7 +40,7 @@ public: struct polling_item final { std::string name; frequency freq; - std::function action; + std::function action; }; public: diff --git a/repertory/librepertory/include/utils/tasks.hpp b/repertory/librepertory/include/utils/tasks.hpp index 12429589..d39f5778 100644 --- a/repertory/librepertory/include/utils/tasks.hpp +++ b/repertory/librepertory/include/utils/tasks.hpp @@ -30,7 +30,7 @@ class app_config; class tasks final { public: struct task final { - std::function action; + std::function action; }; class i_task { diff --git a/repertory/librepertory/src/db/impl/rdb_file_db.cpp b/repertory/librepertory/src/db/impl/rdb_file_db.cpp index c521386a..e1bc99cf 100644 --- a/repertory/librepertory/src/db/impl/rdb_file_db.cpp +++ b/repertory/librepertory/src/db/impl/rdb_file_db.cpp @@ -151,16 +151,12 @@ auto rdb_file_db::count() const -> std::uint64_t { void rdb_file_db::enumerate_api_path_list( std::function &)> callback, - const stop_type &stop_requested) const { + stop_type &stop_requested) const { std::vector 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 { std::vector 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(), diff --git a/repertory/librepertory/src/db/impl/rdb_meta_db.cpp b/repertory/librepertory/src/db/impl/rdb_meta_db.cpp index 74f83fe9..3e517ba2 100644 --- a/repertory/librepertory/src/db/impl/rdb_meta_db.cpp +++ b/repertory/librepertory/src/db/impl/rdb_meta_db.cpp @@ -66,7 +66,7 @@ auto rdb_meta_db::create_iterator(rocksdb::ColumnFamilyHandle *family) const void rdb_meta_db::enumerate_api_path_list( std::function &)> callback, - const stop_type &stop_requested) const { + stop_type &stop_requested) const { std::vector list{}; auto iter = create_iterator(meta_family_); diff --git a/repertory/librepertory/src/db/impl/sqlite_file_db.cpp b/repertory/librepertory/src/db/impl/sqlite_file_db.cpp index bbbe7891..cadc2055 100644 --- a/repertory/librepertory/src/db/impl/sqlite_file_db.cpp +++ b/repertory/librepertory/src/db/impl/sqlite_file_db.cpp @@ -135,11 +135,11 @@ auto sqlite_file_db::count() const -> std::uint64_t { void sqlite_file_db::enumerate_api_path_list( std::function &)> callback, - const stop_type &stop_requested) const { + stop_type &stop_requested) const { std::vector 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 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 { std::vector 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 row; if (result.get_row(row) && row.has_value()) { ret.emplace_back(i_file_db::file_info{ diff --git a/repertory/librepertory/src/db/impl/sqlite_meta_db.cpp b/repertory/librepertory/src/db/impl/sqlite_meta_db.cpp index e26c3937..f0000bcf 100644 --- a/repertory/librepertory/src/db/impl/sqlite_meta_db.cpp +++ b/repertory/librepertory/src/db/impl/sqlite_meta_db.cpp @@ -77,12 +77,12 @@ void sqlite_meta_db::clear() { void sqlite_meta_db::enumerate_api_path_list( std::function &)> 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 list{}; - while (result.has_row() && not stop_requested) { + while (not stop_requested && result.has_row()) { std::optional row; if (result.get_row(row) && row.has_value()) { list.push_back(row->get_column("api_path").get_value()); diff --git a/repertory/librepertory/src/providers/base_provider.cpp b/repertory/librepertory/src/providers/base_provider.cpp index 8e3fe622..3589655b 100644 --- a/repertory/librepertory/src/providers/base_provider.cpp +++ b/repertory/librepertory/src/providers/base_provider.cpp @@ -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_list, const stop_type &stop_requested) { + std::deque 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_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_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; } diff --git a/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp b/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp index cc6a4156..f4c00a5d 100644 --- a/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp +++ b/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp @@ -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 removed_list{};