Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / step / pkgmgr / step_check_force_clean.cc
index b4dcf97..f826924 100644 (file)
 #include <pkgmgr-info.h>
 #include <tzplatform_config.h>
 
-#include <boost/filesystem.hpp>
-#include <boost/filesystem/path.hpp>
+#include <filesystem>
 
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/installer_context.h"
+#include "common/utils/manifest_util.h"
 
-namespace bf = boost::filesystem;
+namespace fs = std::filesystem;
 
-namespace {
-
-int PkgmgrAppInfoCallback(const pkgmgrinfo_appinfo_h handle,
-                              void *user_data) {
-  manifest_x *mfx = static_cast<manifest_x*>(user_data);
-  application_x* application =
-          static_cast<application_x*>(calloc(1, sizeof(application_x)));
-  if (!application)
-    return PMINFO_R_ERROR;
-
-  char* app_id = nullptr;
-  if (pkgmgrinfo_appinfo_get_appid(handle, &app_id))
-    return PMINFO_R_ERROR;
-
-  icon_x* icon = static_cast<icon_x*>(calloc(1, sizeof(icon_x)));
-  if (!icon)
-    return PMINFO_R_ERROR;
-
-  char* icon_text = nullptr;
-  if (pkgmgrinfo_appinfo_get_icon(handle, &icon_text))
-    return PMINFO_R_ERROR;
-
-  if (!mfx->root_path) {
-    char *root_path = nullptr;
-    if (pkgmgrinfo_appinfo_get_root_path(handle, &root_path))
-      return PMINFO_R_ERROR;
-    mfx->root_path = strdup(root_path);
-  }
-
-  application->appid = strdup(app_id);
-  icon->text = strdup(icon_text);
-  application->icon = g_list_append(application->icon, icon);
-  mfx->application = g_list_append(mfx->application, application);
-
-  return PMINFO_R_OK;
-}
-
-int PkgmgrGenerateManifestInfoFromDB(manifest_x *mfx,
-                                     const char *pkgid, uid_t uid) {
-  pkgmgrinfo_appinfo_filter_h filter;
-  mfx->package = strdup(pkgid);
-
-  if (pkgmgrinfo_appinfo_filter_create(&filter))
-    return PMINFO_R_ERROR;
-
-  if (pkgmgrinfo_appinfo_filter_add_string(filter,
-                          PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
-    pkgmgrinfo_appinfo_filter_destroy(filter);
-    return PMINFO_R_ERROR;
-  }
-
-  if (pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(filter,
-                          PkgmgrAppInfoCallback, mfx, uid)) {
-    pkgmgrinfo_appinfo_filter_destroy(filter);
-    return PMINFO_R_ERROR;
-  }
-
-  pkgmgrinfo_appinfo_filter_destroy(filter);
-
-  return PMINFO_R_OK;
-}
-
-}  // namespace
 
 namespace common_installer {
 namespace pkgmgr {
 
 Step::Status StepCheckForceClean::process() {
-  if (context_->request_type.get() != RequestType::Uninstall)
+  if (context_->request_type.get() != RequestType::Uninstall &&
+      context_->request_type.get() != RequestType::PartialUninstall)
     return Status::OK;
 
-  uid_t uid;
-  bool is_readonly;
-  if (QueryIsGlobalPackage(context_->pkgid.get(), context_->uid.get())) {
-    uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
-    is_readonly = QueryIsReadonlyPackage(context_->pkgid.get(),
-                                        context_->uid.get());
-  } else {
-    uid = context_->uid.get();
-    is_readonly = context_->is_readonly_package.get();
-  }
-  bf::path xml_path = bf::path(getUserManifestPath(uid, is_readonly))
-                      / bf::path(context_->pkgid.get());
-  xml_path += ".xml";
+  fs::path xml_path = GetManifestLocation(context_->pkgid.get(),
+                                          context_->uid.get(),
+                                          context_->is_readonly_package.get());
 
   // if manifeset not found but pkg exist in db for target uid, do clean
-  if (!bf::exists(xml_path) &&
-      QueryIsPackageInstalled(context_->pkgid.get(), context_->uid.get())) {
+  PkgQueryInterface pkg_query(context_->pkgid.get(), context_->uid.get());
+  if (!fs::exists(xml_path) &&
+      pkg_query.IsPackageInstalled()) {
     context_->force_clean_from_db.set(true);
-    manifest_x* manifest =
-        static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)));
-    if (!PkgmgrGenerateManifestInfoFromDB(manifest,
-            reinterpret_cast<const char*>(context_->pkgid.get().c_str()),
-            context_->uid.get())) {
-      context_->manifest_data.set(manifest);
-      context_->pkg_path.set(manifest->root_path);
+    manifest_x* manifest = PkgmgrGenerateManifestInfoFromDB(
+        context_->pkgid.get(), context_->uid.get());
+    if (!manifest) {
+      LOG(ERROR) << "Failed to get manifest_x from DB";
+      return Status::ERROR;
     }
+
+    context_->manifest_data.set(manifest);
   }
 
   return Status::OK;