From 8128ac09b355a2a12d4d1e17530a97a20095abdf Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 10 Dec 2024 11:08:37 -0600 Subject: [PATCH] file manager fixes --- .../include/file_manager/file_manager.hpp | 21 ++++++++------- .../include/file_manager/i_upload_manager.hpp | 4 +-- .../src/file_manager/file_manager.cpp | 26 +++++++++++++++---- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/repertory/librepertory/include/file_manager/file_manager.hpp b/repertory/librepertory/include/file_manager/file_manager.hpp index 3abde31e..85a28570 100644 --- a/repertory/librepertory/include/file_manager/file_manager.hpp +++ b/repertory/librepertory/include/file_manager/file_manager.hpp @@ -85,6 +85,9 @@ private: void queue_upload(const std::string &api_path, const std::string &source_path, bool no_lock); + void remove_resume(const std::string &api_path, + const std::string &source_path, bool no_lock); + void remove_upload(const std::string &api_path, bool no_lock); void swap_renamed_items(std::string from_api_path, std::string to_api_path, @@ -131,13 +134,13 @@ public: [[nodiscard]] auto get_open_handle_count() const -> std::size_t; - [[nodiscard]] auto - get_stored_downloads() const -> std::vector; + [[nodiscard]] auto get_stored_downloads() const + -> std::vector; [[nodiscard]] auto has_no_open_file_handles() const -> bool override; - [[nodiscard]] auto - is_processing(const std::string &api_path) const -> bool override; + [[nodiscard]] auto is_processing(const std::string &api_path) const + -> bool override; #if defined(PROJECT_TESTING) [[nodiscard]] auto open(std::shared_ptr of, @@ -150,13 +153,13 @@ public: [[nodiscard]] auto remove_file(const std::string &api_path) -> api_error; - [[nodiscard]] auto - rename_directory(const std::string &from_api_path, - const std::string &to_api_path) -> api_error; + [[nodiscard]] auto rename_directory(const std::string &from_api_path, + const std::string &to_api_path) + -> api_error; [[nodiscard]] auto rename_file(const std::string &from_api_path, - const std::string &to_api_path, - bool overwrite) -> api_error; + const std::string &to_api_path, bool overwrite) + -> api_error; void start(); diff --git a/repertory/librepertory/include/file_manager/i_upload_manager.hpp b/repertory/librepertory/include/file_manager/i_upload_manager.hpp index 24561593..789c6488 100644 --- a/repertory/librepertory/include/file_manager/i_upload_manager.hpp +++ b/repertory/librepertory/include/file_manager/i_upload_manager.hpp @@ -29,14 +29,14 @@ class i_upload_manager { INTERFACE_SETUP(i_upload_manager); public: - virtual void queue_upload(const i_open_file &o) = 0; + virtual void queue_upload(const i_open_file &file) = 0; virtual void remove_resume(const std::string &api_path, const std::string &source_path) = 0; virtual void remove_upload(const std::string &api_path) = 0; - virtual void store_resume(const i_open_file &o) = 0; + virtual void store_resume(const i_open_file &file) = 0; }; } // namespace repertory diff --git a/repertory/librepertory/src/file_manager/file_manager.cpp b/repertory/librepertory/src/file_manager/file_manager.cpp index 42ed2e86..88399e31 100644 --- a/repertory/librepertory/src/file_manager/file_manager.cpp +++ b/repertory/librepertory/src/file_manager/file_manager.cpp @@ -429,7 +429,7 @@ void file_manager::queue_upload(const std::string &api_path, api_path, source_path, })) { - remove_resume(api_path, source_path); + remove_resume(api_path, source_path, true); event_system::instance().raise(api_path, source_path); } else { event_system::instance().raise( @@ -454,8 +454,10 @@ auto file_manager::remove_file(const std::string &api_path) -> api_error { close_all(api_path); + mutex_lock lock(upload_mtx_); remove_upload(api_path, true); - remove_resume(api_path, fsi.source_path); + remove_resume(api_path, fsi.source_path, true); + upload_notify_.notify_all(); res = provider_.remove_file(api_path); if (res != api_error::success) { @@ -473,12 +475,26 @@ auto file_manager::remove_file(const std::string &api_path) -> api_error { void file_manager::remove_resume(const std::string &api_path, const std::string &source_path) { - if (not mgr_db_->remove_resume(api_path)) { + return remove_resume(api_path, source_path, false); +} + +void file_manager::remove_resume(const std::string &api_path, + const std::string &source_path, bool no_lock) { + if (provider_.is_read_only()) { return; } - event_system::instance().raise(api_path, - source_path); + std::unique_ptr lock; + if (not no_lock) { + lock = std::make_unique(upload_mtx_); + } + + if (mgr_db_->remove_resume(api_path)) { + event_system::instance().raise(api_path, + source_path); + } + + upload_notify_.notify_all(); } void file_manager::remove_upload(const std::string &api_path) {