Fix hybrid pkg uninstallation 28/182128/1
authorTomasz Swierczek <t.swierczek@samsung.com>
Wed, 20 Jun 2018 12:31:59 +0000 (14:31 +0200)
committerTomasz Swierczek <t.swierczek@samsung.com>
Wed, 20 Jun 2018 13:53:33 +0000 (15:53 +0200)
Removal of last app in pkg removed also pkg information from DB.
This meant that subsequent Cynara policy removal could not calculate
proper Smack label of the app, hence not removing policy & keeping
artifacts in Cynara DB.

Change-Id: Ib647b16f5e0d46e4f31bbaa7b823f04071e827d7

src/common/include/service_impl.h
src/common/privilege_db.cpp
src/common/service_impl.cpp

index 85416d0..f02453a 100644 (file)
@@ -394,7 +394,7 @@ private:
                                 app_inst_req &req,
                                 UninstallHelper &uh);
 
-    void appUninstallCynaraPolicies(app_inst_req::app &app,
+    void appUninstallCynaraPolicies(std::string &processLabel,
                                     app_inst_req &req,
                                     UninstallHelper &uh);
 
index fb7fadb..644ad78 100644 (file)
@@ -570,7 +570,7 @@ bool PrivilegeDb::IsPackageHybrid(const std::string& pkgName)
         if (command->Step())
             isHybrid = command->GetColumnInteger(0);
 
-        LogDebug("Package " << pkgName << "has is_hybrid set to " << isHybrid);
+        LogDebug("Package " << pkgName << " has is_hybrid set to " << isHybrid);
 
         return (isHybrid > 0);
     });
index 0729bbf..084a4bf 100644 (file)
@@ -1003,11 +1003,10 @@ void ServiceImpl::appUninstallPrivileges(app_inst_req::app &app, app_inst_req &r
     uh.removeApps.push_back(removeApp);
 }
 
-void ServiceImpl::appUninstallCynaraPolicies(app_inst_req::app &app, app_inst_req &req,
+void ServiceImpl::appUninstallCynaraPolicies(std::string &processLabel, app_inst_req &req,
         UninstallHelper &ui)
 {
-    std::string processLabel = getAppProcessLabel(app.appName, req.pkgName);
-    LogDebug("Generated uninstall parameters: pkgName=" << req.pkgName
+    LogDebug("Removing Cynara policy for: pkgName=" << req.pkgName
              << " Smack label=" << processLabel);
 
     bool global = req.installationType == SM_APP_INSTALL_GLOBAL ||
@@ -1100,16 +1099,25 @@ int ServiceImpl::appUninstall(const Credentials &creds, app_inst_req &req)
         m_privilegeDb.GetPackagesInfo(uh.pkgsInfo);
         getPkgsProcessLabels(uh.pkgsInfo, uh.pkgsProcessLabels);
 
+        LogDebug("Uninstalling pkg: " << req.pkgName << " with " << req.apps.size() << " apps");
+        for (auto &app: req.apps) {
+            LogDebug("-- Removing app: " << app.appName);
+        }
+
         // [db] begin
         ScopedTransaction trans(m_privilegeDb);
 
         for (auto &app : req.apps) {
             if (app.appName.empty())
                 continue;
+            // Cynara client (Smack label) needs to be calculated before we'll remove app from privileges db
+            // Otherwise, last app being removed from pkg will not be able to determine correct Smack label
+            // if the pkg is hybrid
+            std::string processLabel = getAppProcessLabel(app.appName, req.pkgName);
             // [db] remove app
             appUninstallPrivileges(app, req, uh);
             // [cynara] update app policy
-            appUninstallCynaraPolicies(app, req, uh);
+            appUninstallCynaraPolicies(processLabel, req, uh);
         }
 
         // [db] commit