Add GetDependencyInfo at TPK archive info 15/211115/4
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 30 Jul 2019 07:50:09 +0000 (16:50 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 14 Aug 2019 04:43:35 +0000 (04:43 +0000)
Related changes:
[slp-pkgmgr] : https://review.tizen.org/gerrit/211114
[pkgmgr-info] : https://review.tizen.org/gerrit/211111

Change-Id: I7c8fd6dcf8be0387c7fcd98f8018f0174044b873
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/lib/tpk_archive_info.cc

index 9437413..a181a51 100644 (file)
@@ -13,6 +13,7 @@
 #include <tpk_manifest_handlers/tpk_config_parser.h>
 #include <tpk_manifest_handlers/application_manifest_constants.h>
 #include <tpk_manifest_handlers/author_handler.h>
+#include <tpk_manifest_handlers/dependencies_handler.h>
 #include <tpk_manifest_handlers/description_handler.h>
 #include <tpk_manifest_handlers/package_handler.h>
 #include <tpk_manifest_handlers/privileges_handler.h>
@@ -99,6 +100,33 @@ bool GetPrivilegesInfo(const tpk::parse::TPKConfigParser& parser,
   return true;
 }
 
+bool GetDependencyInfo(const tpk::parse::TPKConfigParser& parser,
+    package_manager_pkg_detail_info_t* info) {
+  auto dependencies_info =
+      std::static_pointer_cast<const tpk::parse::DependenciesInfo>(
+          parser.GetManifestData(tpk::application_keys::kDependenciesKey));
+  if (!dependencies_info)
+    return true;
+
+  for (const auto& dependency : dependencies_info->dependencies()) {
+    pkg_dependency_info_t* dep =
+        static_cast<pkg_dependency_info_t*>
+        (calloc(1, sizeof(pkg_dependency_info_t)));
+    if (!dep) {
+      LOG(ERROR) << "Out of memory";
+      return false;
+    }
+    snprintf(dep->pkgid, sizeof(dep->pkgid), "%s", dependency.pkgid().c_str());
+    snprintf(dep->type, sizeof(dep->type), "%s", dependency.type().c_str());
+    if (!dependency.type().empty())
+      snprintf(dep->required_version,
+          sizeof(dep->required_version), "%s",
+          dependency.required_version().c_str());
+    info->dependency_list = g_list_append(info->dependency_list, dep);
+  }
+  return true;
+}
+
 template <typename T>
 bool GetAppLabel(const tpk::parse::TPKConfigParser& parser,
     const std::string& key, const char* locale,
@@ -307,6 +335,8 @@ bool TpkArchiveInfo::GetArchiveInfo(const char* file_path,
     LOG(WARNING) << "Failed to get author info";
   if (!GetPrivilegesInfo(parser, info))
     LOG(WARNING) << "Failed to get privilege info";
+  if (!GetDependencyInfo(parser, info))
+    LOG(WARNING) << "Failed to get dependency info";
 
   char* locale = vconf_get_str(kVconfLanguageKey);
   if (!locale)