From 1f46ea81bbd007464c24c7c06f07bd02d4c2a6a4 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Mon, 3 Aug 2020 16:40:27 +0900 Subject: [PATCH] Fix static analysis issue Fix uncaught exception. Change-Id: Ib2526443fcc27fd615fb9325282dbfd3515e9844 Signed-off-by: Sangyoon Jang (cherry picked from commit 140ba528998c7fa6f607bb081bca66a1e9518034) --- src/common/utils/file_util.cc | 12 +++++++++--- src/pkg_recovery/pkg_recovery.cc | 16 ++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/common/utils/file_util.cc b/src/common/utils/file_util.cc index 6595256..e5f602f 100644 --- a/src/common/utils/file_util.cc +++ b/src/common/utils/file_util.cc @@ -339,12 +339,18 @@ bool RemoveAll(const bf::path& path) { } bool Remove(const bf::path& path) { - if (!exists(path) && !bf::is_symlink(bf::symlink_status(path))) + bs::error_code error; + if (!exists(path, error)) { + if (error) { + LOG(ERROR) << "Cannot remove: " << path << ", " << error.message(); + return false; + } + return true; + } + if (!bf::is_symlink(bf::symlink_status(path))) return true; - bs::error_code error; bf::remove(path, error); - if (error) { LOG(ERROR) << "Cannot remove: " << path << ", " << error.message(); return false; diff --git a/src/pkg_recovery/pkg_recovery.cc b/src/pkg_recovery/pkg_recovery.cc index 72babe0..9e9ad0a 100644 --- a/src/pkg_recovery/pkg_recovery.cc +++ b/src/pkg_recovery/pkg_recovery.cc @@ -80,10 +80,11 @@ void PkgRecoveryService::Run() { void PkgRecoveryService::SearchBackupFiles(uid_t uid) { const bf::path recovery_dir = ci::GetRootAppPath(false, uid); - for (bf::directory_iterator iter(recovery_dir); - iter != bf::directory_iterator(); - ++iter) { - try { + try { + for (bf::directory_iterator iter(recovery_dir); + iter != bf::directory_iterator(); + ++iter) { + std::string file = iter->path().filename().string(); std::regex backup_regex(kBackupFilePattern); std::smatch match; @@ -94,11 +95,10 @@ void PkgRecoveryService::SearchBackupFiles(uid_t uid) { else bf::rename(iter->path(), orig_file); } - } catch (...) { - LOG(WARNING) << "Exception occurred: " - << boost::current_exception_diagnostic_information(); - continue; } + } catch (...) { + LOG(WARNING) << "Exception occurred: " + << boost::current_exception_diagnostic_information(); } } -- 2.7.4