[bug] Rename file is broken for files that are existing #19
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2024-09-28 13:16:37 -05:00
parent 113b5e7258
commit a58fcc7f14
2 changed files with 29 additions and 30 deletions

View File

@ -384,14 +384,15 @@ auto file_manager::handle_file_rename(const std::string &from_api_path,
std::string source_path{}; std::string source_path{};
auto file_iter = open_file_lookup_.find(from_api_path); auto file_iter = open_file_lookup_.find(from_api_path);
if (file_iter != open_file_lookup_.end()) { if (file_iter != open_file_lookup_.end()) {
should_upload = file_iter->second->is_modified();
source_path = file_iter->second->get_source_path(); source_path = file_iter->second->get_source_path();
} }
if (not should_upload) { if (not should_upload) {
should_upload = upload_lookup_.contains(from_api_path); should_upload = upload_lookup_.contains(from_api_path);
if (should_upload) { if (should_upload) {
if (source_path.empty()) {
source_path = upload_lookup_.at(from_api_path)->get_source_path(); source_path = upload_lookup_.at(from_api_path)->get_source_path();
}
} else { } else {
auto result = db::db_select{*db_.get(), upload_table} auto result = db::db_select{*db_.get(), upload_table}
.column("source_path") .column("source_path")
@ -400,7 +401,7 @@ auto file_manager::handle_file_rename(const std::string &from_api_path,
.go(); .go();
std::optional<db::db_select::row> row; std::optional<db::db_select::row> row;
should_upload = result.get_row(row) && row.has_value(); should_upload = result.get_row(row) && row.has_value();
if (should_upload) { if (should_upload && source_path.empty()) {
source_path = row->get_column("source_path").get_value<std::string>(); source_path = row->get_column("source_path").get_value<std::string>();
} }
} }
@ -411,15 +412,20 @@ auto file_manager::handle_file_rename(const std::string &from_api_path,
} }
auto ret = provider_.rename_file(from_api_path, to_api_path); auto ret = provider_.rename_file(from_api_path, to_api_path);
if (ret == api_error::success) { if (ret != api_error::success) {
swap_renamed_items(from_api_path, to_api_path); queue_upload(from_api_path, source_path, false);
return ret;
} }
swap_renamed_items(from_api_path, to_api_path);
if (should_upload) { if (should_upload) {
queue_upload(to_api_path, source_path, false); queue_upload(to_api_path, source_path, false);
} }
return ret; return source_path.empty()
? api_error::success
: provider_.set_item_meta(to_api_path, META_SOURCE, source_path);
} }
auto file_manager::has_no_open_file_handles() const -> bool { auto file_manager::has_no_open_file_handles() const -> bool {
@ -598,35 +604,22 @@ void file_manager::remove_upload(const std::string &api_path, bool no_lock) {
lock = std::make_unique<mutex_lock>(upload_mtx_); lock = std::make_unique<mutex_lock>(upload_mtx_);
} }
auto file_iter = upload_lookup_.find(api_path);
if (file_iter == upload_lookup_.end()) {
auto result = db::db_select{*db_.get(), upload_table}
.delete_query()
.where("api_path")
.equals(api_path)
.go();
if (result.ok()) {
result = db::db_select{*db_.get(), upload_active_table}
.delete_query()
.where("api_path")
.equals(api_path)
.go();
event_system::instance().raise<file_upload_removed>(api_path);
}
} else {
auto result = db::db_select{*db_.get(), upload_active_table} auto result = db::db_select{*db_.get(), upload_active_table}
.delete_query() .delete_query()
.where("api_path") .where("api_path")
.equals(api_path) .equals(api_path)
.go(); .go();
if (result.ok()) {
event_system::instance().raise<file_upload_removed>(api_path);
}
auto file_iter = upload_lookup_.find(api_path);
if (file_iter != upload_lookup_.end()) {
file_iter->second->cancel(); file_iter->second->cancel();
upload_lookup_.erase(api_path); upload_lookup_.erase(api_path);
} }
if (result.ok()) {
event_system::instance().raise<file_upload_removed>(api_path);
}
if (not no_lock) { if (not no_lock) {
upload_notify_.notify_all(); upload_notify_.notify_all();
} }

View File

@ -746,7 +746,13 @@ auto base_provider::upload_file(const std::string &api_path,
error); error);
return error; return error;
}; };
try { try {
auto res = set_item_meta(api_path, META_SOURCE, source_path);
if (res != api_error::success) {
return notify_end(res);
}
return notify_end(upload_file_impl(api_path, source_path, stop_requested)); return notify_end(upload_file_impl(api_path, source_path, stop_requested));
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::raise_error(function_name, e, "exception occurred"); utils::error::raise_error(function_name, e, "exception occurred");