diff --git a/repertory/librepertory/src/file_manager/file_manager.cpp b/repertory/librepertory/src/file_manager/file_manager.cpp index a6c25a61..2154050a 100644 --- a/repertory/librepertory/src/file_manager/file_manager.cpp +++ b/repertory/librepertory/src/file_manager/file_manager.cpp @@ -158,9 +158,10 @@ void file_manager::close_all(const std::string &api_path) { auto closeable_file = file_iter->second; handles = closeable_file->get_handles(); - for (auto handle : handles) { + for (auto &&handle : handles) { closeable_file->remove(handle); } + open_file_lookup_.erase(api_path); } 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{}; auto file_iter = open_file_lookup_.find(from_api_path); if (file_iter != open_file_lookup_.end()) { - should_upload = file_iter->second->is_modified(); 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; } + 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) { queue_upload(to_api_path, source_path, false); } - return source_path.empty() - ? api_error::success - : provider_.set_item_meta(to_api_path, META_SOURCE, source_path); + return ret; } 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; } - remove_upload(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); if (res != api_error::success) { return res; @@ -613,9 +624,8 @@ void file_manager::remove_upload(const std::string &api_path, bool no_lock) { .go(); 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); - ptr->cancel(); } 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, const std::string &to_api_path, bool overwrite) -> api_error { - static constexpr const std::string_view function_name{ - static_cast(__FUNCTION__), - }; - if (not provider_.is_rename_supported()) { 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) { auto file_iter = open_file_lookup_.find(from_api_path); 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_[to_api_path]->set_api_path(to_api_path); + ptr->set_api_path(to_api_path); + open_file_lookup_[to_api_path] = ptr; } } diff --git a/repertory/librepertory/src/providers/base_provider.cpp b/repertory/librepertory/src/providers/base_provider.cpp index 61b30016..2f69328a 100644 --- a/repertory/librepertory/src/providers/base_provider.cpp +++ b/repertory/librepertory/src/providers/base_provider.cpp @@ -748,11 +748,6 @@ auto base_provider::upload_file(const std::string &api_path, }; 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)); } catch (const std::exception &e) { utils::error::raise_error(function_name, e, "exception occurred");