3d1f60670addc04cfae037756c947966feb7bd38
[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 <boost/filesystem/path.hpp>
9 #include <pkgmgrinfo_basic.h>
10
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 boost::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 storage directories in path
112  *
113  * \param path base path, which contains storage directories
114  * \param pkgid package id
115  *
116  * \return true if succeed, false otherwise
117  */
118 bool DeleteStorageDirectories(const boost::filesystem::path& path,
119                               const std::string& pkgid);
120
121 /**
122  * \brief Deletes shared directories in path
123  *
124  * \param path base path, which containsshared directories
125  * \param pkgid package id
126  *
127  * \return true if succeed, false otherwise
128  */
129 bool DeleteSharedDirectories(const boost::filesystem::path& path,
130                              const std::string& pkgid);
131
132 /**
133  * \brief Returns path prefix for internal storage, typically '/home'
134  *
135  * \return path prefix
136  *
137  */
138 std::string GetDirectoryPathForInternalStorage();
139
140 /**
141  * \brief Returns path prefix for external storage, typically sd card mount point
142  *
143  * \return path prefix
144  *
145  */
146 std::string GetDirectoryPathForExternalStorage();
147
148 /**
149  * \brief Create symlinks for read-only files of global app for all users.
150  *
151  * \param pkgid package id
152  *
153  * \return true if succeed, false otherwise
154  *
155  */
156 bool CreateGlobalAppSymlinksForAllUsers(const std::string& pkgid);
157
158 /**
159  * \brief Create symlinks for read-only files of global app for user.
160  *
161  * \param pkgid package id
162  * \param uid user id
163  *
164  * \return true if succeed, false otherwise
165  *
166  */
167 bool CreateGlobalAppSymlinksForUser(const std::string& pkgid, uid_t uid);
168
169 /**
170  * \brief Delete symlinks for read-only files of global app for all users.
171  *
172  * \param pkgid package id
173  *
174  * \return true if succeed, false otherwise
175  *
176  */
177 bool DeleteGlobalAppSymlinksForAllUsers(const std::string& pkgid);
178
179 /**
180  * \brief Delete symlinks for read-only files of global app for user.
181  *
182  * \param pkgid package id
183  * \param uid user id
184  *
185  * \return true if succeed, false otherwise
186  *
187  */
188 bool DeleteGlobalAppSymlinksForUser(const std::string& pkgid, uid_t uid);
189
190 /**
191  * \brief Set owner and permission of package directory.
192  *
193  * \param pkgid package id
194  * \param uid user id
195  *
196  * \return true if succeed, false otherwise
197  */
198 bool SetPackageDirectoryOwnerAndPermissions(const boost::filesystem::path& path,
199                                             uid_t uid);
200
201 /**
202  * \brief Return true when installer should support legacy shared data directory.
203  *
204  * \param api_version package api version
205  *
206  * \return true when should support legacy shared data directory, false otherwise
207  */
208 bool ShouldSupportLegacySharedDataDir(const std::string& api_version);
209
210 /**
211  * \brief Creates shared data directory for specific package
212  *
213  * \param pkgid package id
214  * \param uid user id
215  *
216  * \return true if succeed, false otherwise
217  */
218 bool CreateSharedDataDir(const std::string& pkgid, uid_t uid);
219
220 /**
221  * \brief Creates per user shared data directories for specific package
222  *
223  * \param pkgid package id
224  *
225  * \return true if succeed, false otherwise
226  */
227 bool CreatePerUserSharedDataDir(const std::string& pkgid);
228
229 /**
230  * \brief Deletes of shared data directory for specific package
231  *
232  * \param pkgid package id
233  * \param uid user id
234  *
235  * \return true if succeed, false otherwise
236  */
237 bool DeleteSharedDataDir(const std::string& pkgid, uid_t uid);
238
239 /**
240  * \brief Deletes per user shared data directories for specific package
241  *
242  * \param pkgid package id
243  *
244  * \return true if succeed, false otherwise
245  */
246 bool DeletePerUserSharedDataDir(const std::string& pkgid);
247
248 /**
249  * \brief Backups shared data directories for specific package
250  *
251  * \param pkgid package id
252  * \param uid user id
253  *
254  * \return true if succeed, false otherwise
255  */
256 bool BackupSharedDataDir(const std::string& pkgid, uid_t uid);
257
258 /**
259  * \brief Backups per user shared data directories for specific package
260  *
261  * \param pkgid package id
262  *
263  * \return true if succeed, false otherwise
264  */
265 bool BackupPerUserSharedDataDir(const std::string& pkgid);
266
267 /**
268  * \brief Restores shared data directories for specific package
269  *
270  * \param pkgid package id
271  * \param uid user id
272  *
273  * \return true if succeed, false otherwise
274  */
275 bool RestoreSharedDataDir(const std::string& pkgid, uid_t uid);
276
277 /**
278  * \brief Restores per user shared data directories for specific package
279  *
280  * \param pkgid package id
281  *
282  * \return true if succeed, false otherwise
283  */
284 bool RestorePerUserSharedDataDir(const std::string& pkgid);
285
286 /**
287  * \brief Removes backup of shared data directories for specific package
288  *
289  * \param pkgid package id
290  * \param uid user id
291  *
292  * \return true if succeed, false otherwise
293  */
294 bool RemoveBackupSharedDataDir(const std::string& pkgid, uid_t uid);
295
296 /**
297  * \brief Removes backup of per user shared data directories for specific package
298  *
299  * \param pkgid package id
300  *
301  * \return true if succeed, false otherwise
302  */
303 bool RemoveBackupPerUserSharedDataDir(const std::string& pkgid);
304
305 }  // namespace common_installer
306
307 #endif  // COMMON_SHARED_DIRS_H_