From: Woongsuk Cho Date: Thu, 9 Nov 2023 01:05:34 +0000 (+0900) Subject: Gets the user's uid related to installed app only. X-Git-Tag: accepted/tizen/8.0/unified/20231109.181656~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=07a22157e9ddad89658a459fae3b07835e820411;p=platform%2Fcore%2Fdotnet%2Flauncher.git Gets the user's uid related to installed app only. if there are many installed apps, it takes a lot of time to delete profile data. This is because it attempts to delete profile data for all uids. To optimize this, only uids related to the installed app are obtained. --- diff --git a/NativeLauncher/inc/profile_common.h b/NativeLauncher/inc/profile_common.h index 7495a23..87329be 100644 --- a/NativeLauncher/inc/profile_common.h +++ b/NativeLauncher/inc/profile_common.h @@ -31,7 +31,7 @@ typedef enum { * @param[in] pkgId package id * @return profile_error_e */ -profile_error_e removeAppProfileData(const std::string& pkgId); +profile_error_e removeAppProfileData(const std::string& pkgId, void *user_data); /** * @brief remove all app profile data diff --git a/NativeLauncher/installer-plugin/dotnet_apptype_plugin.cc b/NativeLauncher/installer-plugin/dotnet_apptype_plugin.cc index 48e0ed3..25d2c4e 100644 --- a/NativeLauncher/installer-plugin/dotnet_apptype_plugin.cc +++ b/NativeLauncher/installer-plugin/dotnet_apptype_plugin.cc @@ -57,7 +57,7 @@ extern "C" int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc, const char* pkgId) return 0; } - if (removeAppProfileData(pkgId) != PROFILE_ERROR_NONE) { + if (removeAppProfileData(pkgId, NULL) != PROFILE_ERROR_NONE) { _ERR("Failed to remove [%s] profile data", pkgId); } diff --git a/NativeLauncher/tool/dotnettool.cc b/NativeLauncher/tool/dotnettool.cc index 4343b49..0afa2ff 100644 --- a/NativeLauncher/tool/dotnettool.cc +++ b/NativeLauncher/tool/dotnettool.cc @@ -394,7 +394,7 @@ int main(int argc, char* argv[]) } while (it != args.end()) { std::string pkg = std::string(*it); - if (removeAppProfileData(pkg) != PROFILE_ERROR_NONE) { + if (removeAppProfileData(pkg, NULL) != PROFILE_ERROR_NONE) { _SERR("Failed to remove [%s] profile data", pkg.c_str()); } it = args.erase(it); 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"); }