Cleanup around Tizen2X apps/packages generation functions 80/69480/3
authorLukasz Pawelczyk <l.pawelczyk@samsung.com>
Thu, 12 May 2016 10:56:11 +0000 (12:56 +0200)
committerLukasz Pawelczyk <l.pawelczyk@samsung.com>
Thu, 19 May 2016 11:14:42 +0000 (13:14 +0200)
Create two separate functions, one for apps and one for packages. This
way we remove code duplication that was there before.
Remove the exclusion rule from the "packages" part. It wouldn't even work
properly when there were more then one app from the same package and was
just confusing. Further commits in this series are about handling
possible duplicates properly.

Change-Id: I31f3cb032cb1baab2940e9847547e3d2e3921335

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

index 415e4c9..05ffb23 100644 (file)
@@ -123,7 +123,7 @@ private:
         { StmtType::EGetPrivilegeGroups, " SELECT group_name FROM privilege_group_view WHERE privilege_name = ?" },
         { StmtType::EGetUserApps, "SELECT name FROM app WHERE uid=?" },
         { StmtType::EGetAllTizen2XApps,  "SELECT name FROM app WHERE version LIKE '2.%%' AND name <> ?" },
-        { StmtType::EGetAllTizen2XPackages,  "SELECT DISTINCT pkg_name FROM app_pkg_view WHERE version LIKE '2.%%' AND app_name <> ?" },
+        { StmtType::EGetAllTizen2XPackages,  "SELECT DISTINCT pkg_name FROM app_pkg_view WHERE version LIKE '2.%%'" },
         { StmtType::EGetAppsInPkg, " SELECT app_name FROM app_pkg_view WHERE pkg_name = ?" },
         { StmtType::EGetGroups, "SELECT DISTINCT group_name FROM privilege_group_view" },
         { StmtType::EGetPkgAuthorId, "SELECT author_id FROM pkg WHERE name = ? AND author_id IS NOT NULL"},
@@ -447,20 +447,15 @@ public:
     void GetTizen2XApps(const std::string &origApp, std::vector<std::string> &apps);
 
     /**
-     * Retrieve list of all apps and packages excluding one specified (typically action originator)
+     * Retrieve list of all Tizen 2.X packages
      *
-     * @param origApp - do not include specific application name in the list
-     * @param[out] apps - vector of app identifiers describing installed 2.x apps,
-     *                    this parameter do not need to be empty, but
-     *                    it is being overwritten during function call.
      * @param[out] packages - vector of package identifiers describing installed 2.x packages,
      *                    this parameter do not need to be empty, but
      *                    it is being overwritten during function call.
      * @exception DB::SqlConnection::Exception::InternalError on internal error
      * @exception DB::SqlConnection::Exception::ConstraintError on constraint violation
      */
-    void GetTizen2XAppsAndPackages(const std::string& origApp,
-         std::vector<std::string> &apps, std::vector<std::string> &packages);
+    void GetTizen2XPackages(std::vector<std::string> &packages);
 
     /* Retrive an id of an author from database
      *
index 7b72b9c..3254330 100644 (file)
@@ -448,31 +448,16 @@ void PrivilegeDb::GetTizen2XApps(const std::string& origApp, std::vector<std::st
      });
 }
 
-void PrivilegeDb::GetTizen2XAppsAndPackages(const std::string& origApp,
-    std::vector<std::string> &apps, std::vector<std::string> &packages)
+void PrivilegeDb::GetTizen2XPackages(std::vector<std::string> &packages)
 {
     try_catch<void>([&] {
-        {
-            auto command = getStatement(StmtType::EGetAllTizen2XApps);
-            command->BindString(1, origApp);
-            apps.clear();
-            while (command->Step()) {
-                const std::string & tizen2XApp = command->GetColumnString(0);
-                LogDebug("Found " << tizen2XApp << " Tizen 2.X apps installed");
-                apps.push_back(tizen2XApp);
-            };
-        }
-        // grouping the packages below (can not use the statement above)
-        {
-            auto command = getStatement(StmtType::EGetAllTizen2XPackages);
-            command->BindString(1, origApp);
-            packages.clear();
-            while (command->Step()) {
-                const std::string & tizen2XPkg = command->GetColumnString(0);
-                LogDebug("Found " << tizen2XPkg << " Tizen 2.X packages installed");
-                packages.push_back(tizen2XPkg);
-            };
-        }
+        auto command = getStatement(StmtType::EGetAllTizen2XPackages);
+        packages.clear();
+        while (command->Step()) {
+            const std::string & tizen2XPkg = command->GetColumnString(0);
+            LogDebug("Found " << tizen2XPkg << " Tizen 2.X packages installed");
+            packages.push_back(tizen2XPkg);
+        };
      });
 }
 
index a035875..9b9b0dc 100755 (executable)
@@ -422,8 +422,10 @@ int ServiceImpl::appInstall(const Credentials &creds, app_inst_req &&req)
         CynaraAdmin::getInstance().UpdateAppPolicy(appLabel, cynaraUserStr, req.privileges);
 
         // if app is targetted to Tizen 2.X, give other 2.X apps RO rules to it's shared dir
-        if(isTizen2XVersion(req.tizenVersion))
-            PrivilegeDb::getInstance().GetTizen2XAppsAndPackages(req.appName, allTizen2XApps, allTizen2XPackages);
+        if(isTizen2XVersion(req.tizenVersion)) {
+            PrivilegeDb::getInstance().GetTizen2XApps(req.appName, allTizen2XApps);
+            PrivilegeDb::getInstance().GetTizen2XPackages(allTizen2XPackages);
+        }
 
         // WTF? Why this commit is here? Shouldn't it be at the end of this function?
         PrivilegeDb::getInstance().CommitTransaction();