Fix finding mainfest location 52/91352/1
authorSangyoon Jang <s89.jang@samsung.com>
Fri, 7 Oct 2016 06:16:06 +0000 (15:16 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Fri, 7 Oct 2016 06:22:45 +0000 (15:22 +0900)
This patch fixes issue when the installer try to find location of
installed manifest of global package.

Added pkgmgr query helper functions:
  QueryIsGlobalPackage, QueryIsPreloadPackage

Change-Id: I6284dfe61515b937fbcda234b978feba897a8221
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
src/common/pkgmgr_query.cc
src/common/pkgmgr_query.h
src/common/step/configuration/step_parse_manifest.cc

index aa8afaea98265dc91d68b1fa118765bed51a1335..691c343461b4a59e9dbdc250416fd189489a1519 100644 (file)
@@ -215,4 +215,44 @@ bool QueryIsPackageInstalled(const std::string& pkg_id, uid_t uid) {
   return true;
 }
 
+bool QueryIsGlobalPackage(const std::string& pkg_id, uid_t uid) {
+  pkgmgrinfo_pkginfo_h handle;
+  int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkg_id.c_str(), uid, &handle);
+  if (ret != PMINFO_R_OK) {
+    if (ret != PMINFO_R_ENOENT)
+      LOG(ERROR) << "Failed to call pkgmgrinfo_pkginfo_get_usr_pkginfo";
+    return false;
+  }
+
+  bool is_global = false;
+  if (pkgmgrinfo_pkginfo_is_for_all_users(handle, &is_global) != PMINFO_R_OK) {
+    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_for_all_users failed";
+    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+    return false;
+  }
+
+  pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+  return is_global;
+}
+
+bool QueryIsPreloadPackage(const std::string& pkg_id, uid_t uid) {
+  pkgmgrinfo_pkginfo_h handle;
+  int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkg_id.c_str(), uid, &handle);
+  if (ret != PMINFO_R_OK) {
+    if (ret != PMINFO_R_ENOENT)
+      LOG(ERROR) << "Failed to call pkgmgrinfo_pkginfo_get_usr_pkginfo";
+    return false;
+  }
+
+  bool is_preload = false;
+  if (pkgmgrinfo_pkginfo_is_preload(handle, &is_preload) != PMINFO_R_OK) {
+    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_preload failed";
+    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+    return false;
+  }
+
+  pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+  return is_preload;
+}
+
 }  // namespace common_installer
index 16a705f1a5af33cfdca5562ea99e9c21e7e95b46..b2b39e3d366b920befec18fa80064e06686384f5 100644 (file)
@@ -107,6 +107,28 @@ bool QueryIsPackageInstalled(const std::string& pkg_id,
  */
 bool QueryIsPackageInstalled(const std::string& pkg_id, uid_t uid);
 
+/**
+ * \brief Adapter interface for external PkgMgr module used for checking
+ *        if given package is global package
+ *
+ * \param pkg_id package id
+ * \param uid user id
+ *
+ * \return true if package is global package
+ */
+bool QueryIsGlobalPackage(const std::string& pkg_id, uid_t uid);
+
+/**
+ * \brief Adapter interface for external PkgMgr module used for checking
+ *        if given package is preloaded package
+ *
+ * \param pkg_id package id
+ * \param uid user id
+ *
+ * \return true if package is preloaded
+ */
+bool QueryIsPreloadPackage(const std::string& pkg_id, uid_t uid);
+
 }  // namespace common_installer
 
 #endif  // COMMON_PKGMGR_QUERY_H_
index 727a99d65927b2668f954070f848feae921e51d2..215e69e10ffc7bb949fab742ec1781fb9df2883d 100644 (file)
@@ -105,9 +105,18 @@ bool StepParseManifest::LocateConfigFile() {
       break;
     }
     case ManifestLocation::INSTALLED: {
+      uid_t uid;
+      bool is_preload;
+      if (QueryIsGlobalPackage(context_->pkgid.get(), context_->uid.get())) {
+        uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+        is_preload = QueryIsPreloadPackage(context_->pkgid.get(),
+            context_->uid.get());
+      } else {
+        uid = context_->uid.get();
+        is_preload = context_->is_preload_request.get();
+      }
       bf::path xml_path =
-          bf::path(getUserManifestPath(context_->uid.get(),
-              context_->is_preload_request.get()))
+          bf::path(getUserManifestPath(uid, is_preload))
           / bf::path(context_->pkgid.get());
       xml_path += ".xml";
       context_->xml_path.set(xml_path);