Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / step / filesystem / step_remove_temporary_directory.cc
1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by a apache 2.0 license that can be
3 // found in the LICENSE file.
4 #include "common/step/filesystem/step_remove_temporary_directory.h"
5
6 #include <filesystem>
7
8 #include "common/installer_context.h"
9 #include "common/utils/file_util.h"
10
11 namespace common_installer {
12 namespace filesystem {
13
14 namespace fs = std::filesystem;
15
16 Step::Status StepRemoveTemporaryDirectory::RecoveryUpdate() {
17   return RemoveFiles();
18 }
19
20 Step::Status StepRemoveTemporaryDirectory::RecoveryNew() {
21   return RemoveFiles();
22 }
23
24 Step::Status StepRemoveTemporaryDirectory::Cleanup() {
25   return RemoveFiles();
26 }
27
28 Step::Status StepRemoveTemporaryDirectory::RemoveFiles() {
29   fs::path unpack_dir_path = context_->unpacked_dir_path.get();
30   fs::path patch_dir_path = unpack_dir_path;
31   fs::path mount_dir_path = unpack_dir_path;
32   fs::path shared_res_backup_dir_path = unpack_dir_path;
33   patch_dir_path += ".patch";
34   mount_dir_path += ".bck";
35   shared_res_backup_dir_path += ".SharedRes";
36   if (unpack_dir_path.empty())
37     return Step::Status::OK;
38   if (!ClearPath(unpack_dir_path) ||
39       !ClearPath(patch_dir_path) ||
40       !ClearPath(mount_dir_path) ||
41       !ClearPath(shared_res_backup_dir_path))
42     return Step::Status::RECOVERY_ERROR;
43   return Step::Status::OK;
44 }
45
46 bool StepRemoveTemporaryDirectory::ClearPath(const fs::path& path) {
47   return RemoveAll(path);
48 }
49
50 }  // namespace filesystem
51 }  // namespace common_installer