From 19aa13487aacae24fd9de80a5e3f681f8d2c6250 Mon Sep 17 00:00:00 2001 From: Lukasz Pawelczyk Date: Thu, 12 May 2016 12:56:11 +0200 Subject: [PATCH] Cleanup around Tizen2X apps/packages generation functions 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 | 11 +++-------- src/common/privilege_db.cpp | 31 ++++++++----------------------- src/common/service_impl.cpp | 6 ++++-- 3 files changed, 15 insertions(+), 33 deletions(-) diff --git a/src/common/include/privilege_db.h b/src/common/include/privilege_db.h index 415e4c9..05ffb23 100644 --- a/src/common/include/privilege_db.h +++ b/src/common/include/privilege_db.h @@ -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 &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 &apps, std::vector &packages); + void GetTizen2XPackages(std::vector &packages); /* Retrive an id of an author from database * diff --git a/src/common/privilege_db.cpp b/src/common/privilege_db.cpp index 7b72b9c..3254330 100644 --- a/src/common/privilege_db.cpp +++ b/src/common/privilege_db.cpp @@ -448,31 +448,16 @@ void PrivilegeDb::GetTizen2XApps(const std::string& origApp, std::vector &apps, std::vector &packages) +void PrivilegeDb::GetTizen2XPackages(std::vector &packages) { try_catch([&] { - { - 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); + }; }); } diff --git a/src/common/service_impl.cpp b/src/common/service_impl.cpp index a035875..9b9b0dc 100755 --- a/src/common/service_impl.cpp +++ b/src/common/service_impl.cpp @@ -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(); -- 2.7.4