[Recovery] StepRemoveTemporaryDirectory 15/45715/3
authorWojciech Kosowicz <w.kosowicz@samsung.com>
Mon, 3 Aug 2015 09:45:25 +0000 (11:45 +0200)
committerPawel Sikorski <p.sikorski@samsung.com>
Tue, 11 Aug 2015 08:40:15 +0000 (01:40 -0700)
Step deletes all the directories that starts with 'unpack' within
root app directory

Change-Id: I22c5b8a3db9fc370876a47a8193a8f5490b48fb9

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

index d3c22d4..e9c876a 100644 (file)
@@ -31,6 +31,7 @@ SET(SRCS
   step/step_parse.cc
   step/step_remove_icons.cc
   step/step_remove_files.cc
+  step/step_remove_temporary_directory.cc
   step/step_revoke_security.cc
   step/step_register_security.cc
   step/step_unregister_app.cc
diff --git a/src/common/step/step_remove_temporary_directory.cc b/src/common/step/step_remove_temporary_directory.cc
new file mode 100644 (file)
index 0000000..3457a44
--- /dev/null
@@ -0,0 +1,36 @@
+// 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_remove_temporary_directory.h"
+
+#include <boost/filesystem.hpp>
+#include <boost/system/error_code.hpp>
+
+#include "common/context_installer.h"
+
+namespace common_installer {
+namespace filesystem {
+
+namespace bf = boost::filesystem;
+
+Step::Status StepRemoveTemporaryDirectory::RecoveryUpdate() {
+  RemoveFiles();
+  return Step::Status::OK;
+}
+
+Step::Status StepRemoveTemporaryDirectory::RecoveryNew() {
+  RemoveFiles();
+  return Step::Status::OK;
+}
+
+void StepRemoveTemporaryDirectory::RemoveFiles() {
+  bf::path unpack_dir_path = context_->unpacked_dir_path.get();
+  if (unpack_dir_path.empty())
+    return;
+  boost::system::error_code error_code;
+  bf::remove_all(unpack_dir_path, error_code);
+  return;
+}
+}  // namespace filesystem
+}  // namespace common_installer
+
diff --git a/src/common/step/step_remove_temporary_directory.h b/src/common/step/step_remove_temporary_directory.h
new file mode 100644 (file)
index 0000000..af31960
--- /dev/null
@@ -0,0 +1,40 @@
+// 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_REMOVE_TEMPORARY_DIRECTORY_H_
+#define COMMON_STEP_STEP_REMOVE_TEMPORARY_DIRECTORY_H_
+
+#include "common/step/step_recovery.h"
+
+namespace common_installer {
+namespace filesystem {
+
+/**
+ * @brief removes temp directories if install gets
+ *        interrupted
+ *
+ * Part of Recovery Mode. If recovery mode gets called
+ * path to temporary unpack directory and its content get
+ * deleted
+ */
+class StepRemoveTemporaryDirectory : public recovery::StepRecovery {
+ public:
+  using StepRecovery::StepRecovery;
+
+  Status RecoveryNew() override;
+  Status RecoveryUpdate() override;
+ private:
+  /**
+   * @brief RemoveFiles
+   * Removes all the temporary files
+   */
+  void RemoveFiles();
+
+  SCOPE_LOG_TAG(RemoveTemporaryDirectory)
+};
+
+}  // namespace filesystem
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_STEP_REMOVE_TEMPORARY_DIRECTORY_H_