Separate IsPackageInstalled() 79/160479/1
authorSeungha Son <seungha.son@samsung.com>
Tue, 24 Oct 2017 11:36:20 +0000 (20:36 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 16 Nov 2017 08:18:27 +0000 (17:18 +0900)
Separate the method of checking whether it is installed only and how to
check whether the installed or not as ReqeustMode.

related patch : https://review.tizen.org/gerrit/#/c/158632/

Signed-off-by: Seungha Son <seungha.son@samsung.com>
Change-Id: I62f7e7c6c30cda101cc0856fc057431552837dfb

src/common/pkgmgr_query.cc
src/common/pkgmgr_query.h
src/common/pkgmgr_signal.cc
src/common/step/pkgmgr/step_check_force_clean.cc
src/common/step/pkgmgr/step_check_installable.cc

index 5d7240d..eb5fec0 100644 (file)
@@ -113,8 +113,11 @@ std::string PkgQueryInterface::StorageForPkgId() {
   return installed_location;
 }
 
-bool PkgQueryInterface::IsPackageInstalled(RequestMode request_mode
-                                      /* = RequestMode::USER */) {
+bool PkgQueryInterface::IsPackageInstalled() {
+  return IsValid();
+}
+
+bool PkgQueryInterface::IsPackageInstalled(RequestMode mode) {
   if (!IsValid())
     return false;
   bool is_global = false;
@@ -122,10 +125,10 @@ bool PkgQueryInterface::IsPackageInstalled(RequestMode request_mode
     LOG(ERROR) << "pkgmgrinfo_pkginfo_is_for_all_users failed";
     return false;
   }
-  if ((request_mode != RequestMode::GLOBAL) && is_global)
-    return false;
 
-  if ((uid_ != kGlobalUserUid) && is_global)
+  if (mode == RequestMode::GLOBAL && !is_global)
+    return false;
+  if (mode == RequestMode::USER && is_global)
     return false;
 
   return true;
index ed360f6..f372b1b 100644 (file)
@@ -50,11 +50,18 @@ class PkgQueryInterface {
   /**
    * \brief Checks if given package is installed/registered.
    *
-   * \param request_mode request mode
+   * \return true if package is installed
+   */
+  bool IsPackageInstalled();
+
+  /**
+   * \brief Checks if given package is installed/registered as request mode.
+   *
+   * \param mode request mode
    *
    * \return true if package is installed
    */
-  bool IsPackageInstalled(RequestMode request_mode = RequestMode::USER);
+  bool IsPackageInstalled(RequestMode mode);
 
   /**
    * \brief Checks if given package is global package.
index c74eb6e..d544423 100644 (file)
@@ -269,7 +269,7 @@ bool PkgmgrSignal::SetupUserList(const std::string& pkgid) {
     switch (request_mode_) {
       case RequestMode::GLOBAL:
         // if user pkg is installed, installer will not send signal to user.
-        if (pkg_query.IsPackageInstalled(RequestMode::USER))
+        if (pkg_query.IsPackageInstalled(ci::RequestMode::USER))
           continue;
         else
           user_list_.emplace_back(uids[i], request_type_);
@@ -279,7 +279,7 @@ bool PkgmgrSignal::SetupUserList(const std::string& pkgid) {
           continue;
         // if global pkg is installed,
         // user pkg operation will be handled as update.
-        if (pkg_query_for_global.IsPackageInstalled())
+        if (pkg_query_for_global.IsPackageInstalled(ci::RequestMode::GLOBAL))
           user_list_.emplace_back(uids[i], RequestType::Update);
         else
           user_list_.emplace_back(uids[i], request_type_);
index b9d9268..90be356 100644 (file)
@@ -33,7 +33,7 @@ Step::Status StepCheckForceClean::process() {
   // if manifeset not found but pkg exist in db for target uid, do clean
   PkgQueryInterface pkg_query(context_->pkgid.get(), context_->uid.get());
   if (!bf::exists(xml_path) &&
-      pkg_query.IsPackageInstalled(context_->request_mode.get())) {
+      pkg_query.IsPackageInstalled()) {
     context_->force_clean_from_db.set(true);
     manifest_x* manifest =
         static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)));
index 863071c..17eef26 100644 (file)
@@ -24,7 +24,7 @@ Step::Status StepCheckInstallable::process() {
   switch (context_->request_mode.get()) {
     case RequestMode::USER: {
       PkgQueryInterface pkg_query(context_->pkgid.get(), kGlobalUserUid);
-      if (pkg_query.IsPackageInstalled()) {
+      if (pkg_query.IsPackageInstalled(RequestMode::GLOBAL)) {
         LOG(ERROR) << "This package is already installed as global package";
         return Status::OPERATION_NOT_ALLOWED;
       }
@@ -35,7 +35,7 @@ Step::Status StepCheckInstallable::process() {
       for (auto l : list) {
         uid_t uid = std::get<0>(l);
         PkgQueryInterface pkg_query(context_->pkgid.get(), uid);
-        if (pkg_query.IsPackageInstalled()) {
+        if (pkg_query.IsPackageInstalled(RequestMode::USER)) {
           LOG(ERROR) << "This package is already installed by user("
                      << uid << ")";
           return Status::OPERATION_NOT_ALLOWED;