Implement LocateConfigFile()
authorJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 10 May 2021 08:18:32 +0000 (17:18 +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 c33946e..de24fad 100644 (file)
@@ -4,8 +4,21 @@
 
 #include "step/configuration/step_parse_rpk_manifest.h"
 
+#include <pkgmgr-info.h>
+
 #include <common/installer_context.h>
 #include <common/step/step.h>
+#include "common/utils/paths.h"
+#include "common/utils/pkgmgr_query.h"
+
+namespace bf = boost::filesystem;
+
+namespace {
+
+const char kManifestFileName[] = "tizen-manifest.xml";
+
+}  // namespace
+
 
 namespace rpk {
 namespace configuration {
@@ -27,5 +40,71 @@ common_installer::Step::Status StepParseRpkManifest::process() {
   return common_installer::Step::Status::OK;
 }
 
+bool StepParseRpkManifest::LocateConfigFile() {
+  boost::filesystem::path manifest;
+  switch (manifest_location_) {
+    case ManifestLocation::RECOVERY: {
+      bf::path backup_path = common_installer::GetBackupPathForPackagePath(
+          context_->GetPkgPath()) / kManifestFileName;
+      bf::path in_package_path = context_->GetPkgPath() / kManifestFileName;
+      bf::path install_path =
+          bf::path(getUserManifestPath(context_->uid.get(),
+                      context_->is_readonly_package.get()))
+              / bf::path(context_->pkgid.get());
+      install_path += ".xml";
+      bf::path backup_install_path =
+          common_installer::GetBackupPathForManifestFile(install_path);
+      if (bf::exists(backup_install_path))
+        manifest = backup_install_path;
+      else if (bf::exists(backup_path))
+        manifest = backup_path;
+      else if (bf::exists(install_path))
+        manifest = install_path;
+      else if (bf::exists(in_package_path))
+        manifest = in_package_path;
+      break;
+    }
+    case ManifestLocation::INSTALLED: {
+      uid_t uid;
+      bool is_readonly = context_->is_readonly_package.get();
+      common_installer::PkgQueryInterface pkg_query(
+          context_->pkgid.get(), context_->uid.get());
+      if (pkg_query.IsGlobalPackage())
+        uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+      else
+        uid = context_->uid.get();
+      bf::path xml_path =
+          bf::path(getUserManifestPath(uid, is_readonly))
+          / bf::path(context_->pkgid.get());
+      xml_path += ".xml";
+      context_->xml_path.set(xml_path);
+      manifest = context_->xml_path.get();
+      if (!boost::filesystem::exists(manifest)) {
+        /* This routine has added for platform update */
+        manifest = context_->unpacked_dir_path.get();
+        manifest /= kManifestFileName;
+      }
+      break;
+    }
+    case ManifestLocation::PACKAGE: {
+      manifest = context_->unpacked_dir_path.get();
+      manifest /= kManifestFileName;
+      break;
+    }
+    default: {
+      LOG(ERROR) << "Unknown manifest location value";
+      return false;
+    }
+  }
+
+  LOG(DEBUG) << "manifest path: " << manifest;
+
+  if (!boost::filesystem::exists(manifest))
+    return false;
+
+  path_ = manifest;
+  return true;
+}
+
 }  // namespace configuration
 }  // namespace rpk
index 61c5fba..1f70cfe 100644 (file)
@@ -37,6 +37,10 @@ class StepParseRpkManifest : public common_installer::Step {
   explicit StepParseRpkManifest(common_installer::InstallerContext* context,
       ManifestLocation manifest_location, StoreLocation store_location);
 
+ protected:
+  bool LocateConfigFile();
+  boost::filesystem::path path_;
+
   Status process() override;
   Status clean() override { return Status::OK; }
   Status undo() override { return Status::OK; }