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.
5 #ifndef COMMON_SHARED_DIRS_H_
6 #define COMMON_SHARED_DIRS_H_
8 #include <pkgmgrinfo_basic.h>
14 namespace common_installer {
17 * \brief Performs a creation of directories for specific user in external storage
19 * \param pkgid id of package
20 * \param create_skel_directories flag
22 * \return true if succeed, false otherwise
25 bool PerformExternalDirectoryCreationForUser(uid_t uid,
26 const std::string& pkgid);
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
33 * \return true if succeed, false otherwise
35 bool PerformExternalDirectoryDeletionForUser(uid_t user,
36 const std::string& pkgid);
39 * \brief Performs a creation of directories in external storage (eg. SD card)
41 * \param pkgid id of package
42 * \param create_skel_directories flag
44 * \return true if succeed, false otherwise
47 bool PerformExternalDirectoryCreationForAllUsers(const std::string& pkgid);
50 * \brief Find pkgs which has external storage privilege for each user and make
51 * directories in external storage (eg. SD card)
53 * \return true if succeed, false otherwise
56 bool PerformExternalDirectoryCreationForAllPkgs();
59 * \brief Performs a removal of directories in external storage (eg. SD card)
60 * \param pkgid id of package
62 * \return true if succeed, false otherwise
64 bool PerformExternalDirectoryDeletionForAllUsers(const std::string& pkgid);
67 * \brief Creates per user storage directories in path
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
75 * \return true if succeed, false otherwise
77 bool CreatePerUserStorageDirectories(const std::string& pkgid,
78 bool trusted, bool shareddata,
80 const std::vector<const char*>
82 std::vector<const char*>());
85 * \brief Creates storage directories in path
87 * \param path base path, where storage directories will be created in
88 * \param pkgid package id
90 * \param trusted signed package flag
91 * \param shareddata shared data privilege flag
93 * \return true if succeed, false otherwise
95 bool CreateStorageDirectories(const std::filesystem::path& path,
96 const std::string& pkgid, uid_t uid,
97 bool trusted, bool shareddata);
100 * \brief Deletes per user storage directories in path
102 * \param pkgid package id
103 * \param keep_rwdata keep rwdata flag
105 * \return true if succeed, false otherwise
107 bool DeletePerUserStorageDirectories(const std::string& pkgid,
108 bool keep_rwdata = false);
111 * \brief Deletes RW directories in path, this should be invoked after
112 * unzipping package for remove rw directories
114 * \param path base path, which contains rw directories
116 void RemoveRWDirectories(const std::filesystem::path& root);
119 * \brief Deletes shared directories in path
121 * \param path base path, which containsshared directories
122 * \param pkgid package id
124 * \return true if succeed, false otherwise
126 bool DeleteSharedDirectories(const std::filesystem::path& path,
127 const std::string& pkgid);
130 * \brief Returns path prefix for internal storage, typically '/home'
132 * \return path prefix
135 std::string GetDirectoryPathForInternalStorage();
138 * \brief Returns path prefix for external storage, typically sd card mount point
140 * \return path prefix
143 std::string GetDirectoryPathForExternalStorage();
146 * \brief Create symlinks for read-only files of global app for all users.
148 * \param pkgid package id
150 * \return true if succeed, false otherwise
153 bool CreateGlobalAppSymlinksForAllUsers(const std::string& pkgid);
156 * \brief Create symlinks for read-only files of global app for user.
158 * \param pkgid package id
161 * \return true if succeed, false otherwise
164 bool CreateGlobalAppSymlinksForUser(const std::string& pkgid, uid_t uid);
167 * \brief Delete symlinks for read-only files of global app for all users.
169 * \param pkgid package id
171 * \return true if succeed, false otherwise
174 bool DeleteGlobalAppSymlinksForAllUsers(const std::string& pkgid);
177 * \brief Delete symlinks for read-only files of global app for user.
179 * \param pkgid package id
182 * \return true if succeed, false otherwise
185 bool DeleteGlobalAppSymlinksForUser(const std::string& pkgid, uid_t uid);
188 * \brief Set owner and permission of package directory.
190 * \param pkgid package id
193 * \return true if succeed, false otherwise
195 bool SetPackageDirectoryOwnerAndPermissions(const std::filesystem::path& path,
199 * \brief Return true when installer should support legacy shared data directory.
201 * \param api_version package api version
203 * \return true when should support legacy shared data directory, false otherwise
205 bool ShouldSupportLegacySharedDataDir(const std::string& api_version);
208 * \brief Creates shared data directory for specific package
210 * \param pkgid package id
213 * \return true if succeed, false otherwise
215 bool CreateSharedDataDir(const std::string& pkgid, uid_t uid);
218 * \brief Creates per user shared data directories for specific package
220 * \param pkgid package id
222 * \return true if succeed, false otherwise
224 bool CreatePerUserSharedDataDir(const std::string& pkgid);
227 * \brief Deletes of shared data directory for specific package
229 * \param pkgid package id
232 * \return true if succeed, false otherwise
234 bool DeleteSharedDataDir(const std::string& pkgid, uid_t uid);
237 * \brief Deletes per user shared data directories for specific package
239 * \param pkgid package id
241 * \return true if succeed, false otherwise
243 bool DeletePerUserSharedDataDir(const std::string& pkgid);
246 * \brief Backups shared data directories for specific package
248 * \param pkgid package id
251 * \return true if succeed, false otherwise
253 bool BackupSharedDataDir(const std::string& pkgid, uid_t uid);
256 * \brief Backups per user shared data directories for specific package
258 * \param pkgid package id
260 * \return true if succeed, false otherwise
262 bool BackupPerUserSharedDataDir(const std::string& pkgid);
265 * \brief Restores shared data directories for specific package
267 * \param pkgid package id
270 * \return true if succeed, false otherwise
272 bool RestoreSharedDataDir(const std::string& pkgid, uid_t uid);
275 * \brief Restores per user shared data directories for specific package
277 * \param pkgid package id
279 * \return true if succeed, false otherwise
281 bool RestorePerUserSharedDataDir(const std::string& pkgid);
284 * \brief Removes backup of shared data directories for specific package
286 * \param pkgid package id
289 * \return true if succeed, false otherwise
291 bool RemoveBackupSharedDataDir(const std::string& pkgid, uid_t uid);
294 * \brief Removes backup of per user shared data directories for specific package
296 * \param pkgid package id
298 * \return true if succeed, false otherwise
300 bool RemoveBackupPerUserSharedDataDir(const std::string& pkgid);
302 } // namespace common_installer
304 #endif // COMMON_SHARED_DIRS_H_