From 6da907910c50843129e0a5cc32dc63e3add543cb Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Mon, 9 Dec 2024 10:33:46 -0600 Subject: [PATCH] file mgr db unit tests and fixes --- .../librepertory/include/db/i_file_mgr_db.hpp | 35 ++++++------ .../librepertory/src/db/rdb_file_mgr_db.cpp | 53 +++++++++++++------ .../src/db/sqlite_file_mgr_db.cpp | 6 --- .../src/file_manager/file_manager.cpp | 14 ++--- 4 files changed, 60 insertions(+), 48 deletions(-) diff --git a/repertory/librepertory/include/db/i_file_mgr_db.hpp b/repertory/librepertory/include/db/i_file_mgr_db.hpp index 8cb06519..1e0e1354 100644 --- a/repertory/librepertory/include/db/i_file_mgr_db.hpp +++ b/repertory/librepertory/include/db/i_file_mgr_db.hpp @@ -43,7 +43,6 @@ public: struct upload_entry final { std::string api_path; - std::uint64_t date_time{}; std::string source_path; }; @@ -52,35 +51,35 @@ public: [[nodiscard]] virtual auto add_upload(upload_entry entry) -> bool = 0; - [[nodiscard]] virtual auto - add_upload_active(upload_active_entry entry) -> bool = 0; + [[nodiscard]] virtual auto add_upload_active(upload_active_entry entry) + -> bool = 0; virtual void clear() = 0; - [[nodiscard]] virtual auto - get_next_upload() const -> std::optional = 0; + [[nodiscard]] virtual auto get_next_upload() const + -> std::optional = 0; - [[nodiscard]] virtual auto - get_resume_list() const -> std::vector = 0; + [[nodiscard]] virtual auto get_resume_list() const + -> std::vector = 0; [[nodiscard]] virtual auto get_upload(const std::string &api_path) const -> std::optional = 0; - [[nodiscard]] virtual auto - get_upload_active_list() const -> std::vector = 0; + [[nodiscard]] virtual auto get_upload_active_list() const + -> std::vector = 0; - [[nodiscard]] virtual auto - remove_resume(const std::string &api_path) -> bool = 0; + [[nodiscard]] virtual auto remove_resume(const std::string &api_path) + -> bool = 0; - [[nodiscard]] virtual auto - remove_upload(const std::string &api_path) -> bool = 0; + [[nodiscard]] virtual auto remove_upload(const std::string &api_path) + -> bool = 0; - [[nodiscard]] virtual auto - remove_upload_active(const std::string &api_path) -> bool = 0; + [[nodiscard]] virtual auto remove_upload_active(const std::string &api_path) + -> bool = 0; - [[nodiscard]] virtual auto - rename_resume(const std::string &from_api_path, - const std::string &to_api_path) -> bool = 0; + [[nodiscard]] virtual auto rename_resume(const std::string &from_api_path, + const std::string &to_api_path) + -> bool = 0; }; } // namespace repertory diff --git a/repertory/librepertory/src/db/rdb_file_mgr_db.cpp b/repertory/librepertory/src/db/rdb_file_mgr_db.cpp index 0aef2713..a2f4e382 100644 --- a/repertory/librepertory/src/db/rdb_file_mgr_db.cpp +++ b/repertory/librepertory/src/db/rdb_file_mgr_db.cpp @@ -104,19 +104,21 @@ auto rdb_file_mgr_db::add_upload(upload_entry entry) -> bool { REPERTORY_USES_FUNCTION_NAME(); return perform_action(function_name, [this, &entry]() -> rocksdb::Status { - auto data = json({ - {"date_time", entry.date_time}, - {"source_path", entry.source_path}, - }); - return db_->Put(rocksdb::WriteOptions{}, upload_family_, - utils::string::zero_pad(std::to_string(++id_), 19U) + '|' + + utils::string::zero_pad(std::to_string(++id_), 20U) + '|' + entry.api_path, - data.dump()); + entry.source_path); }); } -auto rdb_file_mgr_db::add_upload_active(upload_active_entry entry) -> bool {} +auto rdb_file_mgr_db::add_upload_active(upload_active_entry entry) -> bool { + REPERTORY_USES_FUNCTION_NAME(); + + return perform_action(function_name, [this, &entry]() -> rocksdb::Status { + return db_->Put(rocksdb::WriteOptions{}, upload_active_family_, + entry.api_path, entry.source_path); + }); +} void rdb_file_mgr_db::clear() { create_or_open(true); } @@ -137,8 +139,7 @@ auto rdb_file_mgr_db::get_next_upload() const -> std::optional { auto data = json::parse(iter->value().ToString()); return upload_entry{ api_path, - data.at("date_time").get(), - data.at("source_path").get(), + iter->value().ToString(), }; } @@ -177,8 +178,7 @@ auto rdb_file_mgr_db::get_upload(const std::string &api_path) const auto data = json::parse(iter->value().ToString()); return upload_entry{ api_path, - data.at("date_time").get(), - data.at("source_path").get(), + iter->value().ToString(), }; } @@ -186,7 +186,19 @@ auto rdb_file_mgr_db::get_upload(const std::string &api_path) const } auto rdb_file_mgr_db::get_upload_active_list() const - -> std::vector {} + -> std::vector { + std::vector ret; + + auto iter = create_iterator(upload_active_family_); + for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { + ret.emplace_back(upload_active_entry{ + iter->key().ToString(), + iter->value().ToString(), + }); + } + + return ret; +} auto rdb_file_mgr_db::perform_action(std::string_view function_name, std::function action) @@ -203,7 +215,7 @@ auto rdb_file_mgr_db::remove_resume(const std::string &api_path) -> bool { REPERTORY_USES_FUNCTION_NAME(); return perform_action(function_name, [this, &api_path]() -> rocksdb::Status { - return db_->Delete(rocksdb::WriteOptions{}, api_path); + return db_->Delete(rocksdb::WriteOptions{}, resume_family_, api_path); }); } @@ -219,8 +231,8 @@ auto rdb_file_mgr_db::remove_upload(const std::string &api_path) -> bool { continue; } - return perform_action(function_name, []() -> rocksdb::Status { - return db_->Delete(rocksdb::WriteOptions{}, iter->key()); + return perform_action(function_name, [this, &iter]() -> rocksdb::Status { + return db_->Delete(rocksdb::WriteOptions{}, upload_family_, iter->key()); }); } @@ -228,7 +240,14 @@ auto rdb_file_mgr_db::remove_upload(const std::string &api_path) -> bool { } auto rdb_file_mgr_db::remove_upload_active(const std::string &api_path) - -> bool {} + -> bool { + REPERTORY_USES_FUNCTION_NAME(); + + return perform_action(function_name, [this, &api_path]() -> rocksdb::Status { + return db_->Delete(rocksdb::WriteOptions{}, upload_active_family_, + api_path); + }); +} auto rdb_file_mgr_db::rename_resume(const std::string &from_api_path, const std::string &to_api_path) -> bool { diff --git a/repertory/librepertory/src/db/sqlite_file_mgr_db.cpp b/repertory/librepertory/src/db/sqlite_file_mgr_db.cpp index b4e42190..15181e15 100644 --- a/repertory/librepertory/src/db/sqlite_file_mgr_db.cpp +++ b/repertory/librepertory/src/db/sqlite_file_mgr_db.cpp @@ -56,7 +56,6 @@ const std::map sql_create_tables{ "(" "id INTEGER PRIMARY KEY AUTOINCREMENT, " "api_path TEXT UNIQUE, " - "date_time INTEGER, " "source_path TEXT" ");", }, @@ -99,7 +98,6 @@ auto sqlite_file_mgr_db::add_upload(upload_entry entry) -> bool { return utils::db::sqlite::db_insert{*db_, upload_table} .or_replace() .column_value("api_path", entry.api_path) - .column_value("date_time", static_cast(entry.date_time)) .column_value("source_path", entry.source_path) .go() .ok(); @@ -152,8 +150,6 @@ auto sqlite_file_mgr_db::get_next_upload() const return upload_entry{ row->get_column("api_path").get_value(), - static_cast( - row->get_column("date_time").get_value()), row->get_column("source_path").get_value(), }; } @@ -202,8 +198,6 @@ auto sqlite_file_mgr_db::get_upload(const std::string &api_path) const return upload_entry{ row->get_column("api_path").get_value(), - static_cast( - row->get_column("date_time").get_value()), row->get_column("source_path").get_value(), }; } diff --git a/repertory/librepertory/src/file_manager/file_manager.cpp b/repertory/librepertory/src/file_manager/file_manager.cpp index 17ac8aad..823fce6c 100644 --- a/repertory/librepertory/src/file_manager/file_manager.cpp +++ b/repertory/librepertory/src/file_manager/file_manager.cpp @@ -361,10 +361,11 @@ auto file_manager::open(const std::string &api_path, bool directory, return open(api_path, directory, ofd, handle, file, nullptr); } -auto file_manager::open( - const std::string &api_path, bool directory, const open_file_data &ofd, - std::uint64_t &handle, std::shared_ptr &file, - std::shared_ptr closeable_file) -> api_error { +auto file_manager::open(const std::string &api_path, bool directory, + const open_file_data &ofd, std::uint64_t &handle, + std::shared_ptr &file, + std::shared_ptr closeable_file) + -> api_error { const auto create_and_add_handle = [&](std::shared_ptr cur_file) { handle = get_next_handle(); @@ -426,7 +427,6 @@ void file_manager::queue_upload(const std::string &api_path, if (mgr_db_->add_upload(i_file_mgr_db::upload_entry{ api_path, - utils::time::get_time_now(), source_path, })) { remove_resume(api_path, source_path); @@ -597,8 +597,8 @@ auto file_manager::rename_directory(const std::string &from_api_path, } auto file_manager::rename_file(const std::string &from_api_path, - const std::string &to_api_path, - bool overwrite) -> api_error { + const std::string &to_api_path, bool overwrite) + -> api_error { if (not provider_.is_rename_supported()) { return api_error::not_implemented; }