[BackupManifest] Added step for update installation 15/38515/1
authorTomasz Iwanek <t.iwanek@samsung.com>
Tue, 24 Mar 2015 16:12:12 +0000 (17:12 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Tue, 21 Apr 2015 13:30:43 +0000 (15:30 +0200)
Tizen-JIRA: TC-2482

Change-Id: I09cfd57bf0edb9d2851fe49f02b4fdc11202e854

src/common/CMakeLists.txt
src/common/context_installer.h
src/common/step/step_backup_manifest.cc [new file with mode: 0644]
src/common/step/step_backup_manifest.h [new file with mode: 0644]

index dca15a0..ab76581 100644 (file)
@@ -5,6 +5,7 @@ SET(SRCS
   pkgmgr_interface.cc
   pkgmgr_signal.cc
   security_registration.cc
+  step/step_backup_manifest.cc
   step/step_unzip.cc
   step/step_check_signature.cc
   step/step_configure.cc
index d82742c..b6a446b 100644 (file)
@@ -66,6 +66,9 @@ class ContextInstaller {
   // path to manifest xml file used to register data in databases
   Property<boost::filesystem::path> xml_path;
 
+  // path to old manifest xml while updating
+  Property<boost::filesystem::path> backup_xml_path;
+
   // pkgid used for update or uninstallation processing
   Property<std::string> pkgid;
 
diff --git a/src/common/step/step_backup_manifest.cc b/src/common/step/step_backup_manifest.cc
new file mode 100644 (file)
index 0000000..0d95974
--- /dev/null
@@ -0,0 +1,77 @@
+// Copyright (c) 2015 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 "common/step/step_backup_manifest.h"
+
+#include <boost/filesystem/path.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <boost/system/error_code.hpp>
+
+#include <pkgmgr-info.h>
+#include <pkgmgr_installer.h>
+
+#include <string>
+
+#include "utils/file_util.h"
+#include "utils/logging.h"
+
+namespace bf = boost::filesystem;
+namespace bs = boost::system;
+
+namespace common_installer {
+namespace backup_manifest {
+
+Step::Status StepBackupManifest::precheck() {
+  if (!bf::exists(context_->xml_path.get())) {
+    LOG(ERROR) << "Xml manifest file does not exist";
+    return Status::ERROR;
+  }
+}
+
+Step::Status StepBackupManifest::process() {
+  // set backup file path
+  bf::path backup_xml_path = context_->xml_path.get();
+  backup_xml_path =  + ".bck";
+  context_->backup_xml_path.set(backup_xml_path);
+
+  if (!utils::MoveFile(context_->xml_path.get(),
+      context_->backup_xml_path.get())) {
+    LOG(ERROR) << "Failed to make a copy of xml manifest file";
+    return Status::ERROR;
+  }
+  LOG(DEBUG) << "Manifest backup created";
+  return Status::OK;
+}
+
+Step::Status StepBackupManifest::clean() {
+  bs::error_code error;
+  bf::remove(context_->backup_xml_path.get(), error);
+  if (error) {
+    LOG(WARNING) << "Cannot remove backup manifest file";
+    return Status::ERROR;
+  }
+  LOG(DEBUG) << "Manifest backup removed";
+  return Status::OK;
+}
+
+Step::Status StepBackupManifest::undo() {
+  if (bf::exists(context_->backup_xml_path.get())) {
+    bs::error_code error;
+    bf::remove(context_->xml_path.get(), error);
+    if (error) {
+      LOG(ERROR) << "Failed to remove newly generated xml file in revert";
+      return Status::ERROR;
+    }
+    if (!utils::MoveFile(context_->backup_xml_path.get(),
+        context_->xml_path.get())) {
+      LOG(ERROR) << "Failed to revert a content of xml manifest file";
+      return Status::ERROR;
+    }
+    LOG(DEBUG) << "Manifest reverted from backup";
+  }
+  return Status::OK;
+}
+
+}  // namespace backup_manifest
+}  // namespace common_installer
diff --git a/src/common/step/step_backup_manifest.h b/src/common/step/step_backup_manifest.h
new file mode 100644 (file)
index 0000000..59906f1
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright (c) 2015 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 COMMON_STEP_STEP_BACKUP_MANIFEST_H_
+#define COMMON_STEP_STEP_BACKUP_MANIFEST_H_
+
+#include "common/context_installer.h"
+#include "common/step/step.h"
+#include "utils/logging.h"
+
+namespace common_installer {
+namespace backup_manifest {
+
+class StepBackupManifest : public Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+  Status clean() override;
+  Status undo() override;
+  Status precheck() override;
+
+  SCOPE_LOG_TAG(BackupManifest)
+};
+
+}  // namespace backup_manifest
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_STEP_BACKUP_MANIFEST_H_