Block different type installation with same pkgid
[platform/core/appfw/app-installers.git] / src / common / step / pkgmgr / step_check_removable.cc
index 7dd0bc8..caf7c73 100644 (file)
@@ -4,9 +4,15 @@
 
 #include "common/step/pkgmgr/step_check_removable.h"
 
-#include <pkgmgr-info.h>
+#include <sys/types.h>
+#include <unistd.h>
 
-#include "common/app_installer.h"
+#include <string>
+#include <vector>
+
+#include "common/installer/app_installer.h"
+#include "common/pkgmgr_dependency.h"
+#include "common/utils/pkgmgr_query.h"
 
 namespace common_installer {
 namespace pkgmgr {
@@ -15,30 +21,21 @@ Step::Status StepCheckRemovable::process() {
   if (context_->force_remove.get())
       return Status::OK;
 
-  pkgmgrinfo_pkginfo_h handle;
-  int ret =
-      pkgmgrinfo_pkginfo_get_usr_all_pkginfo(context_->pkgid.get().c_str(),
-          context_->uid.get(), &handle);
-  if (ret != PMINFO_R_OK) {
+  PkgQueryInterface pkg_query(context_->pkgid.get().c_str(),
+      context_->uid.get());
+  if (!pkg_query.IsValid()) {
     LOG(ERROR) << "This package is not installed";
     return Status::INVALID_VALUE;
   }
-
-  bool removable;
-  ret = pkgmgrinfo_pkginfo_is_removable(handle, &removable);
-  if (ret != PMINFO_R_OK) {
-    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+  bool removable = pkg_query.IsRemovablePackage();
+  if (pkg_query.GetLastOperationError() != PMINFO_R_OK)
     return Status::INVALID_VALUE;
-  }
 
   if (!removable) {
     LOG(ERROR) << "This package is not removable";
-    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
     return Status::OPERATION_NOT_ALLOWED;
   }
 
-  pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-
   return Status::OK;
 }