Change the file remove to a virtual function in recovery
[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 <boost/filesystem.hpp>
7 #include <boost/system/error_code.hpp>
8
9 #include "common/installer_context.h"
10 #include "common/utils/file_util.h"
11
12 namespace common_installer {
13 namespace filesystem {
14
15 namespace bf = boost::filesystem;
16
17 Step::Status StepRemoveTemporaryDirectory::RecoveryUpdate() {
18   return RemoveFiles();
19 }
20
21 Step::Status StepRemoveTemporaryDirectory::RecoveryNew() {
22   return RemoveFiles();
23 }
24
25 Step::Status StepRemoveTemporaryDirectory::Cleanup() {
26   return RemoveFiles();
27 }
28
29 Step::Status StepRemoveTemporaryDirectory::RemoveFiles() {
30   bf::path unpack_dir_path = context_->unpacked_dir_path.get();
31   bf::path patch_dir_path = unpack_dir_path;
32   bf::path mount_dir_path = unpack_dir_path;
33   bf::path shared_res_backup_dir_path = unpack_dir_path;
34   patch_dir_path += ".patch";
35   mount_dir_path += ".bck";
36   shared_res_backup_dir_path += ".SharedRes";
37   if (unpack_dir_path.empty())
38     return Step::Status::OK;
39   if (!ClearPath(unpack_dir_path) ||
40       !ClearPath(patch_dir_path) ||
41       !ClearPath(mount_dir_path) ||
42       !ClearPath(shared_res_backup_dir_path))
43     return Step::Status::RECOVERY_ERROR;
44   return Step::Status::OK;
45 }
46
47 bool StepRemoveTemporaryDirectory::ClearPath(const bf::path& path) {
48   return RemoveAll(path);
49 }
50
51 }  // namespace filesystem
52 }  // namespace common_installer
53