close all files in background
This commit is contained in:
parent
33e8e0890b
commit
baf769c462
@ -93,7 +93,7 @@ E_SIMPLE3(download_stored_failed, error, true,
|
||||
std::string, error, err, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE1(download_timeout, warn, true,
|
||||
E_SIMPLE1(item_timeout, normal, true,
|
||||
std::string, api_path, ap, E_STRING
|
||||
);
|
||||
// clang-format on
|
||||
|
@ -86,23 +86,15 @@ file_manager::~file_manager() {
|
||||
}
|
||||
|
||||
void file_manager::close(std::uint64_t handle) {
|
||||
unique_recur_mutex_lock file_lock(open_file_mtx_);
|
||||
recur_mutex_lock file_lock(open_file_mtx_);
|
||||
auto closeable_file = get_open_file_by_handle(handle);
|
||||
if (closeable_file) {
|
||||
closeable_file->remove(handle);
|
||||
|
||||
if (closeable_file->can_close()) {
|
||||
auto api_path = closeable_file->get_api_path();
|
||||
open_file_lookup_.erase(api_path);
|
||||
file_lock.unlock();
|
||||
|
||||
closeable_file->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void file_manager::close_all(const std::string &api_path) {
|
||||
unique_recur_mutex_lock file_lock(open_file_mtx_);
|
||||
recur_mutex_lock file_lock(open_file_mtx_);
|
||||
std::vector<std::uint64_t> handles;
|
||||
auto iter = open_file_lookup_.find(api_path);
|
||||
if (iter == open_file_lookup_.end()) {
|
||||
@ -115,11 +107,6 @@ void file_manager::close_all(const std::string &api_path) {
|
||||
for (auto handle : handles) {
|
||||
closeable_file->remove(handle);
|
||||
}
|
||||
|
||||
open_file_lookup_.erase(api_path);
|
||||
file_lock.unlock();
|
||||
|
||||
closeable_file->close();
|
||||
}
|
||||
|
||||
void file_manager::close_timed_out_files() {
|
||||
@ -141,7 +128,7 @@ void file_manager::close_timed_out_files() {
|
||||
|
||||
for (auto &closeable_file : closeable_list) {
|
||||
closeable_file->close();
|
||||
event_system::instance().raise<download_timeout>(
|
||||
event_system::instance().raise<item_timeout>(
|
||||
closeable_file->get_api_path());
|
||||
}
|
||||
closeable_list.clear();
|
||||
@ -838,7 +825,7 @@ void file_manager::stop() {
|
||||
while (not upload_lookup_.empty()) {
|
||||
upload_lock.lock();
|
||||
if (not upload_lookup_.empty()) {
|
||||
upload_notify_.wait_for(upload_lock, 1s);
|
||||
upload_notify_.wait_for(upload_lock, 1ms);
|
||||
}
|
||||
upload_notify_.notify_all();
|
||||
upload_lock.unlock();
|
||||
|
@ -1711,8 +1711,8 @@ TEST(file_manager, file_is_closed_after_download_timeout) {
|
||||
const auto source_path = utils::path::combine(
|
||||
cfg.get_cache_directory(), {utils::create_uuid_string()});
|
||||
|
||||
event_consumer es("download_timeout", [](const event &e) {
|
||||
const auto &ee = dynamic_cast<const download_timeout &>(e);
|
||||
event_consumer es("item_timeout", [](const event &e) {
|
||||
const auto &ee = dynamic_cast<const item_timeout &>(e);
|
||||
EXPECT_STREQ("/test_download_timeout.txt",
|
||||
ee.get_api_path().get<std::string>().c_str());
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user