Recovery for tpk backend 41/46141/3
authorTomasz Iwanek <t.iwanek@samsung.com>
Fri, 14 Aug 2015 08:04:49 +0000 (10:04 +0200)
committerPawel Sikorski <p.sikorski@samsung.com>
Wed, 19 Aug 2015 08:24:07 +0000 (01:24 -0700)
Change-Id: I8d0ec4bd539cc2227ce582a9c291a87e17b1f2e1

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

index 6b3a2e5..19c3260 100644 (file)
@@ -1,7 +1,8 @@
 SET(SRCS
-    step/step_parse.cc
     step/step_create_symbolic_link.cc
     step/step_copy_manifest_xml.cc
+    step/step_parse.cc
+    step/step_parse_recovery.cc
     tpk_app_query_interface.cc
     tpk_installer.cc
     xml_parser/xml_parser.cc
index 952120b..9729209 100644 (file)
@@ -7,7 +7,6 @@
 #include <vector>
 #include "common/context_installer.h"
 #include "common/step/step.h"
-#include "common/utils/logging.h"
 
 using std::vector;
 using std::string;
@@ -15,6 +14,7 @@ using xml_parser::XmlParser;
 using xml_parser::XmlTree;
 using xml_parser::XmlElement;
 
+namespace bf = boost::filesystem;
 namespace ci = common_installer;
 
 namespace tpk {
@@ -93,18 +93,23 @@ Status StepParse::precheck() {
   return Step::Status::OK;
 }
 
+bf::path StepParse::LocateConfigFile() const {
+  boost::filesystem::path path(context_->unpacked_dir_path.get());
+  path /= kManifestFileName;
+  return path;
+}
+
 /* process()
  * Parse tizen-manifest.xml and get the data from it
  * Store the data into the context_
  */
 Status StepParse::process() {
-  boost::filesystem::path mPath(context_->unpacked_dir_path.get());
-  mPath /= kManifestFileName;
+  bf::path m_path = LocateConfigFile();
 
-  LOG(INFO) << "Parse " << mPath.c_str();
+  LOG(INFO) << "Parse " << m_path.c_str();
 
   XmlParser parser;
-  std::unique_ptr<XmlTree> tree(parser.ParseAndGetNewTree(mPath.c_str()));
+  std::unique_ptr<XmlTree> tree(parser.ParseAndGetNewTree(m_path.c_str()));
   if (tree == nullptr) {
     LOG(ERROR) << "Failure on parsing xml";
     return Status::ERROR;
index bc79d3a..ab98cc6 100644 (file)
@@ -18,6 +18,9 @@ class StepParse : public common_installer::Step {
   Status undo()     override { return Status::OK; };
   Status precheck() override;
 
+ protected:
+  virtual boost::filesystem::path LocateConfigFile() const;
+
  private:
   bool SetContextByManifestParser(xml_parser::XmlTree* tree);
   bool SetPkgInfoManifest(manifest_x* m,
@@ -25,7 +28,7 @@ class StepParse : public common_installer::Step {
   bool SetPkgInfoChildren(manifest_x *m,
       xml_parser::XmlTree *tree, xml_parser::XmlElement* manifest);
 
-  SCOPE_LOG_TAG(StepParse)
+  SCOPE_LOG_TAG(Parse)
 };
 
 }  // namespace parse
diff --git a/src/tpk/step/step_parse_recovery.cc b/src/tpk/step/step_parse_recovery.cc
new file mode 100644 (file)
index 0000000..da0fd29
--- /dev/null
@@ -0,0 +1,55 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "tpk/step/step_parse_recovery.h"
+
+#include <boost/filesystem/operations.hpp>
+
+#include "common/backup_paths.h"
+
+namespace bf = boost::filesystem;
+
+namespace {
+
+const char kManifestFileName[] = "tizen-manifest.xml";
+
+}  // namespace
+
+namespace tpk {
+namespace parse {
+
+common_installer::Step::Status StepParseRecovery::process() {
+  (void) StepParse::process();
+  return Status::OK;
+}
+
+
+common_installer::Step::Status StepParseRecovery::precheck() {
+  if (context_->root_application_path.get().empty()) {
+    LOG(ERROR) << "Root path of packages in not set";
+    return Status::ERROR;
+  }
+  if (context_->pkgid.get().empty()) {
+    LOG(WARNING) << "Pkgid is not set. Parsing skipped";
+    return Status::OK;
+  }
+  return Status::OK;
+}
+
+boost::filesystem::path StepParseRecovery::LocateConfigFile() const {
+  context_->pkg_path.set(
+      context_->root_application_path.get() / context_->pkgid.get());
+  bf::path path1 = common_installer::GetBackupPathForPackagePath(
+      context_->pkg_path.get()) / kManifestFileName;
+  bf::path path2 = context_->pkg_path.get() / kManifestFileName;
+  if (bf::exists(path1))
+    return path1;
+  if (bf::exists(path2))
+    return path2;
+  return {};
+}
+
+}  // namespace parse
+}  // namespace tpk
+
diff --git a/src/tpk/step/step_parse_recovery.h b/src/tpk/step/step_parse_recovery.h
new file mode 100644 (file)
index 0000000..9047af5
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef TPK_STEP_STEP_PARSE_RECOVERY_H_
+#define TPK_STEP_STEP_PARSE_RECOVERY_H_
+
+#include <boost/filesystem/path.hpp>
+
+#include "common/utils/logging.h"
+#include "tpk/step/step_parse.h"
+
+namespace tpk {
+namespace parse {
+
+class StepParseRecovery : public StepParse {
+ public:
+  using StepParse::StepParse;
+
+  Status process() override;
+  Status precheck() override;
+
+ protected:
+  boost::filesystem::path LocateConfigFile() const override;
+
+  SCOPE_LOG_TAG(ParseRecovery)
+};
+}  // namespace parse
+}  // namespace tpk
+
+#endif  // TPK_STEP_STEP_PARSE_RECOVERY_H_
index 58ef201..6e15cdd 100644 (file)
 #include "common/step/step_fail.h"
 #include "common/step/step_generate_xml.h"
 #include "common/step/step_old_manifest.h"
+#include "common/step/step_open_recovery_file.h"
 #include "common/step/step_parse.h"
+#include "common/step/step_recover_application.h"
+#include "common/step/step_recover_files.h"
+#include "common/step/step_recover_icons.h"
+#include "common/step/step_recover_manifest.h"
+#include "common/step/step_recover_security.h"
+#include "common/step/step_recover_storage_directories.h"
 #include "common/step/step_register_app.h"
 #include "common/step/step_remove_icons.h"
 #include "common/step/step_remove_files.h"
 #include "common/step/step_revoke_security.h"
+#include "common/step/step_remove_temporary_directory.h"
 #include "common/step/step_register_security.h"
 #include "common/step/step_check_signature.h"
 #include "common/step/step_unregister_app.h"
@@ -27,6 +35,7 @@
 #include "tpk/step/step_copy_manifest_xml.h"
 #include "tpk/step/step_create_symbolic_link.h"
 #include "tpk/step/step_parse.h"
+#include "tpk/step/step_parse_recovery.h"
 
 namespace ci = common_installer;
 
@@ -61,8 +70,7 @@ void TpkInstaller::Prepare() {
       ReinstallSteps();
       break;
     case ci::RequestType::Recovery:
-      AddStep<ci::configuration::StepFail>();
-      // TODO(t.iwanek): recovery mode invocation...
+      RecoverySteps();
       break;
     default:
       AddStep<ci::configuration::StepFail>();
@@ -117,5 +125,18 @@ void TpkInstaller::ReinstallSteps() {
   AddStep<ci::configuration::StepFail>();
 }
 
+void TpkInstaller::RecoverySteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::recovery::StepOpenRecoveryFile>();
+  AddStep<tpk::parse::StepParseRecovery>();
+  AddStep<ci::pkgmgr::StepRecoverApplication>();
+  AddStep<ci::filesystem::StepRemoveTemporaryDirectory>();
+  AddStep<ci::filesystem::StepRecoverIcons>();
+  AddStep<ci::filesystem::StepRecoverManifest>();
+  AddStep<ci::filesystem::StepRecoverStorageDirectories>();
+  AddStep<ci::filesystem::StepRecoverFiles>();
+  AddStep<ci::security::StepRecoverSecurity>();
+}
+
 }  // namespace tpk
 
index f7d723c..83291bd 100644 (file)
@@ -28,6 +28,7 @@ class TpkInstaller : public common_installer::AppInstaller {
   void UpdateSteps();
   void UninstallSteps();
   void ReinstallSteps();
+  void RecoverySteps();
 
   SCOPE_LOG_TAG(TpkInstaller)
 };