Pinning a file should automatically initiate a download to cache #38
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
Blockstorage/repertory/pipeline/head There was a failure building this commit

This commit is contained in:
2025-09-16 06:56:12 -05:00
parent 5583d3f493
commit cbfa64556a
4 changed files with 40 additions and 15 deletions

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -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<i_open_file> 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) {

View File

@@ -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");
}
}