#include <pwd.h>
#include <tzplatform_config.h>
-// Gets the user's uid with a directory under the home directory.
-// In order to reduce unnecessary operation, only uids related to installed app are obtained.
-static std::vector<uid_t> getUserIds()
+// Gets app root directories of users.
+// In order to reduce unnecessary operation, it is obtained only when an app root exists.
+static std::vector<std::string> getUserAppRoots()
{
DIR *dir;
struct dirent* entry;
struct passwd *p;
- std::vector<uid_t> uids;
+ std::vector<std::string> userAppRoots;
dir = opendir("/home");
if (dir == nullptr) {
- return uids;
+ return userAppRoots;
}
while ((entry = readdir(dir)) != nullptr) {
if (entry->d_type == DT_DIR) {
if ((p = getpwnam(entry->d_name)) != NULL) {
- uids.push_back(p->pw_uid);
+ tzplatform_set_user(p->pw_uid);
+ const char* tzUserApp = tzplatform_getenv(TZ_USER_APP);
+ if (tzUserApp != NULL && exist(tzUserApp)) {
+ userAppRoots.push_back(tzUserApp);
+ }
+ tzplatform_reset_user();
}
}
}
closedir(dir);
- return uids;
-}
-
-static std::string getAppDataPath(const std::string& pkgId, uid_t uid)
-{
- std::string pDataFile;
-
- tzplatform_set_user(uid);
-
- const char* tzUserApp = tzplatform_getenv(TZ_USER_APP);
- if (tzUserApp != NULL) {
- pDataFile = std::string(tzUserApp) + "/" + pkgId + "/data/";
- }
-
- tzplatform_reset_user();
-
- return pDataFile;
+ return userAppRoots;
}
profile_error_e removeAppProfileData(const std::string& pkgId, void *user_data)
return PROFILE_ERROR_INVALID_PARAMETER;
}
- std::vector<uid_t> uidList;
+ std::vector<std::string> userAppRoots;
if (user_data != NULL) {
- uidList = *(std::vector<uid_t>*)user_data;
+ userAppRoots = *(std::vector<std::string>*)user_data;
} else {
- uidList = getUserIds();
+ userAppRoots = getUserAppRoots();
}
- for (auto it = uidList.begin(); it != uidList.end(); ++it) {
+ for (auto it = userAppRoots.begin(); it != userAppRoots.end(); ++it) {
// get data path from pkgid and uid
- std::string dataPath = getAppDataPath(pkgId, *it);
+ std::string dataPath = *it + "/" + pkgId + "/data/";
if (!dataPath.empty() && exist(dataPath)) {
std::string pDataFile = dataPath + PROFILE_BASENAME;
void removeAllAppProfileData()
{
// To reduce repeated getUserIds calls, get uids here.
- std::vector<uid_t> uidList = getUserIds();
- int ret = pkgmgrinfo_appinfo_get_installed_list(removeAppProfileListCb, &uidList);
+ std::vector<std::string> userAppRoots = getUserAppRoots();
+ int ret = pkgmgrinfo_appinfo_get_installed_list(removeAppProfileListCb, &userAppRoots);
if (ret != PMINFO_R_OK) {
_SERR("Failed to get installed list");
}