Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / recovery_file.h
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 #ifndef COMMON_RECOVERY_FILE_H_
6 #define COMMON_RECOVERY_FILE_H_
7
8 #include <cstdio>
9 #include <filesystem>
10 #include <memory>
11 #include <string>
12
13 #include "common/utils/request.h"
14
15 namespace common_installer {
16
17 namespace recovery {
18
19 /**
20  * Responsible for managing recovery file.
21  *
22  * It dumps information to recover file regarding current status of handled
23  * request.
24  */
25 class RecoveryFile {
26  public:
27   /**
28    * Creates new RecoveryFile object for given file
29    *
30    * \param path path to the package/id
31    *
32    * \return new RecoveryFile object
33    */
34   static std::unique_ptr<RecoveryFile> CreateRecoveryFile(
35       const std::filesystem::path& path, RequestType type);
36
37   /**
38    * Opens RecoveryFile object for given request
39    *
40    * \param path path to the package/id
41    *
42    * \return new RecoveryFile object
43    */
44   static std::unique_ptr<RecoveryFile> OpenRecoveryFile(
45       const std::filesystem::path& path);
46
47   /** Desctructor */
48   ~RecoveryFile();
49
50   /** Detaching object from given recovery file */
51   void Detach();
52
53   /**
54    * Checks if object is detached from file
55    *
56    * \return true if detached
57    *
58    */
59   bool is_detached() const;
60
61   /**
62    * setter for unpacked dir
63    *
64    * \param unpacked_dir new unpacked_dir value
65    */
66   void set_unpacked_dir(std::filesystem::path unpacked_dir);
67
68   /**
69    * setter for pkgid
70    *
71    * \param pkgid new pkgid value
72    */
73   void set_pkgid(std::string pkgid);
74
75   /**
76    * setter for backup done
77    *
78    * \param backup_done boolean value of backup_done
79    */
80   void set_backup_done(bool backup_done);
81
82   /**
83    * setter for cleanup flag
84    *
85    * \param cleanup boolean value of cleanup
86    */
87   void set_cleanup(bool cleanup);
88
89   /**
90    * setter for security operation done
91    *
92    * \param security_operation_done boolean value of security_operation_done
93    */
94   void set_security_operation_done(bool security_operation_done);
95
96   /**
97    * getter for unpacked dir
98    *
99    * \return current unpacked_dir
100    */
101   const std::filesystem::path& unpacked_dir() const;
102
103   /**
104    * getter for pkgid
105    *
106    * * \return current pkgid
107    */
108   const std::string& pkgid() const;
109
110   /**
111    * getter for request type
112    *
113    * \return current request type
114    */
115   RequestType type() const;
116
117   /**
118    * getter for backup exist flag
119    *
120    * \return true if backup does exist
121    */
122   bool backup_done() const;
123
124   /**
125    * getter for cleanup flag
126    *
127    * \return true if cleanup flag has set
128    */
129   bool cleanup() const;
130
131   /**
132    * getter for security operation done flag
133    *
134    * \return true if security operation done flag has set
135    */
136   bool security_operation_done() const;
137
138   /**
139    * Transaction of current RecoveryFile content into recovery file
140    *
141    * \return true if success
142    */
143   bool WriteAndCommitFileContent();
144
145  private:
146   RecoveryFile(const std::filesystem::path& path, RequestType type,
147       bool load);
148
149   bool ReadFileContent();
150
151   RequestType type_;
152   std::filesystem::path unpacked_dir_;
153   std::string pkgid_;
154
155   std::filesystem::path path_;
156   std::filesystem::path backup_path_;
157   bool backup_done_;
158   bool cleanup_;
159   bool security_operation_done_;
160 };
161
162 }  // namespace recovery
163 }  // namespace common_installer
164
165 #endif  // COMMON_RECOVERY_FILE_H_