62e01d9226bfa1e781efdd6471f78fb129ece263
[platform/core/appfw/app-installers.git] / src / common / step / rds / step_rds_modify.h
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
5 #ifndef COMMON_STEP_RDS_STEP_RDS_MODIFY_H_
6 #define COMMON_STEP_RDS_STEP_RDS_MODIFY_H_
7
8 #include <boost/filesystem.hpp>
9 #include <common/step/step.h>
10 #include <string>
11 #include <utility>
12 #include <vector>
13
14 #include "common/installer_context.h"
15
16 namespace common_installer {
17 namespace rds {
18
19 /**
20  * \brief Step that apply RDS modification during reinstallation process
21  */
22 class StepRDSModify : public Step {
23  public:
24   /**
25    * \brief Explicit constructor
26    *
27    * \param context Installer context
28    */
29   explicit StepRDSModify(common_installer::InstallerContext* context);
30
31   /**
32    * \brief
33    *
34    * \return
35    */
36   Status process() override;
37
38   /**
39    * \brief Remove files from temporary location
40    *
41    * \return Status::OK
42    */
43   Status clean() override;
44
45   /**
46    * \brief Restore files to the state from before RDS installation
47    *
48    * \return Status::OK
49    */
50   Status undo() override;
51
52   /**
53    * \brief
54    *
55    * \return Status::ERROR when manifest is missing, pkgid is missing,
56    *         or when path to the unpacked directory is missing or not exist,
57    *         Status::OK otherwise
58    */
59   Status precheck() override;
60
61  private:
62   enum class Operation {
63     ADD,
64     MODIFY,
65     DELETE
66   };
67
68   bool AddFiles(boost::filesystem::path unzip_path,
69                 boost::filesystem::path install_path);
70   bool ModifyFiles(boost::filesystem::path unzip_path,
71                    boost::filesystem::path install_path);
72   bool DeleteFiles(boost::filesystem::path install_path);
73   bool SetUpTempBackupDir();
74   void DeleteTempBackupDir();
75   bool PerformBackup(std::string relative_path, Operation operation);
76   void RestoreFiles();
77
78   std::vector<std::pair<std::string, Operation>> success_modifications_;
79   boost::filesystem::path backup_temp_dir_;
80   std::vector<std::string> files_to_modify_;
81   std::vector<std::string> files_to_add_;
82   std::vector<std::string> files_to_delete_;
83
84   STEP_NAME(RDSModify)
85 };
86
87 }  // namespace rds
88 }  // namespace common_installer
89
90 #endif  // COMMON_STEP_RDS_STEP_RDS_MODIFY_H_