refactor
This commit is contained in:
parent
dfb9d78448
commit
c4326520cd
@ -223,11 +223,6 @@ E_SIMPLE1(orphaned_file_detected, warn, true,
|
||||
std::string, source, src, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE2(orphaned_file_processed, warn, true,
|
||||
std::string, source, src, E_STRING,
|
||||
std::string, dest, dest, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE3(orphaned_file_processing_failed, error, true,
|
||||
std::string, source, src, E_STRING,
|
||||
std::string, dest, dest, E_STRING,
|
||||
|
@ -481,52 +481,65 @@ void base_provider::remove_deleted_files() {
|
||||
}
|
||||
|
||||
for (auto &&item : removed_list) {
|
||||
if (not item.directory) {
|
||||
if (utils::file::file(item.source_path).exists()) {
|
||||
if (item.directory) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (not utils::file::file(item.source_path).exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto orphaned_directory =
|
||||
utils::path::combine(config_.get_data_directory(), {"orphaned"});
|
||||
if (utils::file::directory(orphaned_directory).create_directory()) {
|
||||
const auto parts = utils::string::split(item.api_path, '/', false);
|
||||
const auto orphaned_file = utils::path::combine(
|
||||
orphaned_directory,
|
||||
{utils::path::strip_to_file_name(item.source_path) + '_' +
|
||||
parts[parts.size() - 1U]});
|
||||
|
||||
event_system::instance().raise<orphaned_file_detected>(
|
||||
item.source_path);
|
||||
if (utils::file::reset_modified_time(item.source_path) &&
|
||||
utils::file::file(item.source_path)
|
||||
.copy_to(orphaned_file, true)) {
|
||||
event_system::instance().raise<orphaned_file_processed>(
|
||||
item.source_path, orphaned_file);
|
||||
} else {
|
||||
event_system::instance().raise<orphaned_file_processing_failed>(
|
||||
item.source_path, orphaned_file,
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
}
|
||||
} else {
|
||||
if (not utils::file::directory(orphaned_directory).create_directory()) {
|
||||
utils::error::raise_error(
|
||||
function_name, std::to_string(utils::get_last_error_code()),
|
||||
"failed to create orphaned directory|sp|" + orphaned_directory);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
const auto parts = utils::string::split(item.api_path, '/', false);
|
||||
const auto orphaned_file = utils::path::combine(
|
||||
orphaned_directory, {utils::path::strip_to_file_name(item.source_path) +
|
||||
'_' + parts[parts.size() - 1U]});
|
||||
|
||||
event_system::instance().raise<orphaned_file_detected>(item.source_path);
|
||||
if (not utils::file::reset_modified_time(item.source_path)) {
|
||||
event_system::instance().raise<orphaned_file_processing_failed>(
|
||||
item.source_path, orphaned_file,
|
||||
"reset modified failed|" +
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (not utils::file::file(item.source_path).copy_to(orphaned_file, true)) {
|
||||
[[maybe_unused]] auto removed = utils::file::file{orphaned_file}.remove();
|
||||
event_system::instance().raise<orphaned_file_processing_failed>(
|
||||
item.source_path, orphaned_file,
|
||||
"copy failed|" + std::to_string(utils::get_last_error_code()));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (not fm_->evict_file(item.api_path)) {
|
||||
event_system::instance().raise<orphaned_file_processing_failed>(
|
||||
item.source_path, orphaned_file, "eviction failed");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fm_->evict_file(item.api_path)) {
|
||||
db3_->remove_api_path(item.api_path);
|
||||
event_system::instance().raise<file_removed_externally>(
|
||||
item.api_path, item.source_path);
|
||||
}
|
||||
}
|
||||
event_system::instance().raise<file_removed_externally>(item.api_path,
|
||||
item.source_path);
|
||||
}
|
||||
|
||||
for (auto &&item : removed_list) {
|
||||
if (item.directory) {
|
||||
if (not item.directory) {
|
||||
continue;
|
||||
}
|
||||
|
||||
db3_->remove_api_path(item.api_path);
|
||||
event_system::instance().raise<directory_removed_externally>(
|
||||
item.api_path, item.source_path);
|
||||
}
|
||||
}
|
||||
|
||||
auto source_list =
|
||||
utils::file::directory{config_.get_cache_directory()}.get_files();
|
||||
@ -534,6 +547,24 @@ void base_provider::remove_deleted_files() {
|
||||
filesystem_item fsi{};
|
||||
if (get_filesystem_item_from_source_path(source_file->get_path(), fsi) !=
|
||||
api_error::item_not_found) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto reference_time =
|
||||
source_file->get_time(config_.get_eviction_uses_accessed_time()
|
||||
? utils::file::time_type::accessed
|
||||
: utils::file::time_type::modified);
|
||||
if (not reference_time.has_value()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto delay = (config_.get_eviction_delay_mins() * 60UL) *
|
||||
utils::time::NANOS_PER_SECOND;
|
||||
if ((reference_time.value() + static_cast<std::uint64_t>(delay)) <=
|
||||
utils::time::get_time_now()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
event_system::instance().raise<orphaned_source_file_detected>(
|
||||
source_file->get_path());
|
||||
if (source_file->remove()) {
|
||||
@ -541,7 +572,6 @@ void base_provider::remove_deleted_files() {
|
||||
source_file->get_path());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto base_provider::remove_file(const std::string &api_path) -> api_error {
|
||||
|
Loading…
x
Reference in New Issue
Block a user