Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / shared_dirs.h
1 // Copyright (c) 2016 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_SHARED_DIRS_H_
6 #define COMMON_SHARED_DIRS_H_
7
8 #include <pkgmgrinfo_basic.h>
9
10 #include <filesystem>
11 #include <string>
12 #include <vector>
13
14 namespace common_installer {
15
16 /**
17  * \brief Performs a creation of directories for specific user in external storage
18  *
19  * \param pkgid id of package
20  * \param create_skel_directories flag
21  *
22  * \return true if succeed, false otherwise
23  *
24  */
25 bool PerformExternalDirectoryCreationForUser(uid_t uid,
26                                              const std::string& pkgid);
27
28 /**
29  * \brief Performs a removal of directories for specific user in external storage
30  * \param user id of user
31  * \param pkgid id of package
32  *
33  * \return true if succeed, false otherwise
34  */
35 bool PerformExternalDirectoryDeletionForUser(uid_t user,
36                                             const std::string& pkgid);
37
38 /**
39  * \brief Performs a creation of directories in external storage (eg. SD card)
40  *
41  * \param pkgid id of package
42  * \param create_skel_directories flag
43  *
44  * \return true if succeed, false otherwise
45  *
46  */
47 bool PerformExternalDirectoryCreationForAllUsers(const std::string& pkgid);
48
49 /**
50  * \brief Find pkgs which has external storage privilege for each user and make
51  *  directories in external storage (eg. SD card)
52  *
53  * \return true if succeed, false otherwise
54  *
55  */
56 bool PerformExternalDirectoryCreationForAllPkgs();
57
58 /**
59  * \brief Performs a removal of directories in external storage (eg. SD card)
60  * \param pkgid id of package
61  *
62  * \return true if succeed, false otherwise
63  */
64 bool PerformExternalDirectoryDeletionForAllUsers(const std::string& pkgid);
65
66 /**
67  * \brief Creates per user storage directories in path
68  *
69  * \param pkgid package id
70  * \param trusted signed package flag
71  * \param shareddata shared data privilege flag
72  * \param is_readonly readonly flag
73  * \param additional_dirs additional directories vector
74  *
75  * \return true if succeed, false otherwise
76  */
77 bool CreatePerUserStorageDirectories(const std::string& pkgid,
78                                      bool trusted, bool shareddata,
79                                      bool is_readonly,
80                                      const std::vector<const char*>
81                                      additional_dirs =
82                                          std::vector<const char*>());
83
84 /**
85  * \brief Creates storage directories in path
86  *
87  * \param path base path, where storage directories will be created in
88  * \param pkgid package id
89  * \param uid user id
90  * \param trusted signed package flag
91  * \param shareddata shared data privilege flag
92  *
93  * \return true if succeed, false otherwise
94  */
95 bool CreateStorageDirectories(const std::filesystem::path& path,
96                               const std::string& pkgid, uid_t uid,
97                               bool trusted, bool shareddata);
98
99 /**
100  * \brief Deletes per user storage directories in path
101  *
102  * \param pkgid package id
103  * \param keep_rwdata keep rwdata flag
104  *
105  * \return true if succeed, false otherwise
106  */
107 bool DeletePerUserStorageDirectories(const std::string& pkgid,
108                                      bool keep_rwdata = false);
109
110 /**
111  * \brief Deletes RW directories in path, this should be invoked after
112  *        unzipping package for remove rw directories
113  *
114  * \param path base path, which contains rw directories
115  */
116 void RemoveRWDirectories(const std::filesystem::path& root);
117
118 /**
119  * \brief Deletes shared directories in path
120  *
121  * \param path base path, which containsshared directories
122  * \param pkgid package id
123  *
124  * \return true if succeed, false otherwise
125  */
126 bool DeleteSharedDirectories(const std::filesystem::path& path,
127                              const std::string& pkgid);
128
129 /**
130  * \brief Returns path prefix for internal storage, typically '/home'
131  *
132  * \return path prefix
133  *
134  */
135 std::string GetDirectoryPathForInternalStorage();
136
137 /**
138  * \brief Returns path prefix for external storage, typically sd card mount point
139  *
140  * \return path prefix
141  *
142  */
143 std::string GetDirectoryPathForExternalStorage();
144
145 /**
146  * \brief Create symlinks for read-only files of global app for all users.
147  *
148  * \param pkgid package id
149  *
150  * \return true if succeed, false otherwise
151  *
152  */
153 bool CreateGlobalAppSymlinksForAllUsers(const std::string& pkgid);
154
155 /**
156  * \brief Create symlinks for read-only files of global app for user.
157  *
158  * \param pkgid package id
159  * \param uid user id
160  *
161  * \return true if succeed, false otherwise
162  *
163  */
164 bool CreateGlobalAppSymlinksForUser(const std::string& pkgid, uid_t uid);
165
166 /**
167  * \brief Delete symlinks for read-only files of global app for all users.
168  *
169  * \param pkgid package id
170  *
171  * \return true if succeed, false otherwise
172  *
173  */
174 bool DeleteGlobalAppSymlinksForAllUsers(const std::string& pkgid);
175
176 /**
177  * \brief Delete symlinks for read-only files of global app for user.
178  *
179  * \param pkgid package id
180  * \param uid user id
181  *
182  * \return true if succeed, false otherwise
183  *
184  */
185 bool DeleteGlobalAppSymlinksForUser(const std::string& pkgid, uid_t uid);
186
187 /**
188  * \brief Set owner and permission of package directory.
189  *
190  * \param pkgid package id
191  * \param uid user id
192  *
193  * \return true if succeed, false otherwise
194  */
195 bool SetPackageDirectoryOwnerAndPermissions(const std::filesystem::path& path,
196                                             uid_t uid);
197
198 /**
199  * \brief Return true when installer should support legacy shared data directory.
200  *
201  * \param api_version package api version
202  *
203  * \return true when should support legacy shared data directory, false otherwise
204  */
205 bool ShouldSupportLegacySharedDataDir(const std::string& api_version);
206
207 /**
208  * \brief Creates shared data directory for specific package
209  *
210  * \param pkgid package id
211  * \param uid user id
212  *
213  * \return true if succeed, false otherwise
214  */
215 bool CreateSharedDataDir(const std::string& pkgid, uid_t uid);
216
217 /**
218  * \brief Creates per user shared data directories for specific package
219  *
220  * \param pkgid package id
221  *
222  * \return true if succeed, false otherwise
223  */
224 bool CreatePerUserSharedDataDir(const std::string& pkgid);
225
226 /**
227  * \brief Deletes of shared data directory for specific package
228  *
229  * \param pkgid package id
230  * \param uid user id
231  *
232  * \return true if succeed, false otherwise
233  */
234 bool DeleteSharedDataDir(const std::string& pkgid, uid_t uid);
235
236 /**
237  * \brief Deletes per user shared data directories for specific package
238  *
239  * \param pkgid package id
240  *
241  * \return true if succeed, false otherwise
242  */
243 bool DeletePerUserSharedDataDir(const std::string& pkgid);
244
245 /**
246  * \brief Backups shared data directories for specific package
247  *
248  * \param pkgid package id
249  * \param uid user id
250  *
251  * \return true if succeed, false otherwise
252  */
253 bool BackupSharedDataDir(const std::string& pkgid, uid_t uid);
254
255 /**
256  * \brief Backups per user shared data directories for specific package
257  *
258  * \param pkgid package id
259  *
260  * \return true if succeed, false otherwise
261  */
262 bool BackupPerUserSharedDataDir(const std::string& pkgid);
263
264 /**
265  * \brief Restores shared data directories for specific package
266  *
267  * \param pkgid package id
268  * \param uid user id
269  *
270  * \return true if succeed, false otherwise
271  */
272 bool RestoreSharedDataDir(const std::string& pkgid, uid_t uid);
273
274 /**
275  * \brief Restores per user shared data directories for specific package
276  *
277  * \param pkgid package id
278  *
279  * \return true if succeed, false otherwise
280  */
281 bool RestorePerUserSharedDataDir(const std::string& pkgid);
282
283 /**
284  * \brief Removes backup of shared data directories for specific package
285  *
286  * \param pkgid package id
287  * \param uid user id
288  *
289  * \return true if succeed, false otherwise
290  */
291 bool RemoveBackupSharedDataDir(const std::string& pkgid, uid_t uid);
292
293 /**
294  * \brief Removes backup of per user shared data directories for specific package
295  *
296  * \param pkgid package id
297  *
298  * \return true if succeed, false otherwise
299  */
300 bool RemoveBackupPerUserSharedDataDir(const std::string& pkgid);
301
302 }  // namespace common_installer
303
304 #endif  // COMMON_SHARED_DIRS_H_