diff --git a/repertory/librepertory/src/file_manager/file_manager.cpp b/repertory/librepertory/src/file_manager/file_manager.cpp index 5bc40e6c..c4b09a6c 100644 --- a/repertory/librepertory/src/file_manager/file_manager.cpp +++ b/repertory/librepertory/src/file_manager/file_manager.cpp @@ -384,14 +384,15 @@ 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(); } if (not should_upload) { should_upload = upload_lookup_.contains(from_api_path); if (should_upload) { - source_path = upload_lookup_.at(from_api_path)->get_source_path(); + if (source_path.empty()) { + source_path = upload_lookup_.at(from_api_path)->get_source_path(); + } } else { auto result = db::db_select{*db_.get(), upload_table} .column("source_path") @@ -400,7 +401,7 @@ auto file_manager::handle_file_rename(const std::string &from_api_path, .go(); std::optional row; 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(); } } @@ -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); - if (ret == api_error::success) { - swap_renamed_items(from_api_path, to_api_path); + if (ret != api_error::success) { + queue_upload(from_api_path, source_path, false); + return ret; } + swap_renamed_items(from_api_path, to_api_path); + if (should_upload) { 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 { @@ -598,35 +604,22 @@ void file_manager::remove_upload(const std::string &api_path, bool no_lock) { lock = std::make_unique(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(api_path); - } - } else { - auto result = db::db_select{*db_.get(), upload_active_table} - .delete_query() - .where("api_path") - .equals(api_path) - .go(); - if (result.ok()) { - event_system::instance().raise(api_path); - } + auto result = db::db_select{*db_.get(), upload_active_table} + .delete_query() + .where("api_path") + .equals(api_path) + .go(); + auto file_iter = upload_lookup_.find(api_path); + if (file_iter != upload_lookup_.end()) { file_iter->second->cancel(); upload_lookup_.erase(api_path); } + if (result.ok()) { + event_system::instance().raise(api_path); + } + if (not no_lock) { upload_notify_.notify_all(); } diff --git a/repertory/librepertory/src/providers/base_provider.cpp b/repertory/librepertory/src/providers/base_provider.cpp index 3c5e1adb..61b30016 100644 --- a/repertory/librepertory/src/providers/base_provider.cpp +++ b/repertory/librepertory/src/providers/base_provider.cpp @@ -746,7 +746,13 @@ auto base_provider::upload_file(const std::string &api_path, error); return error; }; + 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");