From cbfa64556a9644a48f64acaa3a83532be18b26ab Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 16 Sep 2025 06:56:12 -0500 Subject: [PATCH] Pinning a file should automatically initiate a download to cache #38 --- .../librepertory/src/db/impl/rdb_meta_db.cpp | 12 ++++++--- .../src/db/impl/sqlite_meta_db.cpp | 11 +++++--- .../src/file_manager/file_manager.cpp | 25 ++++++++++++++----- .../src/providers/base_provider.cpp | 7 ++++-- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/repertory/librepertory/src/db/impl/rdb_meta_db.cpp b/repertory/librepertory/src/db/impl/rdb_meta_db.cpp index 538f3d90..7598ccf1 100644 --- a/repertory/librepertory/src/db/impl/rdb_meta_db.cpp +++ b/repertory/librepertory/src/db/impl/rdb_meta_db.cpp @@ -318,9 +318,10 @@ void rdb_meta_db::remove_api_path(const std::string &api_path) { } } -auto rdb_meta_db::remove_api_path( - const std::string &api_path, const std::string &source_path, - rocksdb::Transaction *txn) -> rocksdb::Status { +auto rdb_meta_db::remove_api_path(const std::string &api_path, + const std::string &source_path, + rocksdb::Transaction *txn) + -> rocksdb::Status { auto txn_res = txn->Delete(pinned_family_, api_path); if (not txn_res.ok()) { return txn_res; @@ -345,7 +346,10 @@ auto rdb_meta_db::remove_item_meta(const std::string &api_path, const std::string &key) -> api_error { if (key == META_DIRECTORY || key == META_PINNED || key == META_SIZE || key == META_SOURCE) { - // TODO log warning for unsupported attributes + utils::error::raise_api_path_error( + function_name, api_path, + fmt::format("failed to remove item meta-key is restricted|key|{}", + key)); return api_error::success; } diff --git a/repertory/librepertory/src/db/impl/sqlite_meta_db.cpp b/repertory/librepertory/src/db/impl/sqlite_meta_db.cpp index 3bf829a7..aa292fe7 100644 --- a/repertory/librepertory/src/db/impl/sqlite_meta_db.cpp +++ b/repertory/librepertory/src/db/impl/sqlite_meta_db.cpp @@ -307,7 +307,10 @@ auto sqlite_meta_db::remove_item_meta(const std::string &api_path, const std::string &key) -> api_error { if (key == META_DIRECTORY || key == META_PINNED || key == META_SIZE || key == META_SOURCE) { - // TODO log warning for unsupported attributes + utils::error::raise_api_path_error( + function_name, api_path, + fmt::format("failed to remove item meta-key is restricted|key|{}", + key)); return api_error::success; } @@ -343,8 +346,10 @@ auto sqlite_meta_db::set_item_meta(const std::string &api_path, auto sqlite_meta_db::set_item_meta(const std::string &api_path, const api_meta_map &meta) -> api_error { api_meta_map existing_meta{}; - if (get_item_meta(api_path, existing_meta) != api_error::success) { - // TODO handle error + auto res = get_item_meta(api_path, existing_meta); + if (res != api_error::success) { + utils::error::raise_api_path_error(function_name, api_path, res, + "failed to get item meta"); } for (const auto &item : meta) { diff --git a/repertory/librepertory/src/file_manager/file_manager.cpp b/repertory/librepertory/src/file_manager/file_manager.cpp index 1d62c060..ab4c5b18 100644 --- a/repertory/librepertory/src/file_manager/file_manager.cpp +++ b/repertory/librepertory/src/file_manager/file_manager.cpp @@ -158,18 +158,27 @@ auto file_manager::download_pinned_file(const std::string &api_path) -> bool { try { if (provider_.is_read_only()) { - // TODO handle error + utils::error::raise_api_path_error( + function_name, api_path, + fmt::format( + "failed to download pinned file-provider is " + "read-only|type|{}", + app_config::get_provider_name(provider_.get_provider_type()))); return false; } std::string str_pinned; auto res = provider_.get_item_meta(api_path, META_PINNED, str_pinned); if (res != api_error::success) { - // TODO handle error + utils::error::raise_api_path_error( + function_name, api_path, res, + "failed to get item meta|key|META_PINNED"); return false; } if (not utils::string::to_bool(str_pinned)) { - // TODO handle error + utils::error::raise_api_path_error( + function_name, api_path, + "failed to download pinned file-file is not pinned"); return false; } @@ -177,17 +186,21 @@ auto file_manager::download_pinned_file(const std::string &api_path) -> bool { std::shared_ptr open_file; res = open(api_path, false, {}, handle, open_file); if (res != api_error::success) { - // TODO handle error + utils::error::raise_api_path_error( + function_name, api_path, res, + "failed to download pinned file-file open failed"); return false; } auto ret = get_open_file(handle, true, open_file); if (ret) { open_file->force_download(); + } else { + utils::error::raise_api_path_error( + function_name, api_path, + "failed to download pinned file-file open as writeable failed"); } - // TODO handle error (ret == false) - close(handle); return ret; } catch (const std::exception &ex) { diff --git a/repertory/librepertory/src/providers/base_provider.cpp b/repertory/librepertory/src/providers/base_provider.cpp index 90546250..a207ff6e 100644 --- a/repertory/librepertory/src/providers/base_provider.cpp +++ b/repertory/librepertory/src/providers/base_provider.cpp @@ -838,7 +838,8 @@ auto base_provider::set_item_meta(const std::string &api_path, if (key == META_PINNED && utils::string::to_bool(value)) { if (fm_ == nullptr || not fm_->download_pinned_file(api_path)) { - // TODO handle error + utils::error::raise_api_path_error(function_name, api_path, + "failed to pin file"); } } @@ -847,6 +848,7 @@ auto base_provider::set_item_meta(const std::string &api_path, auto base_provider::set_item_meta(const std::string &api_path, api_meta_map meta) -> api_error { + REPERTORY_USES_FUNCTION_NAME(); auto ret = meta_db_->set_item_meta(api_path, meta); if (ret != api_error::success) { @@ -856,7 +858,8 @@ auto base_provider::set_item_meta(const std::string &api_path, if (meta.contains(META_PINNED) && utils::string::to_bool(meta.at(META_PINNED))) { if (fm_ == nullptr || not fm_->download_pinned_file(api_path)) { - // TODO handle error + utils::error::raise_api_path_error(function_name, api_path, + "failed to pin file"); } }