Optimize application uninstallation 89/187489/3
authorKonrad Lipinski <k.lipinski2@partner.samsung.com>
Thu, 23 Aug 2018 14:03:58 +0000 (16:03 +0200)
committerKonrad Lipinski <k.lipinski2@partner.samsung.com>
Wed, 29 Aug 2018 08:47:39 +0000 (10:47 +0200)
Many operations were needlessly performed. Mitigated some of those
deficiencies by constraining lifetimes of some automatic variables and
hoisting redundant operations out of the loop.

Change-Id: I19e37f1cb73ec57ecf525b7bc125d0e2e90cc573

src/common/service_impl.cpp

index 6ffb317..a33ed9a 100644 (file)
@@ -1018,44 +1018,44 @@ int ServiceImpl::appUninstallSmackRules(app_inst_req &req, UninstallHelper &uh)
 {
     try {
         for (unsigned appIdx = 0; appIdx < req.apps.size(); ++appIdx) {
-            const std::string &appName = req.apps[appIdx].appName;
-            std::string processLabel = getAppProcessLabel(appName, req.pkgName);
             if (uh.removeApps[appIdx]) {
+                const std::string &appName = req.apps[appIdx].appName;
+                std::string processLabel = getAppProcessLabel(appName, req.pkgName);
                 LogDebug("Removing Smack rules for appName " << appName);
                 if (uh.isOldPkgHybrid || uh.removePkg || uh.isOldPkgHybrid != req.isHybrid) {
                     /*
                      * Nonhybrid apps have the same label, so revoking it is unnecessary
-                     * unless whole packagee is being removed.
+                     * unless whole package is being removed.
                      */
                     SmackRules::uninstallApplicationRules(appName, processLabel);
                 }
-                LogDebug("Removing Smack rules for pkgName " << req.pkgName);
-                SmackRules::uninstallPackageRules(req.pkgName);
                 if (!uh.removePkg) {
-                    LogDebug("Recreating Smack rules for pkgName " << req.pkgName);
                     uh.pkgLabels.erase(std::remove(uh.pkgLabels.begin(), uh.pkgLabels.end(), processLabel),
                                     uh.pkgLabels.end());
-                    SmackRules::updatePackageRules(req.pkgName, uh.pkgLabels);
-                }
-
-                if (uh.removePkg) {
-                    // remove deinstalled package from packages list and generate SharedRO rules for others
-                    uh.pkgsProcessLabels.erase(
-                        std::remove_if(uh.pkgsProcessLabels.begin(), uh.pkgsProcessLabels.end(),
-                        [&](const std::pair<std::string, std::vector<std::string>> &pkg) {
-                            return pkg.first == req.pkgName;
-                        }),
-                        uh.pkgsProcessLabels.end());
-
-                    SmackRules::generateSharedRORules(uh.pkgsProcessLabels, uh.pkgsInfo);
-                    SmackRules::revokeSharedRORules(uh.pkgsProcessLabels, req.pkgName);
                 }
             }
+        }
 
-            if (uh.authorId != -1 && uh.removeAuthor) {
-                LogDebug("Removing Smack rules for authorId " << uh.authorId);
-                SmackRules::uninstallAuthorRules(uh.authorId);
-            }
+        LogDebug("Removing Smack rules for pkgName " << req.pkgName);
+        SmackRules::uninstallPackageRules(req.pkgName);
+        if (!uh.removePkg) {
+            LogDebug("Recreating Smack rules for pkgName " << req.pkgName);
+            SmackRules::updatePackageRules(req.pkgName, uh.pkgLabels);
+        } else {
+            // remove deinstalled package from packages list and generate SharedRO rules for others
+            uh.pkgsProcessLabels.erase(
+                std::remove_if(uh.pkgsProcessLabels.begin(), uh.pkgsProcessLabels.end(),
+                [&](const std::pair<std::string, std::vector<std::string>> &pkg) {
+                    return pkg.first == req.pkgName;
+                }),
+                uh.pkgsProcessLabels.end());
+
+            SmackRules::generateSharedRORules(uh.pkgsProcessLabels, uh.pkgsInfo);
+            SmackRules::revokeSharedRORules(uh.pkgsProcessLabels, req.pkgName);
+        }
+        if (uh.authorId != -1 && uh.removeAuthor) {
+            LogDebug("Removing Smack rules for authorId " << uh.authorId);
+            SmackRules::uninstallAuthorRules(uh.authorId);
         }
 
         SmackRules::mergeRules();