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