Fix WgtArchiveInfo 47/236447/4
authorSangyoon Jang <jeremy.jang@samsung.com>
Wed, 17 Jun 2020 07:03:56 +0000 (16:03 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Wed, 17 Jun 2020 07:08:15 +0000 (16:08 +0900)
Allow addon only wgt package.

Change-Id: I78a2c71f6dbbed09e47d40f9c17ee5c5c313587c
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/lib/wgt_archive_info.cc
src/lib/wgt_archive_info.h

index 4f5a18b..df7efc2 100644 (file)
@@ -9,6 +9,7 @@
 #include <boost/filesystem/path.hpp>
 
 #include <wgt_manifest_handlers/widget_config_parser.h>
+#include <wgt_manifest_handlers/addon_handler.h>
 #include <wgt_manifest_handlers/application_icons_handler.h>
 #include <wgt_manifest_handlers/application_manifest_constants.h>
 #include <wgt_manifest_handlers/permissions_handler.h>
@@ -47,20 +48,44 @@ bool WgtArchiveInfo::GetPackageInfo(
   auto widget_info =
       std::static_pointer_cast<const wgt::parse::WidgetInfo>(
           parser.GetManifestData(wgt::parse::WidgetInfo::Key()));
+  if (!widget_info) {
+    LOG(ERROR) << "WidgetInfo not found";
+    return false;
+  }
+
+  type_ = "wgt";
+  version_ =  widget_info->version().c_str();
+  author_ = widget_info->author().c_str();
+
+  return true;
+}
+
+bool WgtArchiveInfo::GetApplicationInfo(
+    const wgt::parse::WidgetConfigParser& parser) {
   auto app_info =
       std::static_pointer_cast<const wgt::parse::TizenApplicationInfo>(
           parser.GetManifestData(wgt::parse::TizenApplicationInfo::Key()));
-  if (!widget_info || !app_info) {
-    LOG(ERROR) << "WidgetInfo / TizenApplicationInfo not found";
+  if (!app_info)
     return false;
-  }
 
-  type_ = "wgt";
   name_ = app_info->package().c_str();
   pkgid_ = app_info->package().c_str();
-  version_ =  widget_info->version().c_str();
   api_version_ = app_info->required_version().c_str();
-  author_ = widget_info->author().c_str();
+
+  return true;
+}
+
+bool WgtArchiveInfo::GetAddonInfo(
+    const wgt::parse::WidgetConfigParser& parser) {
+  auto addon_info =
+      std::static_pointer_cast<const wgt::parse::AddonInfo>(
+          parser.GetManifestData(wgt::parse::AddonInfo::Key()));
+  if (!addon_info)
+    return false;
+
+  name_ = addon_info->package().c_str();
+  pkgid_ = addon_info->package().c_str();
+  api_version_ = addon_info->required_version().c_str();
 
   return true;
 }
@@ -203,6 +228,15 @@ bool WgtArchiveInfo::LoadArchiveInfo() {
     bf::remove_all(tmp_dir);
     return false;
   }
+  if (!GetApplicationInfo(parser)) {
+    if (!GetAddonInfo(parser)) {
+      LOG(ERROR) << "Failed to get application info nor addon info. "
+                 << "At least one of them must exist";
+      bf::remove_all(tmp_dir);
+      return false;
+    }
+  }
+
   if (!GetPrivilegesInfo(parser))
     LOG(WARNING) << "Failed to get privileges info";
   if (!GetIconInfo(parser))
index 085bb47..debc32c 100644 (file)
@@ -23,6 +23,8 @@ class WgtArchiveInfo : public common_installer::ArchiveInfo {
 
  private:
   bool GetPackageInfo(const wgt::parse::WidgetConfigParser& parser);
+  bool GetApplicationInfo(const wgt::parse::WidgetConfigParser& parser);
+  bool GetAddonInfo(const wgt::parse::WidgetConfigParser& parser);
   bool GetPrivilegesInfo(const wgt::parse::WidgetConfigParser& parser);
   bool GetIconInfo(const wgt::parse::WidgetConfigParser& parser);
   bool ReadIcon(const bf::path& icon, const bf::path& tmp_dir);