[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-29 09:16:37 -05:00
parent 44a1547d2e
commit 1b1fc0fc09
2 changed files with 21 additions and 19 deletions

View File

@ -158,9 +158,10 @@ void file_manager::close_all(const std::string &api_path) {
auto closeable_file = file_iter->second; auto closeable_file = file_iter->second;
handles = closeable_file->get_handles(); handles = closeable_file->get_handles();
for (auto handle : handles) { for (auto &&handle : handles) {
closeable_file->remove(handle); closeable_file->remove(handle);
} }
open_file_lookup_.erase(api_path);
} }
void file_manager::close_timed_out_files() { void file_manager::close_timed_out_files() {
@ -383,7 +384,6 @@ 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();
} }
@ -415,13 +415,17 @@ auto file_manager::handle_file_rename(const std::string &from_api_path,
return ret; return ret;
} }
swap_renamed_items(from_api_path, to_api_path);
ret = source_path.empty()
? api_error::success
: provider_.set_item_meta(to_api_path, META_SOURCE, source_path);
if (should_upload) { if (should_upload) {
queue_upload(to_api_path, source_path, false); queue_upload(to_api_path, source_path, false);
} }
return source_path.empty() return ret;
? 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 {
@ -556,9 +560,16 @@ auto file_manager::remove_file(const std::string &api_path) -> api_error {
return res; return res;
} }
remove_upload(api_path);
close_all(api_path); close_all(api_path);
remove_upload(api_path);
auto result = db::db_select{*db_.get(), resume_table}
.delete_query()
.where("api_path")
.equals(api_path)
.go();
res = provider_.remove_file(api_path); res = provider_.remove_file(api_path);
if (res != api_error::success) { if (res != api_error::success) {
return res; return res;
@ -613,9 +624,8 @@ void file_manager::remove_upload(const std::string &api_path, bool no_lock) {
.go(); .go();
if (upload_lookup_.find(api_path) != upload_lookup_.end()) { if (upload_lookup_.find(api_path) != upload_lookup_.end()) {
auto ptr = std::move(upload_lookup_.at(api_path)); upload_lookup_.at(api_path)->cancel();
upload_lookup_.erase(api_path); upload_lookup_.erase(api_path);
ptr->cancel();
} }
if (result.ok()) { if (result.ok()) {
@ -706,10 +716,6 @@ auto file_manager::rename_directory(const std::string &from_api_path,
auto file_manager::rename_file(const std::string &from_api_path, auto file_manager::rename_file(const std::string &from_api_path,
const std::string &to_api_path, const std::string &to_api_path,
bool overwrite) -> api_error { bool overwrite) -> api_error {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
};
if (not provider_.is_rename_supported()) { if (not provider_.is_rename_supported()) {
return api_error::not_implemented; return api_error::not_implemented;
} }
@ -962,9 +968,10 @@ void file_manager::swap_renamed_items(std::string from_api_path,
std::string to_api_path) { std::string to_api_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()) {
open_file_lookup_[to_api_path] = open_file_lookup_[from_api_path]; auto ptr = std::move(open_file_lookup_[from_api_path]);
open_file_lookup_.erase(from_api_path); open_file_lookup_.erase(from_api_path);
open_file_lookup_[to_api_path]->set_api_path(to_api_path); ptr->set_api_path(to_api_path);
open_file_lookup_[to_api_path] = ptr;
} }
} }

View File

@ -748,11 +748,6 @@ auto base_provider::upload_file(const std::string &api_path,
}; };
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");