file manager fixes

This commit is contained in:
Scott E. Graves 2024-12-10 11:08:37 -06:00
parent 3a52dfc4ea
commit 8128ac09b3
3 changed files with 35 additions and 16 deletions

View File

@ -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<i_file_mgr_db::resume_entry>;
[[nodiscard]] auto get_stored_downloads() const
-> std::vector<i_file_mgr_db::resume_entry>;
[[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<i_closeable_open_file> 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();

View File

@ -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

View File

@ -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<file_upload_queued>(api_path, source_path);
} else {
event_system::instance().raise<file_upload_failed>(
@ -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<download_resume_removed>(api_path,
source_path);
std::unique_ptr<mutex_lock> lock;
if (not no_lock) {
lock = std::make_unique<mutex_lock>(upload_mtx_);
}
if (mgr_db_->remove_resume(api_path)) {
event_system::instance().raise<download_resume_removed>(api_path,
source_path);
}
upload_notify_.notify_all();
}
void file_manager::remove_upload(const std::string &api_path) {