file db unit tests and fixes
This commit is contained in:
parent
c944039759
commit
2df67abffb
@ -91,14 +91,22 @@ auto rdb_file_db::add_directory(const std::string &api_path,
|
||||
const std::string &source_path) -> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
return perform_action(
|
||||
function_name, [&](rocksdb::Transaction *txn) -> rocksdb::Status {
|
||||
auto res = remove_item(api_path, source_path, txn);
|
||||
if (not res.ok() && not res.IsNotFound()) {
|
||||
std::string existing_source_path;
|
||||
auto res = get_directory_source_path(api_path, existing_source_path);
|
||||
if (res != api_error::success && res != api_error::directory_not_found) {
|
||||
return res;
|
||||
}
|
||||
|
||||
res = txn->Put(directory_family_, api_path, source_path);
|
||||
return perform_action(
|
||||
function_name, [&](rocksdb::Transaction *txn) -> rocksdb::Status {
|
||||
if (not existing_source_path.empty()) {
|
||||
auto res = remove_item(api_path, existing_source_path, txn);
|
||||
if (not res.ok() && not res.IsNotFound()) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
auto res = txn->Put(directory_family_, api_path, source_path);
|
||||
if (not res.ok()) {
|
||||
return res;
|
||||
}
|
||||
@ -111,12 +119,20 @@ auto rdb_file_db::add_or_update_file(const i_file_db::file_data &data)
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
std::string existing_source_path;
|
||||
auto res = get_file_source_path(data.api_path, existing_source_path);
|
||||
if (res != api_error::success && res != api_error::item_not_found) {
|
||||
return res;
|
||||
}
|
||||
|
||||
return perform_action(
|
||||
function_name, [&](rocksdb::Transaction *txn) -> rocksdb::Status {
|
||||
auto res = remove_item(data.api_path, data.source_path, txn);
|
||||
if (not existing_source_path.empty()) {
|
||||
auto res = remove_item(data.api_path, existing_source_path, txn);
|
||||
if (not res.ok() && not res.IsNotFound()) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
json json_data = {
|
||||
{"file_size", data.file_size},
|
||||
@ -124,7 +140,7 @@ auto rdb_file_db::add_or_update_file(const i_file_db::file_data &data)
|
||||
{"source_path", data.source_path},
|
||||
};
|
||||
|
||||
res = txn->Put(file_family_, data.api_path, json_data.dump());
|
||||
auto res = txn->Put(file_family_, data.api_path, json_data.dump());
|
||||
if (not res.ok()) {
|
||||
return res;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user