[Recovery] StepRecoverStorageDirectories 13/45713/3
authorWojciech Kosowicz <w.kosowicz@samsung.com>
Tue, 4 Aug 2015 08:46:26 +0000 (10:46 +0200)
committerPawel Sikorski <p.sikorski@samsung.com>
Tue, 11 Aug 2015 08:36:09 +0000 (01:36 -0700)
Change-Id: I7a9c24ca27646d9e285da00bde06b7465b2e9e1c

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

index fef07eb..338d845 100644 (file)
@@ -22,6 +22,7 @@ SET(SRCS
   step/step_recover_files.cc
   step/step_recover_icons.cc
   step/step_recover_manifest.cc
+  step/step_recover_storage_directories.cc
   step/step_recovery.cc
   step/step_register_app.cc
   step/step_old_manifest.cc
diff --git a/src/common/step/step_recover_storage_directories.cc b/src/common/step/step_recover_storage_directories.cc
new file mode 100644 (file)
index 0000000..4b74539
--- /dev/null
@@ -0,0 +1,44 @@
+// 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 "common/step/step_recover_storage_directories.h"
+
+#include <boost/filesystem/path.hpp>
+#include <boost/system/error_code.hpp>
+
+#include "common/utils/file_util.h"
+
+namespace {
+const char kDataLocation[] = "data";
+const char kSharedLocation[] = "shared";
+}  // namespace
+
+namespace bf = boost::filesystem;
+
+namespace common_installer {
+namespace filesystem {
+
+bool StepRecoverStorageDirectories::MoveAppStorage(
+    const bf::path& in_src,
+    const bf::path& in_dst,
+    const char *key) {
+  bf::path src = in_src / key;
+  bf::path dst = in_dst / key;
+  return common_installer::MoveDir(src, dst);
+}
+
+Step::Status StepRecoverStorageDirectories::RecoveryUpdate() {
+  if (!context_->pkg_path.get().empty()) {
+    bf::path backup_path = common_installer::GetBackupPathForPackagePath(
+        context_->pkg_path.get());
+    if (!backup_path.empty()) {
+      MoveAppStorage(context_->pkg_path.get(), backup_path, kDataLocation);
+      MoveAppStorage(context_->pkg_path.get(), backup_path, kSharedLocation);
+    }
+  }
+  return Status::OK;
+}
+}  // namespace filesystem
+}  // namespace common_installer
+
diff --git a/src/common/step/step_recover_storage_directories.h b/src/common/step/step_recover_storage_directories.h
new file mode 100644 (file)
index 0000000..7b3da48
--- /dev/null
@@ -0,0 +1,45 @@
+// 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 COMMON_STEP_STEP_RECOVER_STORAGE_DIRECTORIES_H_
+#define COMMON_STEP_STEP_RECOVER_STORAGE_DIRECTORIES_H_
+
+#include "common/context_installer.h"
+#include "common/step/step_recovery.h"
+#include "common/utils/logging.h"
+
+namespace common_installer {
+namespace filesystem {
+
+/**
+ * @brief recovers data and shared directories of application
+ *
+ * Part of Recovery Mode. Is responsible for restoring data and shared
+ * directories in case partial update occurs.
+ */
+class StepRecoverStorageDirectories : public recovery::StepRecovery {
+ public:
+  using StepRecovery::StepRecovery;
+
+  Status RecoveryNew() override { return Status::OK; }
+  Status RecoveryUpdate() override;
+ private:
+  /**
+   * @brief moves directories
+   * @param in_src path of the source location
+   * @param in_dst path of the destination location
+   * @param key directory name
+   * @return true if operation successful
+   */
+  bool MoveAppStorage(const boost::filesystem::path& in_src,
+                      const boost::filesystem::path& in_dst,
+                      const char *key);
+
+  SCOPE_LOG_TAG(RecoverStorageDirectories)
+};
+
+}  // namespace filesystem
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_STEP_RECOVER_STORAGE_DIRECTORIES_H_