Move create recovery file to new step 06/154906/10
authorDamian Pietruchowski <d.pietruchow@samsung.com>
Wed, 11 Oct 2017 11:11:16 +0000 (13:11 +0200)
committerDamian Pietruchowski <d.pietruchow@samsung.com>
Tue, 28 Nov 2017 13:49:09 +0000 (13:49 +0000)
Submit together:
- https://review.tizen.org/gerrit/#/c/154907/
- https://review.tizen.org/gerrit/#/c/154908/

Change-Id: Ia0cc4e85c200cf35ece43dae7e802a0c04d50507
Signed-off-by: Damian Pietruchowski <d.pietruchow@samsung.com>
src/common/step/configuration/step_configure.cc
src/common/step/configuration/step_configure.h
src/common/step/recovery/step_create_recovery_file.cc [new file with mode: 0644]
src/common/step/recovery/step_create_recovery_file.h [new file with mode: 0644]

index e0b675d..9f6ec95 100644 (file)
@@ -137,31 +137,6 @@ Step::Status StepConfigure::process() {
       break;
   }
 
-  // Record recovery file
-  if (requestType == RequestType::Install ||
-      requestType == RequestType::Update ||
-      requestType == RequestType::Delta ||
-      requestType == RequestType::MountInstall ||
-      requestType == RequestType::MountUpdate) {
-    std::unique_ptr<recovery::RecoveryFile> recovery_file =
-        recovery::RecoveryFile::CreateRecoveryFile(
-            GenerateTemporaryPath(
-                context_->root_application_path.get() /
-                (context_->pkg_type.get() + "-recovery")),
-            requestType);
-    if (!recovery_file) {
-      LOG(ERROR) << "Failed to create recovery file";
-      return Status::CONFIG_ERROR;
-    }
-    recovery_file->set_type(requestType);
-
-    if (!recovery_file->WriteAndCommitFileContent()) {
-      LOG(ERROR) << "Failed to write recovery file";
-      return Status::CONFIG_ERROR;
-    }
-    context_->recovery_info.set(RecoveryInfo(std::move(recovery_file)));
-  }
-
   return Status::OK;
 }
 
@@ -196,13 +171,6 @@ Step::Status StepConfigure::precheck() {
   return Status::OK;
 }
 
-Step::Status StepConfigure::clean() {
-  // Clean up operations should not be covered by recovery
-  // as backup information is being lost during clean up
-  context_->recovery_info.get().recovery_file.reset();
-  return Status::OK;
-}
-
 bool StepConfigure::SetupRootAppDirectory() {
   if (context_->root_application_path.get().empty()) {
     std::string root_app_path =
index bbed19c..c002552 100644 (file)
@@ -43,7 +43,7 @@ class StepConfigure : public Step {
    *
    * \return Status::OK
    */
-  Status clean() override;
+  Status clean() override { return Status::OK; }
 
   Status undo() override { return Status::OK; }
 
diff --git a/src/common/step/recovery/step_create_recovery_file.cc b/src/common/step/recovery/step_create_recovery_file.cc
new file mode 100644 (file)
index 0000000..e743537
--- /dev/null
@@ -0,0 +1,73 @@
+// Copyright (c) 2017 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 "step_create_recovery_file.h"
+
+#include <boost/filesystem/path.hpp>
+
+#include <pkgmgr-info.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <tzplatform_config.h>
+
+#include <memory>
+#include <string>
+#include <utility>
+
+#include "common/pkgmgr_query.h"
+#include "common/request.h"
+#include "common/utils/file_util.h"
+#include "common/utils/user_util.h"
+#include "common/recovery_file.h"
+
+namespace bf = boost::filesystem;
+
+namespace common_installer {
+namespace configuration {
+
+Step::Status StepCreateRecoveryFile::process() {
+  std::string recovery_filename = context_->pkg_type.get() + "-recovery";
+  bf::path recovery_filepath = GenerateTemporaryPath(
+      context_->root_application_path.get() / recovery_filename);
+  auto recovery_file =
+      recovery::RecoveryFile::CreateRecoveryFile(recovery_filepath,
+          context_->request_type.get());
+  if (!recovery_file) {
+    LOG(ERROR) << "Failed to create recovery file";
+    return Status::CONFIG_ERROR;
+  }
+  recovery_file->set_type(context_->request_type.get());
+
+  if (!recovery_file->WriteAndCommitFileContent()) {
+    LOG(ERROR) << "Failed to write recovery file";
+    return Status::CONFIG_ERROR;
+  }
+  context_->recovery_info.set(RecoveryInfo(std::move(recovery_file)));
+
+  return Status::OK;
+}
+
+Step::Status StepCreateRecoveryFile::precheck() {
+  if (context_->pkg_type.get().empty()) {
+    LOG(ERROR) << "Pkg type is not set";
+    return Status::INVALID_VALUE;
+  }
+  if (context_->root_application_path.get().empty()) {
+    LOG(ERROR) << "Root application path is not set";
+    return Status::INVALID_VALUE;
+  }
+  return Status::OK;
+}
+
+Step::Status StepCreateRecoveryFile::clean() {
+  // Clean up operations should not be covered by recovery
+  // as backup information is being lost during clean up
+  context_->recovery_info.get().recovery_file.reset();
+  return Status::OK;
+}
+
+
+}  // namespace configuration
+}  // namespace common_installer
diff --git a/src/common/step/recovery/step_create_recovery_file.h b/src/common/step/recovery/step_create_recovery_file.h
new file mode 100644 (file)
index 0000000..38a7b9d
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright (c) 2017 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_RECOVERY_STEP_RECORD_RECOVERY_FILE_H_
+#define COMMON_STEP_RECOVERY_STEP_RECORD_RECOVERY_FILE_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include "common/installer_context.h"
+
+#include "common/pkgmgr_interface.h"
+#include "common/step/step.h"
+
+namespace common_installer {
+namespace configuration {
+
+class StepCreateRecoveryFile : public Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+  Status clean() override;
+  Status undo() override { return Status::OK; }
+  Status precheck() override;
+
+  STEP_NAME(Configure)
+};
+
+}  // namespace configuration
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_RECOVERY_STEP_RECORD_RECOVERY_FILE_H_