From 6a844057719a4f85e78b95b7cfe9ae69671ca862 Mon Sep 17 00:00:00 2001 From: Konrad Lipinski Date: Thu, 23 Aug 2018 16:03:58 +0200 Subject: [PATCH] Optimize application uninstallation 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 | 48 ++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/common/service_impl.cpp b/src/common/service_impl.cpp index 6ffb317..a33ed9a 100644 --- a/src/common/service_impl.cpp +++ b/src/common/service_impl.cpp @@ -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> &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> &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(); -- 2.7.4