Fix static analysis issue 78/297278/1
authorilho kim <ilho159.kim@samsung.com>
Wed, 16 Aug 2023 06:53:50 +0000 (15:53 +0900)
committerilho kim <ilho159.kim@samsung.com>
Wed, 16 Aug 2023 06:53:50 +0000 (15:53 +0900)
Remove of unnecessary copy operation from auto

Change-Id: I9e76b2a9f4a18a1c8170a981b87e538590c6a64c
Signed-off-by: ilho kim <ilho159.kim@samsung.com>
src/common/pkgmgr_registration.cc
src/common/pkgmgr_signal.cc
src/common/plugins/category_plugin.cc
src/common/plugins/metadata_plugin.cc
src/common/shared_dirs.cc
src/common/step/filesystem/step_remove_user_data.cc
src/common/step/pkgmgr/step_check_installable.cc
src/common/step/pkgmgr/step_remove_priv_sharedres.cc
src/pkg_recovery/pkg_recovery.cc

index 461ee88..71c2d64 100644 (file)
@@ -63,7 +63,7 @@ bool RegisterCertificates(
     LOG(ERROR) << "Cannot create pkgmgr_instcertinfo_h";
     return false;
   }
-  for (auto pair : kCertTypePairs) {
+  for (const auto& pair : kCertTypePairs) {
      auto cert = (cert_info.*(pair.first)).get();
      auto type = pair.second;
      if (!RegisterCertificate(handle, cert, type))
index 1f5ba98..acb2a92 100644 (file)
@@ -95,7 +95,7 @@ bool PkgmgrSignal::SendStarted(
   if (request_type_ == ci::RequestType::Uninstall) {
     if (!SendAppids(type, pkgid))
       return false;
-    for (auto l : user_list_)
+    for (const auto& l : user_list_)
       SendAppids(l.first, type, pkgid);
   }
 
@@ -110,7 +110,7 @@ bool PkgmgrSignal::SendProgress(int progress,
   if (!SendSignal(PKGMGR_INSTALLER_INSTALL_PERCENT_KEY_STR,
       std::to_string(progress).c_str(), type, pkgid))
     return false;
-  for (auto l : user_list_) {
+  for (const auto& l : user_list_) {
     // ignore error case
     SendSignal(l.first, PKGMGR_INSTALLER_INSTALL_PERCENT_KEY_STR,
         std::to_string(progress).c_str(), type, pkgid);
@@ -142,7 +142,7 @@ bool PkgmgrSignal::SendFinished(
       PKGMGR_INSTALLER_END_KEY_STR, GetResultKey(result), type, pkgid))
     return false;
 
-  for (auto l : user_list_)
+  for (const auto& l : user_list_)
     SendSignal(l.first,
         PKGMGR_INSTALLER_END_KEY_STR, GetResultKey(result), type, pkgid);
 
@@ -172,7 +172,7 @@ bool PkgmgrSignal::SendError(
       type,
       pkgid))
     return false;
-  for (auto l : user_list_)
+  for (const auto& l : user_list_)
     SendSignal(l.first,
         PKGMGR_INSTALLER_ERROR_KEY_STR,
         error_value.c_str(),
index 737982a..78a901d 100644 (file)
@@ -166,7 +166,7 @@ bool CategoryPlugin::Run(xmlDocPtr /*doc_ptr*/, manifest_x* manifest,
     return true;
 
   name = GetFunctionName(ActionType::Removed);
-  for (auto appid : appid_list) {
+  for (const auto& appid : appid_list) {
     int result = 0;
     Exec(name, &result, manifest->package, appid, nullptr);
     if (result) {
index 4de70fe..0cf2a53 100644 (file)
@@ -177,7 +177,7 @@ bool MetadataPlugin::Run(xmlDocPtr /*doc_ptr*/, manifest_x* manifest,
     name = GetFunctionName(action_type);
   else
     name = GetFunctionName(ActionType::Removed);
-  for (auto appid : appid_list_) {
+  for (const auto& appid : appid_list_) {
     int result = 0;
     Exec(name, &result, manifest->package, appid.c_str(), nullptr);
     if (result) {
index 52dd7b5..ba17ea7 100644 (file)
@@ -150,7 +150,7 @@ bool DeleteSharedDataDirectories(const bf::path& path,
     return false;
 
   std::vector<std::string> shared_dirs(kSharedDataEntries);
-  for (auto entry : shared_dirs) {
+  for (const auto& entry : shared_dirs) {
     if (!ci::RemoveAll(path / entry / pkgid))
       return false;
   }
@@ -461,7 +461,7 @@ bool PerformExternalDirectoryDeletionForUser(uid_t user,
 
 bool PerformExternalDirectoryCreationForAllUsers(const std::string& pkgid) {
   UserList list = ci::GetUserList();
-  for (auto l : list) {
+  for (const auto& l : list) {
     if (!PerformExternalDirectoryCreationForUser(std::get<0>(l),
                                                  pkgid))
       LOG(WARNING) << "Could not create external storage directories for user: "
@@ -472,7 +472,7 @@ bool PerformExternalDirectoryCreationForAllUsers(const std::string& pkgid) {
 
 bool PerformExternalDirectoryCreationForAllPkgs() {
   UserList list = ci::GetUserList();
-  for (auto l  : list) {
+  for (const auto& l  : list) {
     uid_t uid = std::get<0>(l);
     pkgmgrinfo_pkginfo_filter_h filter_handle = nullptr;
     int ret = pkgmgrinfo_pkginfo_filter_create(&filter_handle);
@@ -513,7 +513,7 @@ bool PerformExternalDirectoryCreationForAllPkgs() {
 
 bool PerformExternalDirectoryDeletionForAllUsers(const std::string& pkgid) {
   UserList list = ci::GetUserList();
-  for (auto l : list) {
+  for (const auto& l : list) {
     uid_t uid = std::get<0>(l);
     ci::PkgQueryInterface pkg_query(pkgid, uid);
     LOG(DEBUG) << "Deleting directories for user: " << uid;
@@ -558,7 +558,7 @@ bool CreatePerUserStorageDirectories(const std::string& pkgid, bool trusted,
 
   // create per user dir
   UserList list = ci::GetUserList();
-  for (auto l : list) {
+  for (const auto& l : list) {
     uid_t uid = std::get<0>(l);
     bf::path owner_apps_rw = std::get<2>(l) / "apps_rw";
     std::vector<bf::path> apps_rw_paths;
@@ -581,7 +581,7 @@ bool CreatePerUserStorageDirectories(const std::string& pkgid, bool trusted,
 
       if (shareddata) {
         std::vector<std::string> shared_dirs(kSharedDataEntries);
-        for (auto entry : shared_dirs) {
+        for (const auto& entry : shared_dirs) {
           bf::path shared_dst = apps_rw / entry / pkgid;
           if (!::SetPackageDirectoryOwnerAndPermissions(shared_dst, uid))
             return false;
@@ -615,7 +615,7 @@ bool DeletePerUserStorageDirectories(const std::string& pkgid,
 
   // delete per user dir
   UserList list = ci::GetUserList();
-  for (auto l : list) {
+  for (const auto& l : list) {
     uid_t uid = std::get<0>(l);
     bf::path owner_apps_rw = std::get<2>(l) / "apps_rw";
     std::vector<bf::path> apps_rw_paths;
@@ -656,7 +656,7 @@ bool CreateStorageDirectories(const boost::filesystem::path& path,
 
   if (shareddata) {
     std::vector<std::string> shared_dirs(kSharedDataEntries);
-    for (auto entry : shared_dirs) {
+    for (const auto& entry : shared_dirs) {
       bf::path shared_dst = path / entry / pkgid;
       if (!::SetPackageDirectoryOwnerAndPermissions(shared_dst, uid))
         return false;
@@ -694,7 +694,7 @@ bool DeleteSharedDirectories(const bf::path& path,
 
 bool DeleteUserExternalDirectories(const std::string& pkgid) {
   UserList list = ci::GetUserList();
-  for (auto l : list) {
+  for (const auto& l : list) {
     uid_t uid = std::get<0>(l);
     ci::PkgQueryInterface pkg_query(pkgid, uid);
     if (pkg_query.IsPackageInstalled()) {
@@ -727,7 +727,7 @@ bool CreateGlobalAppSymlinksForAllUsers(const std::string& pkgid) {
   }
 
   UserList list = ci::GetUserList();
-  for (auto l : list) {
+  for (const auto& l : list) {
     uid_t uid = std::get<0>(l);
     LOG(DEBUG) << "Creating symlinks for uid: " << uid;
     // check installed user private app.
@@ -785,7 +785,7 @@ bool DeleteGlobalAppSymlinksForAllUsers(const std::string& pkgid) {
   }
 
   UserList list = ci::GetUserList();
-  for (auto l : list) {
+  for (const auto& l : list) {
     uid_t uid = std::get<0>(l);
     LOG(DEBUG) << "Deleting symlinks for uid: " << uid;
 
@@ -883,7 +883,7 @@ bool CreatePerUserSharedDataDir(const std::string& pkgid) {
 
   // create per user dir
   ci::UserList list = ci::GetUserList();
-  for (auto l : list) {
+  for (const auto& l : list) {
     uid_t uid = std::get<0>(l);
     LOG(DEBUG) << "Adding shareddata directory for uid: " << uid;
 
@@ -899,7 +899,7 @@ bool CreatePerUserSharedDataDir(const std::string& pkgid) {
         return false;
 
       std::vector<std::string> shared_dirs(kSharedDataEntries);
-      for (auto entry : shared_dirs) {
+      for (const auto& entry : shared_dirs) {
         bf::path shared_dst = apps_rw / entry / pkgid;
         if (!::SetPackageDirectoryOwnerAndPermissions(shared_dst, uid))
           return false;
@@ -929,7 +929,7 @@ bool DeletePerUserSharedDataDir(const std::string& pkgid) {
     return false;
 
   ci::UserList list = ci::GetUserList();
-  for (auto l : list) {
+  for (const auto& l : list) {
     uid_t uid = std::get<0>(l);
 
     bf::path owner_apps_rw = ci::GetRootAppPath(false, uid);
@@ -959,7 +959,7 @@ bool BackupPerUserSharedDataDir(const std::string& pkgid) {
     return false;
 
   ci::UserList list = ci::GetUserList();
-  for (auto l : list) {
+  for (const auto& l : list) {
     uid_t uid = std::get<0>(l);
     bf::path owner_apps_rw = ci::GetRootAppPath(false, uid);
     std::vector<bf::path> apps_rw_paths;
@@ -986,7 +986,7 @@ bool RestoreSharedDataDir(const std::string& pkgid, uid_t uid) {
     return false;
 
   std::vector<std::string> shared_dirs(kSharedDataEntries);
-  for (auto entry : shared_dirs) {
+  for (const auto& entry : shared_dirs) {
     bf::path shared_dst = apps_rw / entry / pkgid;
     if (!::SetPackageDirectoryOwnerAndPermissions(shared_dst, uid))
       return false;
@@ -1011,7 +1011,7 @@ bool RestorePerUserSharedDataDir(const std::string& pkgid) {
 
   std::string error_message;
   ci::UserList list = ci::GetUserList();
-  for (auto l : list) {
+  for (const auto& l : list) {
     uid_t uid = std::get<0>(l);
     bf::path owner_apps_rw = ci::GetRootAppPath(false, uid);
     std::vector<bf::path> apps_rw_paths;
@@ -1028,7 +1028,7 @@ bool RestorePerUserSharedDataDir(const std::string& pkgid) {
         return false;
 
       std::vector<std::string> shared_dirs(kSharedDataEntries);
-      for (auto entry : shared_dirs) {
+      for (const auto& entry : shared_dirs) {
         bf::path shared_dst = apps_rw / entry / pkgid;
         if (!::SetPackageDirectoryOwnerAndPermissions(shared_dst, uid))
           return false;
@@ -1058,7 +1058,7 @@ bool RemoveBackupPerUserSharedDataDir(const std::string& pkgid) {
     return false;
 
   ci::UserList list = ci::GetUserList();
-  for (auto l : list) {
+  for (const auto& l : list) {
     uid_t uid = std::get<0>(l);
     bf::path owner_apps_rw = ci::GetRootAppPath(false, uid);
     std::vector<bf::path> apps_rw_paths;
index d4b310c..e6a81e4 100644 (file)
@@ -47,7 +47,7 @@ Step::Status StepRemoveUserData::process() {
     return Step::Status::OK;
 
   UserList list = ci::GetUserList();
-  for (auto l : list) {
+  for (const auto& l : list) {
     uid_t uid = std::get<0>(l);
     bf::path owner_apps_rw(std::get<2>(l) / "apps_rw");
     std::vector<bf::path> apps_rw_paths;
index 6faf760..221f6d0 100644 (file)
@@ -39,7 +39,7 @@ Step::Status StepCheckInstallable::process() {
     }
     case RequestMode::GLOBAL: {
       UserList list = GetUserList();
-      for (auto l : list) {
+      for (const auto& l : list) {
         uid_t uid = std::get<0>(l);
         PkgQueryInterface pkg_query(context_->pkgid.get(), uid);
         if (pkg_query.IsPackageInstalled(RequestMode::USER)) {
index 8ff5135..828e51b 100644 (file)
@@ -59,7 +59,7 @@ Step::Status StepRemovePrivSharedres::process() {
 Step::Status StepRemovePrivSharedres::OfflineRemove() {
   if (context_->request_mode.get() == RequestMode::GLOBAL) {
     common_installer::UserList user_list = common_installer::GetUserList();
-    for (auto l : user_list) {
+    for (const auto& l : user_list) {
       uid_t uid = std::get<0>(l);
       if (!RemoveResForUid(context_->pkgid.get(), uid))
         return Status::ERROR;
@@ -75,7 +75,7 @@ Step::Status StepRemovePrivSharedres::OfflineRemove() {
 Step::Status StepRemovePrivSharedres::RequestRemove() {
   if (context_->request_mode.get() == RequestMode::GLOBAL) {
     common_installer::UserList user_list = common_installer::GetUserList();
-    for (auto l : user_list) {
+    for (const auto& l : user_list) {
       uid_t uid = std::get<0>(l);
       int ret = SendUninstallRequest(context_->pkgid.get(), uid);
       if (ret == PKGMGR_R_OK) {
index ddc5455..266748c 100644 (file)
@@ -120,7 +120,7 @@ void PkgRecoveryService::Run() {
 
   // recover normal user packages
   ci::UserList list = ci::GetUserList();
-  for (auto userinfo : list) {
+  for (const auto& userinfo : list) {
     uid_t uid = std::get<0>(userinfo);
     LOG(INFO) << "Searching recovery files for user " << std::get<0>(userinfo);
     SearchBackupFiles(uid);
@@ -183,7 +183,7 @@ std::vector<RecoverEntry> PkgRecoveryService::SearchRecoveryFiles(uid_t uid) {
 void PkgRecoveryService::ProcessRecovery(uid_t uid,
     const std::vector<RecoverEntry>& entries) {
   LOG(INFO) << "Process recovery for user " << uid;
-  for (auto entry : entries) {
+  for (const auto& entry : entries) {
     const char* type = entry.first.c_str();
     const char* file = entry.second.c_str();
     if (!bf::exists(file))