From 4b32664e46e4b32f7ebf19fd1c1200f8b5525040 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 4 Dec 2024 14:53:01 -0600 Subject: [PATCH] meta db unit tests and fixes --- repertory/librepertory/src/db/rdb_meta_db.cpp | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/repertory/librepertory/src/db/rdb_meta_db.cpp b/repertory/librepertory/src/db/rdb_meta_db.cpp index c2f59c13..59a1345a 100644 --- a/repertory/librepertory/src/db/rdb_meta_db.cpp +++ b/repertory/librepertory/src/db/rdb_meta_db.cpp @@ -357,12 +357,6 @@ auto rdb_meta_db::update_item_meta(const std::string &api_path, json json_data) REPERTORY_USES_FUNCTION_NAME(); try { - std::string orig_source_path; - auto ret = get_item_meta(api_path, META_SOURCE, orig_source_path); - if (ret != api_error::success && ret != api_error::item_not_found) { - return ret; - } - if (not json_data.contains(META_PINNED)) { json_data[META_PINNED] = utils::string::from_bool(false); } @@ -375,6 +369,7 @@ auto rdb_meta_db::update_item_meta(const std::string &api_path, json json_data) auto directory = utils::string::to_bool(json_data.at(META_DIRECTORY).get()); + auto pinned = directory ? false : utils::string::to_bool( json_data.at(META_PINNED).get()); @@ -383,13 +378,22 @@ auto rdb_meta_db::update_item_meta(const std::string &api_path, json json_data) json_data.at(META_SIZE).get()); auto source_path = directory ? "" : json_data.at(META_SOURCE).get(); - if (orig_source_path != source_path && not orig_source_path.empty()) { - ret = perform_action(function_name, [&]() -> rocksdb::Status { - return db_->Delete(rocksdb::WriteOptions(), source_family_, - orig_source_path); - }); - if (ret != api_error::success && ret != api_error::item_not_found) { - return ret; + + if (not directory) { + std::string orig_source_path; + auto res = get_item_meta(api_path, META_SOURCE, orig_source_path); + if (res != api_error::success && res != api_error::item_not_found) { + return res; + } + + if (not orig_source_path.empty() && orig_source_path != source_path) { + res = perform_action(function_name, [&]() -> rocksdb::Status { + return db_->Delete(rocksdb::WriteOptions(), source_family_, + orig_source_path); + }); + if (res != api_error::success && res != api_error::item_not_found) { + return res; + } } }