Skip copying data and shared directories to backup if they exist
[platform/core/appfw/app-installers.git] / src / common / step / filesystem / step_recover_storage_directories.cc
1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
4
5 #include "common/step/filesystem/step_recover_storage_directories.h"
6
7 #include <boost/filesystem/path.hpp>
8 #include <boost/system/error_code.hpp>
9
10 #include "common/paths.h"
11 #include "common/utils/file_util.h"
12
13 namespace {
14
15 const char kDataLocation[] = "data";
16 const char kSharedResLocation[] = "shared";
17
18 }  // namespace
19
20 namespace bf = boost::filesystem;
21
22 namespace common_installer {
23 namespace filesystem {
24
25 bool StepRecoverStorageDirectories::MoveAppStorage(
26     const bf::path& in_src,
27     const bf::path& in_dst,
28     const char *key) {
29   bf::path src = in_src / key;
30   if (!bf::exists(src))
31     return false;
32   bf::path dst = in_dst / key;
33   return common_installer::MoveDir(src, dst, FS_MERGE_SKIP);
34 }
35
36 Step::Status StepRecoverStorageDirectories::RecoveryUpdate() {
37   if (!context_->pkg_path.get().empty()) {
38     bf::path backup_path = common_installer::GetBackupPathForPackagePath(
39         context_->pkg_path.get());
40     if (bf::exists(backup_path)) {
41       MoveAppStorage(context_->pkg_path.get(), backup_path, kDataLocation);
42       MoveAppStorage(context_->pkg_path.get(), backup_path, kSharedResLocation);
43     }
44   }
45   return Status::OK;
46 }
47
48 Step::Status StepRecoverStorageDirectories::RecoveryMountUpdate() {
49   return Status::OK;
50 }
51
52 }  // namespace filesystem
53 }  // namespace common_installer
54