X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=NativeLauncher%2Ftool%2Fprofile_common.cc;h=e052544fb9a0d112d5b67d9b0b981d0b4b224139;hb=07a22157e9ddad89658a459fae3b07835e820411;hp=91065f1a925c0cd5b21562b68da3fc14a9b6962b;hpb=bad09c61ae5eb3c17ea3ffa56cc70f2f350ef9b5;p=platform%2Fcore%2Fdotnet%2Flauncher.git diff --git a/NativeLauncher/tool/profile_common.cc b/NativeLauncher/tool/profile_common.cc index 91065f1..e052544 100644 --- a/NativeLauncher/tool/profile_common.cc +++ b/NativeLauncher/tool/profile_common.cc @@ -20,29 +20,35 @@ #include "launcher_env.h" #include +#include #include #include +// 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 getUserIds() { - std::vector list; - - while (true) { - errno = 0; // so we can distinguish errors from no more entries - passwd* entry = getpwent(); - if (!entry) { - if (errno) { - _SERR("Error while getting userIDs"); - list.clear(); - return list; + DIR *dir; + struct dirent* entry; + struct passwd *p; + std::vector uids; + + dir = opendir("/home"); + if (dir == nullptr) { + return uids; + } + + while ((entry = readdir(dir)) != nullptr) { + if (entry->d_type == DT_DIR) { + if ((p = getpwnam(entry->d_name)) != NULL) { + uids.push_back(p->pw_uid); } - break; } - list.push_back(entry->pw_uid); } - endpwent(); - return list; + closedir(dir); + + return uids; } static std::string getAppDataPath(const std::string& pkgId, uid_t uid) @@ -61,16 +67,22 @@ static std::string getAppDataPath(const std::string& pkgId, uid_t uid) return pDataFile; } -profile_error_e removeAppProfileData(const std::string& pkgId) +profile_error_e removeAppProfileData(const std::string& pkgId, void *user_data) { if (pkgId.empty()) { return PROFILE_ERROR_INVALID_PARAMETER; } - std::vector uidList = getUserIds(); - for (auto& uid : uidList) { - // get data path from pkgid - std::string dataPath = getAppDataPath(pkgId, uid); + std::vector uidList; + if (user_data != NULL) { + uidList = *(std::vector*)user_data; + } else { + uidList = getUserIds(); + } + + for (auto it = uidList.begin(); it != uidList.end(); ++it) { + // get data path from pkgid and uid + std::string dataPath = getAppDataPath(pkgId, *it); if (!dataPath.empty() && exist(dataPath)) { std::string pDataFile = dataPath + PROFILE_BASENAME; @@ -110,7 +122,7 @@ static int removeAppProfileListCb(pkgmgrinfo_appinfo_h handle, void *user_data) return 0; } - if (removeAppProfileData(pkgId) != PROFILE_ERROR_NONE) { + if (removeAppProfileData(pkgId, user_data) != PROFILE_ERROR_NONE) { _SERR("Failed to remove profile data for (%s)", pkgId); } @@ -119,7 +131,9 @@ static int removeAppProfileListCb(pkgmgrinfo_appinfo_h handle, void *user_data) void removeAllAppProfileData() { - int ret = pkgmgrinfo_appinfo_get_installed_list(removeAppProfileListCb, NULL); + // To reduce repeated getUserIds calls, get uids here. + std::vector uidList = getUserIds(); + int ret = pkgmgrinfo_appinfo_get_installed_list(removeAppProfileListCb, &uidList); if (ret != PMINFO_R_OK) { _SERR("Failed to get installed list"); }