diff --git a/debian/changelog b/debian/changelog index a7feb28..7c49634 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +deepin-anything (7.0.33) unstable; urgency=medium + + * feat: Improve daemon stability and resource management + + -- wangrong Fri, 28 Nov 2025 17:02:59 +0800 + deepin-anything (7.0.32) unstable; urgency=medium * fix: Fix deepin-anything-daemon coredump diff --git a/src/daemon/deepin-anything-daemon.service b/src/daemon/deepin-anything-daemon.service index 0654eaa..a7c2882 100755 --- a/src/daemon/deepin-anything-daemon.service +++ b/src/daemon/deepin-anything-daemon.service @@ -6,8 +6,10 @@ After=udisks2.service ExecStart=/usr/libexec/deepin-anything-daemon Restart=on-failure RestartSec=30 -MemoryHigh=4G -MemoryMax=5G +StartLimitIntervalSec=3600 # The time window is 3600 seconds (60 minutes) +StartLimitBurst=2 # A maximum of 2 starts are allowed within this window. +MemoryHigh=2G +MemoryMax=3G [Install] WantedBy=default.target diff --git a/src/daemon/src/core/base_event_handler.cpp b/src/daemon/src/core/base_event_handler.cpp index 4b688c9..b6ce906 100755 --- a/src/daemon/src/core/base_event_handler.cpp +++ b/src/daemon/src/core/base_event_handler.cpp @@ -50,9 +50,10 @@ void base_event_handler::terminate_processing() { pool_.wait_for_tasks(); if (!jobs_.empty()) { // Eat all jobs - for (auto&& job : jobs_) { + for (auto &&job : jobs_) { eat_job(std::move(job)); } + jobs_.clear(); } } @@ -351,24 +352,31 @@ bool base_event_handler::scan_directory(const std::string& dir_path, std::functi std::error_code ec; std::string path; - // By default, symlinks are not followed - std::filesystem::recursive_directory_iterator dirpos{ dir_path, std::filesystem::directory_options::skip_permission_denied }; - for (auto it = begin(dirpos); it != end(dirpos); ++it) { - path = std::move(it->path().string()); - if (is_path_in_blacklist(path, config_->blacklist_paths) || - !std::filesystem::exists(it->path(), ec)) { - it.disable_recursion_pending(); - continue; - } - if (!handler(path)) { - return false; - } + try { + // By default, symlinks are not followed + std::filesystem::recursive_directory_iterator dirpos{ dir_path, std::filesystem::directory_options::skip_permission_denied }; + for (auto it = begin(dirpos); it != end(dirpos); ++it) { + path = std::move(it->path().string()); + if (is_path_in_blacklist(path, config_->blacklist_paths) || + !std::filesystem::exists(it->path(), ec)) { + it.disable_recursion_pending(); + continue; + } - if (stop_scan_directory_) { - spdlog::info("Scanning interrupted"); - return true; + if (!handler(path)) { + spdlog::error("Failed to handle path: {}", path); + return false; + } + + if (stop_scan_directory_) { + spdlog::info("Scanning interrupted"); + return true; + } } + } catch (std::filesystem::filesystem_error const& e) { + spdlog::error("Failed to scan directory: {}, {}, {}, {}", + e.what(), e.path1().string(), e.path2().string(), e.code().value()); } spdlog::info("Scanning directory {} completed", dir_path); diff --git a/src/daemon/src/core/file_index_manager.cpp b/src/daemon/src/core/file_index_manager.cpp index b6ef5ef..6b83f6b 100755 --- a/src/daemon/src/core/file_index_manager.cpp +++ b/src/daemon/src/core/file_index_manager.cpp @@ -184,9 +184,10 @@ file_index_manager::file_index_manager(const std::string& persistent_index_dir, } } catch (const LuceneException& e) { spdlog::warn("The index is corrupted: {}", volatile_index_directory_); + std::error_code ec; if (writer_) writer_->close(); if (reader_) reader_->close(); - std::filesystem::remove_all(volatile_index_directory_); + std::filesystem::remove_all(volatile_index_directory_, ec); writer_ = newLucene(dir, newLucene(), @@ -575,7 +576,7 @@ void file_index_manager::check_index_version() { // 检查是否是无效索引 if (std::filesystem::exists(volatile_index_directory_ + "/invalid_index", ec)) { spdlog::warn("The index is invalid: {}, remove it", volatile_index_directory_); - std::filesystem::remove_all(volatile_index_directory_); + std::filesystem::remove_all(volatile_index_directory_, ec); return; } @@ -587,7 +588,7 @@ void file_index_manager::check_index_version() { spdlog::warn("The index is corrupted: {}", volatile_index_directory_); if (reader) reader->close(); spdlog::warn("Removing the corrupted index..."); - std::filesystem::remove_all(volatile_index_directory_); + std::filesystem::remove_all(volatile_index_directory_, ec); return; } @@ -610,7 +611,7 @@ void file_index_manager::check_index_version() { } else { spdlog::warn("The index version is mismatched: {}", volatile_index_directory_); spdlog::warn("Removing the incompatible index..."); - std::filesystem::remove_all(volatile_index_directory_); + std::filesystem::remove_all(volatile_index_directory_, ec); } }