From: Junghyun Yeon Date: Mon, 10 May 2021 09:32:33 +0000 (+0900) Subject: Implement FillPackageInfo X-Git-Tag: submit/tizen/20210617.070222~1^2~18 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=410d2b63b8cf733abec3c3db07223625c1d5c849;p=platform%2Fcore%2Fappfw%2Frpk-installer.git Implement FillPackageInfo Signed-off-by: Junghyun Yeon --- diff --git a/src/rpk/step/configuration/step_parse_rpk_manifest.cc b/src/rpk/step/configuration/step_parse_rpk_manifest.cc index b4eecb9..ec6a875 100644 --- a/src/rpk/step/configuration/step_parse_rpk_manifest.cc +++ b/src/rpk/step/configuration/step_parse_rpk_manifest.cc @@ -6,6 +6,8 @@ #include +#include + #include #include #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 info = + std::static_pointer_cast( + parser_->GetManifestData(kManifestFileName)); + + context_->pkgid.set(info->package()); + + manifest_x* manifest = + static_cast(calloc(1, sizeof(manifest_x))); + if (!manifest) { + LOG(ERROR) << "Out of memory"; + return Step::Status::ERROR; + } + + std::unique_ptr + manifest_auto(manifest, pkgmgr_parser_free_manifest_xml); + + if (!FillManifestX(const_cast(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 pkg_info = + std::static_pointer_cast( + 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 diff --git a/src/rpk/step/configuration/step_parse_rpk_manifest.h b/src/rpk/step/configuration/step_parse_rpk_manifest.h index 2b0824c..c75935b 100644 --- a/src/rpk/step/configuration/step_parse_rpk_manifest.h +++ b/src/rpk/step/configuration/step_parse_rpk_manifest.h @@ -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 parser_; ManifestLocation manifest_location_; StoreLocation store_location_;