Write preload attribute in application manifest 26/58626/4
authorLukasz Wysocki <l.wysocki@samsung.com>
Tue, 2 Feb 2016 09:03:03 +0000 (10:03 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Tue, 2 Feb 2016 10:15:09 +0000 (02:15 -0800)
Change-Id: Ic08b466f1cbedcf62e23f4f85386a00eb4e72496

src/tpk/CMakeLists.txt
src/tpk/step/step_manifest_adjustment.cc [new file with mode: 0644]
src/tpk/step/step_manifest_adjustment.h [new file with mode: 0644]
src/tpk/tpk_installer.cc

index 671f57a..a2b133f 100644 (file)
@@ -4,6 +4,7 @@ SET(SRCS
     step/step_parse_preload.cc
     step/step_convert_xml.cc
     step/step_tpk_patch_icons.cc
+    step/step_manifest_adjustment.cc
     tpk_app_query_interface.cc
     tpk_installer.cc
 )
diff --git a/src/tpk/step/step_manifest_adjustment.cc b/src/tpk/step/step_manifest_adjustment.cc
new file mode 100644 (file)
index 0000000..7777e68
--- /dev/null
@@ -0,0 +1,74 @@
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "tpk/step/step_manifest_adjustment.h"
+
+#include <boost/filesystem/path.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
+
+namespace bs = boost::system;
+namespace bf = boost::filesystem;
+
+using libxml_char = const unsigned char *;
+
+namespace tpk {
+namespace pkgmgr {
+
+common_installer::Step::Status StepManifestAdjustment::precheck() {
+  bf::path xml_path = context_->xml_path.get();
+
+  if (!bf::exists(xml_path)) {
+    LOG(ERROR) << "Cannot find manifest file at " << xml_path;
+    return Step::Status::ERROR;
+  }
+
+  xml_path_ = xml_path;
+
+  return Step::Status::OK;
+}
+
+common_installer::Step::Status StepManifestAdjustment::process() {
+  xmlDocPtr doc = xmlParseFile(xml_path_.c_str());
+
+  if (doc == nullptr) {
+    LOG(ERROR) << "Could not parse file";
+    return Step::Status::ERROR;
+  }
+
+  xmlNodePtr node = xmlDocGetRootElement(doc);
+
+  std::string preload_attrib = "preload";
+  auto attrib = xmlSetProp(node,
+      reinterpret_cast<libxml_char>(preload_attrib.c_str()),
+      reinterpret_cast<libxml_char>(context_->manifest_data.get()->preload));
+
+  if (attrib == nullptr) {
+    LOG(ERROR) << "Failed to set attribute preload";
+    return Step::Status::ERROR;
+  }
+
+  if (xmlSaveFile(xml_path_.c_str(), doc) == -1) {
+    LOG(ERROR) << "Failed to modify xml file";
+    return Step::Status::ERROR;
+  }
+
+  xmlFreeDoc(doc);
+
+  return Step::Status::OK;
+}
+
+common_installer::Step::Status StepManifestAdjustment::clean() {
+  return Step::Status::OK;
+}
+
+common_installer::Step::Status StepManifestAdjustment::undo() {
+  return Step::Status::OK;
+}
+
+}  // namespace pkgmgr
+}  // namespace tpk
diff --git a/src/tpk/step/step_manifest_adjustment.h b/src/tpk/step/step_manifest_adjustment.h
new file mode 100644 (file)
index 0000000..31f3314
--- /dev/null
@@ -0,0 +1,35 @@
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef TPK_STEP_STEP_MANIFEST_ADJUSTMENT_H_
+#define TPK_STEP_STEP_MANIFEST_ADJUSTMENT_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include <boost/filesystem/path.hpp>
+
+#include <common/step/step.h>
+
+namespace tpk {
+namespace pkgmgr {
+
+class StepManifestAdjustment : public common_installer::Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+  Status clean() override;
+  Status undo() override;
+  Status precheck() override;
+
+ private:
+  boost::filesystem::path xml_path_;
+
+  SCOPE_LOG_TAG(StepManifestAdjustment)
+};
+
+}  // namespace pkgmgr
+}  // namespace tpk
+
+#endif  // TPK_STEP_STEP_MANIFEST_ADJUSTMENT_H_
index 97674fb..8b90175 100644 (file)
@@ -40,6 +40,7 @@
 #include <common/step/step_update_tep.h>
 #include "tpk/step/step_check_tpk_background_category.h"
 #include "tpk/step/step_create_symbolic_link.h"
+#include "tpk/step/step_manifest_adjustment.h"
 #include "tpk/step/step_parse_preload.h"
 #include "tpk/step/step_convert_xml.h"
 #include "tpk/step/step_tpk_patch_icons.h"
@@ -213,6 +214,7 @@ void TpkInstaller::ManifestDirectInstallSteps() {
       ci::parse::StepParseManifest::ManifestLocation::INSTALLED,
       ci::parse::StepParseManifest::StoreLocation::NORMAL);
   AddStep<ci::tpk::StepParsePreload>();
+  AddStep<tpk::pkgmgr::StepManifestAdjustment>();
   AddStep<ci::security::StepPrivilegeCompatibility>();
   AddStep<tpk::security::StepCheckTpkBackgroundCategory>();
   AddStep<tpk::filesystem::StepTpkPatchIcons>();
@@ -227,6 +229,7 @@ void TpkInstaller::ManifestDirectUpdateSteps() {
       ci::parse::StepParseManifest::ManifestLocation::INSTALLED,
       ci::parse::StepParseManifest::StoreLocation::NORMAL);
   AddStep<ci::tpk::StepParsePreload>();
+  AddStep<tpk::pkgmgr::StepManifestAdjustment>();
   AddStep<ci::security::StepPrivilegeCompatibility>();
   AddStep<tpk::security::StepCheckTpkBackgroundCategory>();
   AddStep<tpk::filesystem::StepTpkPatchIcons>();