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( auto rdb_meta_db::remove_api_path(const std::string &api_path,
const std::string &api_path, const std::string &source_path, const std::string &source_path,
rocksdb::Transaction *txn) -> rocksdb::Status { rocksdb::Transaction *txn)
-> rocksdb::Status {
auto txn_res = txn->Delete(pinned_family_, api_path); auto txn_res = txn->Delete(pinned_family_, api_path);
if (not txn_res.ok()) { if (not txn_res.ok()) {
return txn_res; 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 { const std::string &key) -> api_error {
if (key == META_DIRECTORY || key == META_PINNED || key == META_SIZE || if (key == META_DIRECTORY || key == META_PINNED || key == META_SIZE ||
key == META_SOURCE) { 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; 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 { const std::string &key) -> api_error {
if (key == META_DIRECTORY || key == META_PINNED || key == META_SIZE || if (key == META_DIRECTORY || key == META_PINNED || key == META_SIZE ||
key == META_SOURCE) { 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; 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, auto sqlite_meta_db::set_item_meta(const std::string &api_path,
const api_meta_map &meta) -> api_error { const api_meta_map &meta) -> api_error {
api_meta_map existing_meta{}; api_meta_map existing_meta{};
if (get_item_meta(api_path, existing_meta) != api_error::success) { auto res = get_item_meta(api_path, existing_meta);
// TODO handle error 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) { for (const auto &item : meta) {

View File

@@ -158,18 +158,27 @@ auto file_manager::download_pinned_file(const std::string &api_path) -> bool {
try { try {
if (provider_.is_read_only()) { 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; return false;
} }
std::string str_pinned; std::string str_pinned;
auto res = provider_.get_item_meta(api_path, META_PINNED, str_pinned); auto res = provider_.get_item_meta(api_path, META_PINNED, str_pinned);
if (res != api_error::success) { 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; return false;
} }
if (not utils::string::to_bool(str_pinned)) { 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; 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; std::shared_ptr<i_open_file> open_file;
res = open(api_path, false, {}, handle, open_file); res = open(api_path, false, {}, handle, open_file);
if (res != api_error::success) { 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; return false;
} }
auto ret = get_open_file(handle, true, open_file); auto ret = get_open_file(handle, true, open_file);
if (ret) { if (ret) {
open_file->force_download(); 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); close(handle);
return ret; return ret;
} catch (const std::exception &ex) { } 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 (key == META_PINNED && utils::string::to_bool(value)) {
if (fm_ == nullptr || not fm_->download_pinned_file(api_path)) { 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, auto base_provider::set_item_meta(const std::string &api_path,
api_meta_map meta) -> api_error { api_meta_map meta) -> api_error {
REPERTORY_USES_FUNCTION_NAME();
auto ret = meta_db_->set_item_meta(api_path, meta); auto ret = meta_db_->set_item_meta(api_path, meta);
if (ret != api_error::success) { 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) && if (meta.contains(META_PINNED) &&
utils::string::to_bool(meta.at(META_PINNED))) { utils::string::to_bool(meta.at(META_PINNED))) {
if (fm_ == nullptr || not fm_->download_pinned_file(api_path)) { 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");
} }
} }