Implement FillPackageInfo
authorJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 10 May 2021 09:32:33 +0000 (18:32 +0900)
committer연정현/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <jungh.yeon@samsung.com>
Wed, 12 May 2021 07:12:49 +0000 (16:12 +0900)
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/rpk/step/configuration/step_parse_rpk_manifest.cc
src/rpk/step/configuration/step_parse_rpk_manifest.h

index b4eecb9..ec6a875 100644 (file)
@@ -6,6 +6,8 @@
 
 #include <pkgmgr-info.h>
 
+#include <rpk_manifest_handlers/package_handler.h>
+
 #include <common/installer_context.h>
 #include <common/step/step.h>
 #include "common/utils/paths.h"
@@ -60,6 +62,50 @@ common_installer::Step::Status StepParseRpkManifest::process() {
     return Step::Status::PARSE_ERROR;
   }
 
+  // Copy data from ManifestData to InstallerContext
+  std::shared_ptr<const rpk::parse::PackageInfo> info =
+      std::static_pointer_cast<const rpk::parse::PackageInfo>(
+          parser_->GetManifestData(kManifestFileName));
+
+  context_->pkgid.set(info->package());
+
+  manifest_x* manifest =
+      static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)));
+  if (!manifest) {
+    LOG(ERROR) << "Out of memory";
+    return Step::Status::ERROR;
+  }
+
+  std::unique_ptr<manifest_x, decltype(pkgmgr_parser_free_manifest_xml)*>
+      manifest_auto(manifest, pkgmgr_parser_free_manifest_xml);
+
+  if (!FillManifestX(const_cast<manifest_x*>(manifest))) {
+    LOG(ERROR) << "[Parse] Storing manifest_x failed. "
+               <<  parser_->GetErrorMessage();
+    return Step::Status::PARSE_ERROR;
+  }
+/*
+  // TODO: add this code when recovery logic has added
+  // write pkgid for recovery file
+  if (context_->recovery_info.get().recovery_file) {
+    context_->recovery_info.get().recovery_file->set_pkgid(manifest->package);
+    context_->recovery_info.get().recovery_file->WriteAndCommitFileContent();
+  }
+*/
+  LOG(INFO) << "Parsed package id: " << info->package();
+
+  switch (store_location_) {
+    case StoreLocation::NORMAL:
+      context_->manifest_data.set(manifest_auto.release());
+      break;
+    case StoreLocation::BACKUP:
+      context_->old_manifest_data.set(manifest_auto.release());
+      break;
+    default:
+      LOG(ERROR) << "Unknown store location for parsed data";
+      return Step::Status::ERROR;
+  }
+
   return common_installer::Step::Status::OK;
 }
 
@@ -129,5 +175,33 @@ bool StepParseRpkManifest::LocateConfigFile() {
   return true;
 }
 
+bool StepParseRpkManifest::FillManifestX(manifest_x* manifest) {
+  if (!FillPackageInfo(manifest))
+    return false;
+  return true;
+}
+
+bool StepParseRpkManifest::FillPackageInfo(manifest_x* manifest) {
+  std::shared_ptr<const rpk::parse::PackageInfo> pkg_info =
+      std::static_pointer_cast<const rpk::parse::PackageInfo>(
+          parser_->GetManifestData(kManifestFileName));
+  if (!pkg_info) {
+    LOG(ERROR) << "Package info manifest data has not been found.";
+    return false;
+  }
+
+  manifest->ns = strdup(pkg_info->xmlns().c_str());
+  manifest->package = strdup(pkg_info->package().c_str());
+  manifest->version = strdup(pkg_info->version().c_str());
+
+/*
+  // TODO: add this code when manifest has variables for these
+  manifest->res_type = strdup(pkg_info->res_type().c_str());
+  manifest->res_version = strdup(pkg_info->res_version().c_str());
+*/
+
+  return true;
+}
+
 }  // namespace configuration
 }  // namespace rpk
index 2b0824c..c75935b 100644 (file)
@@ -47,6 +47,9 @@ class StepParseRpkManifest : public common_installer::Step {
   Status precheck() override;
 
  private:
+  bool FillManifestX(manifest_x* manifest);
+  bool FillPackageInfo(manifest_x* manifest);
+
   std::unique_ptr<rpk::parse::RPKConfigParser> parser_;
   ManifestLocation manifest_location_;
   StoreLocation store_location_;