From 754f7a945453f40bd8f8d0d5dec0010f1a13147a Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Thu, 23 Mar 2017 21:33:36 +0900 Subject: [PATCH 01/16] Fix app_size calculation - Skip the mount point (.mmc, .pkg, tep/mount) - Add external tep file Change-Id: I4de49662e54c1c62e73df0135759c8d97296d962 Signed-off-by: jongmyeongko (cherry picked from commit 56fc473a0d0ce89006f7e128080fd2f8a64c69b6) --- src/pkg_getsize.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 148 insertions(+), 24 deletions(-) diff --git a/src/pkg_getsize.c b/src/pkg_getsize.c index 662832b..9914807 100644 --- a/src/pkg_getsize.c +++ b/src/pkg_getsize.c @@ -92,32 +92,36 @@ static int __get_sdcard_path(char **sdpath) return 0; } -static char *__get_external_image_path_by_handle(pkgmgrinfo_pkginfo_h handle) +static char *__get_external_tep_path_by_handle(pkgmgrinfo_pkginfo_h handle) { int ret; char *result_path; + char *sdpath; - ret = pkgmgrinfo_pkginfo_get_external_image_path(handle, &result_path); + ret = pkgmgrinfo_pkginfo_get_tep_name(handle, &result_path); if (ret != PMINFO_R_OK) return NULL; + ret = __get_sdcard_path(&sdpath); + if (ret < 0) + return NULL; + + if (strstr(result_path, sdpath) == NULL) + return NULL; + return strdup(result_path); } -static char *__get_external_image_path_by_pkgid(const char *pkgid) +static char *__get_external_image_path_by_handle(pkgmgrinfo_pkginfo_h handle) { int ret; char *result_path; - pkgmgrinfo_pkginfo_h handle; - ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle); + ret = pkgmgrinfo_pkginfo_get_external_image_path(handle, &result_path); if (ret != PMINFO_R_OK) return NULL; - result_path = __get_external_image_path_by_handle(handle); - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); - - return result_path; + return strdup(result_path); } static long long __calculate_directory_size(int dfd, bool include_itself) @@ -187,6 +191,60 @@ error: return -1; } +static int __calculate_tep_dir_size(int dfd) +{ + long long size = 0; + struct stat st; + int ret; + DIR *dir; + struct dirent *dent = NULL; + const char *file_info; + char buf[1024] = {0, }; + + ret = fstat(dfd, &st); + if (ret < 0) { + LOGE("fstat() failed, file_info: ., errno: %d (%s)", errno, + strerror_r(errno, buf, sizeof(buf))); + return -1; + } + size += __stat_size(&st); + + dir = fdopendir(dfd); + if (dir == NULL) { + LOGE("fdopendir() failed, errno: %d (%s)", errno, + strerror_r(errno, buf, sizeof(buf))); + return -1; + } + + while ((dent = readdir(dir)) != NULL) { + file_info = dent->d_name; + if (file_info[0] == '.') { + if (file_info[1] == '\0') + continue; + if ((file_info[1] == '.') && (file_info[2] == '\0')) + continue; + } + + if (strncmp(file_info, "mount", strlen("mount")) == 0) + continue; + + ret = fstatat(dfd, file_info, &st, AT_SYMLINK_NOFOLLOW); + if (ret < 0) { + LOGE("fstatat() failed, file_info:%s, errno: %d(%s)", + file_info, errno, strerror_r(errno, buf, sizeof(buf))); + goto error; + } + size += __stat_size(&st); + } + + closedir(dir); + return size; + +error: + closedir(dir); + return -1; +} + static int __calculate_shared_dir_size(int dfd, const char *app_root_dir, long long *data_size, long long *app_size, long long *cache_size) @@ -323,8 +381,8 @@ error: static int __calculate_pkg_size_info(STORAGE_TYPE type, const char *pkgid, const char *ext_image_path, - long long *data_size, long long *cache_size, - long long *app_size) + const char *ext_tep_path, long long *data_size, + long long *cache_size, long long *app_size) { char app_root_dir[MAX_PATH_LENGTH] = {0, }; char buf[1024] = {0, }; @@ -380,6 +438,31 @@ static int __calculate_pkg_size_info(STORAGE_TYPE type, } /* external image file */ *app_size += __stat_size(&st); + LOGD("app_size: %lld", *app_size); + close(subfd); + } + } + if (ext_tep_path) { + subfd = open(ext_tep_path, O_RDONLY); + if (subfd < 0) { + LOGE("open() failed, path: %s, errno: %d (%s)", + ext_tep_path, errno, + strerror_r(errno, buf, sizeof(buf))); + return -1; + } else { + ret = fstat(subfd, &st); + if (ret < 0) { + LOGE("fstat() failed, path: %s, " + "errno: %d (%s)", + ext_tep_path, errno, + strerror_r(errno, buf, + sizeof(buf))); + close(subfd); + return -1; + } + /* external tep file */ + *app_size += __stat_size(&st); + LOGD("app_size: %lld", *app_size); close(subfd); } } @@ -420,6 +503,10 @@ static int __calculate_pkg_size_info(STORAGE_TYPE type, if (dent->d_type != DT_DIR) continue; + if (strncmp(name, ".pkg", strlen(".pkg")) == 0 || + strncmp(name, ".mmc", strlen(".mmc")) == 0) + continue; + subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY); if (subfd < 0) { if (errno != ENOENT) { @@ -469,6 +556,15 @@ static int __calculate_pkg_size_info(STORAGE_TYPE type, goto error; } LOGD("app_size: %lld", *app_size); + } else if (strncmp(name, "tep", strlen("tep")) == 0) { + LOGD("traverse path: %s/%s", app_root_dir, name); + size = __calculate_tep_dir_size(subfd); + if (size < 0) { + LOGE("Calculating tep directory failed."); + goto error; + } + *app_size += size; + LOGD("app_size: %lld", *app_size); } else { LOGD("traverse path: %s/%s", app_root_dir, name); size = __calculate_directory_size(subfd, true); @@ -528,12 +624,12 @@ static char *__get_pkg_size_info_str(const pkg_size_info_t* pkg_size_info) } static int __get_pkg_size_info(const char *pkgid, const char *ext_image_path, - pkg_size_info_t *pkg_size_info) + const char *ext_tep_path, pkg_size_info_t *pkg_size_info) { int ret; ret = __calculate_pkg_size_info(STORAGE_TYPE_INTERNAL_GLOBAL_PATH, - pkgid, ext_image_path, &pkg_size_info->data_size, + pkgid, ext_image_path, ext_tep_path, &pkg_size_info->data_size, &pkg_size_info->cache_size, &pkg_size_info->app_size); if (ret < 0) { LOGE("failed to calculate interal(global) size " \ @@ -545,7 +641,7 @@ static int __get_pkg_size_info(const char *pkgid, const char *ext_image_path, } ret = __calculate_pkg_size_info(STORAGE_TYPE_INTERNAL_USER_PATH, - pkgid, ext_image_path, &pkg_size_info->data_size, + pkgid, ext_image_path, ext_tep_path, &pkg_size_info->data_size, &pkg_size_info->cache_size, &pkg_size_info->app_size); if (ret < 0) { LOGE("failed to calculate interal(user) size " \ @@ -557,8 +653,9 @@ static int __get_pkg_size_info(const char *pkgid, const char *ext_image_path, } ret = __calculate_pkg_size_info(STORAGE_TYPE_EXTERNAL_USER_PATH, - pkgid, ext_image_path, &pkg_size_info->ext_data_size, - &pkg_size_info->ext_cache_size, &pkg_size_info->ext_app_size); + pkgid, ext_image_path, ext_tep_path, + &pkg_size_info->ext_data_size, &pkg_size_info->ext_cache_size, + &pkg_size_info->ext_app_size); if (ret < 0) { LOGE("failed to calculate external(user) size " \ "for pkgid(%s)", pkgid); @@ -578,6 +675,7 @@ static int __get_total_pkg_size_info_cb(const pkgmgrinfo_pkginfo_h handle, int ret; char *pkgid; char *ext_image_path; + char *ext_tep_path; pkg_size_info_t temp_pkg_size_info = {0,}; pkg_size_info_t *pkg_size_info = (void *)user_data; @@ -588,12 +686,16 @@ static int __get_total_pkg_size_info_cb(const pkgmgrinfo_pkginfo_h handle, } ext_image_path = __get_external_image_path_by_handle(handle); - ret = __get_pkg_size_info(pkgid, ext_image_path, &temp_pkg_size_info); + ext_tep_path = __get_external_tep_path_by_handle(handle); + ret = __get_pkg_size_info(pkgid, ext_image_path, ext_tep_path, + &temp_pkg_size_info); if (ret < 0) LOGW("failed to get size of some path"); /* even if it's an error, store all the valid result */ if (ext_image_path) free(ext_image_path); + if (ext_tep_path) + free(ext_tep_path); pkg_size_info->app_size += temp_pkg_size_info.app_size; pkg_size_info->data_size += temp_pkg_size_info.data_size; @@ -643,6 +745,7 @@ static int __send_sizeinfo_cb(const pkgmgrinfo_pkginfo_h handle, int ret; char *pkgid; char *ext_image_path; + char *ext_tep_path; int data_size = 0; int total_size = 0; char total_buf[MAX_PKG_BUF_LEN]; @@ -658,13 +761,17 @@ static int __send_sizeinfo_cb(const pkgmgrinfo_pkginfo_h handle, } ext_image_path = __get_external_image_path_by_handle(handle); - ret = __get_pkg_size_info(pkgid, ext_image_path, &temp_pkg_size_info); + ext_tep_path = __get_external_tep_path_by_handle(handle); + ret = __get_pkg_size_info(pkgid, ext_image_path, ext_tep_path, + &temp_pkg_size_info); if (ret < 0) LOGW("failed to get size of some path"); /* even if it's an error, store all the valid result */ if (ext_image_path) free(ext_image_path); + if (ext_tep_path) + free(ext_tep_path); total_size = temp_pkg_size_info.app_size + temp_pkg_size_info.data_size + temp_pkg_size_info.cache_size; @@ -725,6 +832,8 @@ int main(int argc, char *argv[]) pkg_size_info_t info = {0, }; int fifo_exist = 0; char *ext_image_path = NULL; + char *ext_tep_path = NULL; + pkgmgrinfo_pkginfo_h handle; /* argv has bellowed meaning */ /* argv[1] = pkgid */ @@ -764,19 +873,32 @@ int main(int argc, char *argv[]) "caller_uid=%d, fifo_exist=%d]", pkgid, get_type, target_uid, caller_uid, fifo_exist); + if (get_type == PM_GET_TOTAL_SIZE || + get_type == PM_GET_DATA_SIZE || + get_type == PM_GET_PKG_SIZE_INFO) { + ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle); + if (ret == PMINFO_R_OK) { + ext_image_path = + __get_external_image_path_by_handle(handle); + ext_tep_path = + __get_external_tep_path_by_handle(handle); + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + } + } + switch (get_type) { case PM_GET_TOTAL_SIZE: /* send result to file */ - ext_image_path = __get_external_image_path_by_pkgid(pkgid); - ret = __get_pkg_size_info(pkgid, ext_image_path, &info); + ret = __get_pkg_size_info(pkgid, ext_image_path, ext_tep_path, + &info); if (ret < 0) LOGW("failed to get size of some path"); size = info.app_size + info.data_size + info.cache_size; break; case PM_GET_DATA_SIZE: /* send result to file */ - ext_image_path = __get_external_image_path_by_pkgid(pkgid); - ret = __get_pkg_size_info(pkgid, ext_image_path, &info); + ret = __get_pkg_size_info(pkgid, ext_image_path, ext_tep_path, + &info); if (ret < 0) LOGW("failed to get size of some path"); size = info.data_size + info.cache_size; @@ -799,8 +921,8 @@ int main(int argc, char *argv[]) break; case PM_GET_PKG_SIZE_INFO: /* send result to signal */ - ext_image_path = __get_external_image_path_by_pkgid(pkgid); - ret = __get_pkg_size_info(pkgid, ext_image_path, &info); + ret = __get_pkg_size_info(pkgid, ext_image_path, ext_tep_path, + &info); if (ret < 0) LOGW("failed to get size of some path"); size = info.app_size + info.data_size + info.cache_size; @@ -854,6 +976,8 @@ int main(int argc, char *argv[]) if (ext_image_path) free(ext_image_path); + if (ext_tep_path) + free(ext_tep_path); LOGD("get size result = %d", ret); pkgmgr_installer_free(pi); -- 2.7.4 From 1b60b9a1e69b79cc2c6c2c4008de9d1dfe02d425 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Fri, 31 Mar 2017 21:09:56 +0900 Subject: [PATCH 02/16] Fix static analyzer issues Change-Id: I94f39bbc7c2721865ed868b496d7d633e9588c7a Signed-off-by: Sangyoon Jang --- src/pkg_info.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/pkg_info.c b/src/pkg_info.c index de84154..8973bb6 100644 --- a/src/pkg_info.c +++ b/src/pkg_info.c @@ -1089,6 +1089,7 @@ static int __get_certinfo_from_db(char *pkgid, uid_t uid) ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, handle, uid); if (ret < 0) { printf("pkgmgrinfo_pkginfo_load_certinfo failed\n"); + pkgmgrinfo_pkginfo_destroy_certinfo(handle); return -1; } @@ -1348,12 +1349,6 @@ static int __set_certinfo_in_db(char *pkgid, uid_t uid) break; default: printf("Invalid Number Entered\n"); - choice = 0; - ret = pkgmgr_installer_destroy_certinfo_set_handle(handle); - if (ret < 0) { - printf("pkgmgr_installer_destroy_certinfo_set_handle failed\n"); - return -1; - } break; } } -- 2.7.4 From 17912f5a8db877251b33b52c23d0ba8700edfca5 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Mon, 3 Apr 2017 10:34:46 +0900 Subject: [PATCH 03/16] Fix static analyzer issue Change-Id: I2b98a24932342e94f245094e85940a84cf8361d3 Signed-off-by: jongmyeongko (cherry picked from commit 1e26bf7bec3de727741ed36109dca3d140f6eac3) --- src/pkg_getsize.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pkg_getsize.c b/src/pkg_getsize.c index 9914807..51c6270 100644 --- a/src/pkg_getsize.c +++ b/src/pkg_getsize.c @@ -440,6 +440,7 @@ static int __calculate_pkg_size_info(STORAGE_TYPE type, *app_size += __stat_size(&st); LOGD("app_size: %lld", *app_size); close(subfd); + subfd = -1; } } if (ext_tep_path) { @@ -464,6 +465,7 @@ static int __calculate_pkg_size_info(STORAGE_TYPE type, *app_size += __stat_size(&st); LOGD("app_size: %lld", *app_size); close(subfd); + subfd = -1; } } } else { -- 2.7.4 From 4638ab9fb9a71a3038fc80430b6d91a54e9a87a4 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Thu, 30 Mar 2017 16:47:54 +0900 Subject: [PATCH 04/16] Delete invalid labeling The label 'User::Home' for TZ_SYS_RW_PACKAGE is enough. Change-Id: Ibae510e815b3d3db9205a9df25212ffb5c4e5349 Signed-off-by: jongmyeongko --- packaging/pkgmgr-tool.spec | 1 - 1 file changed, 1 deletion(-) diff --git a/packaging/pkgmgr-tool.spec b/packaging/pkgmgr-tool.spec index ef30b81..f4fbfa7 100644 --- a/packaging/pkgmgr-tool.spec +++ b/packaging/pkgmgr-tool.spec @@ -54,7 +54,6 @@ mkdir -p %{buildroot}%{_sysconfdir}/opt/upgrade # Update mime database to support package mime types update-mime-database %{_datadir}/mime -chsmack -a '*' %{TZ_SYS_RW_PACKAGES} %posttrans if [ ! -f %{TZ_SYS_DB}/.pkgmgr_parser.db ]; then -- 2.7.4 From 90669dc15bb488ef37514d8338962d64ddb5f112 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Fri, 7 Apr 2017 14:09:58 +0900 Subject: [PATCH 05/16] Release version 0.3.2 Changes: - Fix app_size calculation - Fix static analyzer issues - Delete invalid labeling Change-Id: Ic10fd9a00e8f163fd8077d60b13fe86ab33dea7f Signed-off-by: Sangyoon Jang --- packaging/pkgmgr-tool.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/pkgmgr-tool.spec b/packaging/pkgmgr-tool.spec index f4fbfa7..4fff7a1 100644 --- a/packaging/pkgmgr-tool.spec +++ b/packaging/pkgmgr-tool.spec @@ -1,6 +1,6 @@ Name: pkgmgr-tool Summary: Packager Manager Tool package -Version: 0.3.1 +Version: 0.3.2 Release: 1 Group: Application Framework/Package Management License: Apache-2.0 -- 2.7.4 From da54c00f6ecf1ed74c81abe2b7e1e2c750849448 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Tue, 11 Apr 2017 11:22:57 +0900 Subject: [PATCH 06/16] Fix bug on setting tep option Change-Id: I8a82b80651cbe1ddf9d826d3a10542f6f04afd96 Signed-off-by: Sangyoon Jang --- src/pkg_cmd.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/pkg_cmd.c b/src/pkg_cmd.c index b061591..3fcdd46 100644 --- a/src/pkg_cmd.c +++ b/src/pkg_cmd.c @@ -142,8 +142,8 @@ struct pm_tool_args_t { char resolved_path_delta_pkg[PATH_MAX]; char label[PKG_NAME_STRING_LEN_MAX]; char tep_path[PATH_MAX]; - char tep_move[PKG_NAME_STRING_LEN_MAX]; + bool tep_move; int global; int type; int result; @@ -1272,8 +1272,8 @@ int main(int argc, char *argv[]) memset(data.pkg_type, '\0', PKG_TYPE_STRING_LEN_MAX); memset(data.label, '\0', PKG_TYPE_STRING_LEN_MAX); memset(data.tep_path, '\0', PATH_MAX); - memset(data.tep_move, '\0', PKG_NAME_STRING_LEN_MAX); + data.tep_move = 0; data.global = 0; /* By default pkg_cmd will manage for the current user */ data.result = 0; data.type = -1; @@ -1432,8 +1432,7 @@ int main(int argc, char *argv[]) case 'M': /*tep move*/ if (optarg) - strncpy(data.tep_move, (atoi(optarg) == 1) ? "tep_move" : "tep_copy", - PKG_NAME_STRING_LEN_MAX - 1); + data.tep_move = (atoi(optarg) == 1) ? true : false; break; case 't': /* package type */ -- 2.7.4 From e045654a40ca695bec920f56c9e9b11a2f6915eb Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Fri, 14 Apr 2017 13:49:11 +0900 Subject: [PATCH 07/16] Release version 0.3.3 Changes: - Fix bug on setting tep option Change-Id: Ibfacd07e738144c8bfe34dd4bc5791b0cf14eaa3 Signed-off-by: Sangyoon Jang --- packaging/pkgmgr-tool.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/pkgmgr-tool.spec b/packaging/pkgmgr-tool.spec index 4fff7a1..a3dea53 100644 --- a/packaging/pkgmgr-tool.spec +++ b/packaging/pkgmgr-tool.spec @@ -1,6 +1,6 @@ Name: pkgmgr-tool Summary: Packager Manager Tool package -Version: 0.3.2 +Version: 0.3.3 Release: 1 Group: Application Framework/Package Management License: Apache-2.0 -- 2.7.4 From 3c9278f9725e42c8097c230101fafff53340bfa7 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Mon, 24 Apr 2017 21:16:46 +0900 Subject: [PATCH 08/16] Fix the bug that local variable can't be assigned by sdcard api. this can cause the crash issue when there is no sdcard. Change-Id: Ie7608e6b26e29422eaee2e06c7f7daf54f2673b7 Signed-off-by: jongmyeongko --- src/pkg_getsize.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/pkg_getsize.c b/src/pkg_getsize.c index 51c6270..6b68a7a 100644 --- a/src/pkg_getsize.c +++ b/src/pkg_getsize.c @@ -84,11 +84,9 @@ static int __get_sdcard_path(char **sdpath) return -1; ret = storage_get_primary_sdcard(&storage_id, sdpath); - if (ret != STORAGE_ERROR_NONE) { - if (*sdpath) - free(*sdpath); + if (ret != STORAGE_ERROR_NONE) return -1; - } + return 0; } @@ -96,7 +94,7 @@ static char *__get_external_tep_path_by_handle(pkgmgrinfo_pkginfo_h handle) { int ret; char *result_path; - char *sdpath; + char *sdpath = NULL; ret = pkgmgrinfo_pkginfo_get_tep_name(handle, &result_path); if (ret != PMINFO_R_OK) -- 2.7.4 From 46dbf98aed33cb75d17d03f6e9523ec079dcea54 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Mon, 6 Mar 2017 10:25:40 +0900 Subject: [PATCH 09/16] Fix cleardata tool - Fix to remove external data folder if exists - Add some usage at help message Change-Id: I308faac8988dfa31e1fffe7870896fcc3fee0ad8 Signed-off-by: Junghyun Yeon (cherry picked from commit 2d68017e46577fedcb51ce760c2f7bc71d7acd69) Signed-off-by: jongmyeongko --- src/pkg_cleardata.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/src/pkg_cleardata.c b/src/pkg_cleardata.c index 363bf82..1f8159a 100644 --- a/src/pkg_cleardata.c +++ b/src/pkg_cleardata.c @@ -195,8 +195,11 @@ static int __clear_cache_dir(const char *pkgid) /* cache external */ ret = __get_sdcard_path(&sdpath); - if (ret != 0 || sdpath == NULL) - LOGE("Failed to get external storage path"); + if (ret != 0 || sdpath == NULL) { + LOGW("Unable to retrieve external storage path"); + tzplatform_reset_user(); + return 0; + } snprintf(dirname, sizeof(dirname), "%s/%s%s%s", sdpath, "apps", @@ -228,6 +231,7 @@ static int __clear_data_dir(const char *pkgid) const char *rootpath; pkgmgrinfo_pkginfo_h pkg_handle = NULL; char *pkg_type = NULL; + char *sdpath = NULL; if (pkgid == NULL) { LOGE("pkgid is NULL\n"); @@ -250,7 +254,6 @@ static int __clear_data_dir(const char *pkgid) tzplatform_set_user(uid); rootpath = tzplatform_getenv(TZ_USER_APP); - tzplatform_reset_user(); __send_signal(pkgid, pkg_type, PKGMGR_INSTALLER_START_KEY_STR, @@ -291,10 +294,46 @@ static int __clear_data_dir(const char *pkgid) goto catch; } + /* external data */ + ret = __get_sdcard_path(&sdpath); + if (ret != 0 || sdpath == NULL) { + LOGW("Unable to retrieve external storage path"); + __send_signal(pkgid, pkg_type, PKGMGR_INSTALLER_END_KEY_STR, + PKGMGR_INSTALLER_OK_EVENT_STR); + ret = 0; + goto catch; + } + + snprintf(dirname, sizeof(dirname), "%s/%s%s/data", + sdpath, "apps", + tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid)); + ret = __clear_dir(dirname); + if (ret < 0) + LOGE("Failed to clear external data dir."); + + /* external shared/data */ + snprintf(dirname, sizeof(dirname), "%s/%s%s/shared/data", + sdpath, "apps", + tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid)); + ret = __clear_dir(dirname); + if (ret < 0) + LOGE("Failed to clear external shared data dir."); + + /* external shared/trusted */ + snprintf(dirname, sizeof(dirname), "%s/%s%s/shared/trusted", + sdpath, "apps", + tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid)); + ret = __clear_dir(dirname); + if (ret < 0) + LOGE("Failed to clear external shared trusted dir."); + __send_signal(pkgid, pkg_type, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR); catch: + tzplatform_reset_user(); + if (sdpath) + free(sdpath); if (pkg_handle) pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle); return ret; @@ -351,12 +390,13 @@ static void print_usage(void) printf("-d, --data clear pkg's data\n"); printf("-h, --help print this help\n"); printf("-n, --pkgid package id\n"); + printf("-u, --uid user id\n"); printf("\n"); printf("Usage: pkg_cleardata [options]\n"); - printf("pkg_cleardata -c -n \n"); - printf("pkg_cleardata -d -n \n"); - printf("pkg_cleardata -cd -n \n"); + printf("pkg_cleardata -c -n -u \n"); + printf("pkg_cleardata -d -n -u \n"); + printf("pkg_cleardata -cd -n -u \n"); printf("\n"); } -- 2.7.4 From 37666d70a05abbf8d7388e423c18f6a0ed14c849 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Mon, 24 Apr 2017 22:43:12 +0900 Subject: [PATCH 10/16] Apply target_uid for GET_PKG_SIZE_INFO_REQ In the root shell, target_uid is assumed as default user. this is required for the valid calculation of RW directories. Change-Id: Ia32d2651146afdff1bf7159d8e7ceee3a0982191 Signed-off-by: jongmyeongko --- src/pkg_cmd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pkg_cmd.c b/src/pkg_cmd.c index 3fcdd46..2ecdd02 100644 --- a/src/pkg_cmd.c +++ b/src/pkg_cmd.c @@ -1202,9 +1202,13 @@ static int __process_request(uid_t target_uid) } if (strcmp(data.pkgid, PKG_SIZE_INFO_TOTAL) == 0) - ret = pkgmgr_client_get_total_package_size_info(pc, __total_pkg_size_info_recv_cb, NULL); + ret = pkgmgr_client_usr_get_total_package_size_info(pc, + __total_pkg_size_info_recv_cb, NULL, + target_uid); else - ret = pkgmgr_client_get_package_size_info(pc, data.pkgid, __pkg_size_info_recv_cb, NULL); + ret = pkgmgr_client_usr_get_package_size_info(pc, + data.pkgid, __pkg_size_info_recv_cb, NULL, + target_uid); if (ret < 0) { data.result = PKGMGR_INSTALLER_ERR_FATAL_ERROR; -- 2.7.4 From 7a56e0752825d080ae2e3e56a4f6120ba8d1d7a3 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 25 Apr 2017 17:54:51 +0900 Subject: [PATCH 11/16] Release version 0.3.4 Changes: - Fix bug about sdcard api - Fix cleardata tool - Apply taget_uid for GET_PKG_SIZE_INFO_REQ Change-Id: Id1d1342afddb8af3bc6b0913512d672ae2830345 Signed-off-by: Junghyun Yeon --- packaging/pkgmgr-tool.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/pkgmgr-tool.spec b/packaging/pkgmgr-tool.spec index a3dea53..7cace6d 100644 --- a/packaging/pkgmgr-tool.spec +++ b/packaging/pkgmgr-tool.spec @@ -1,6 +1,6 @@ Name: pkgmgr-tool Summary: Packager Manager Tool package -Version: 0.3.3 +Version: 0.3.4 Release: 1 Group: Application Framework/Package Management License: Apache-2.0 -- 2.7.4 From 6006552d2559bb8086a3c6812eb2dfbb0b9b6abf Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Wed, 17 May 2017 14:25:56 +0900 Subject: [PATCH 12/16] Modify calculation logic for data and cache. Exclude the data or cache in the global directory from the calculation of data or cache size. Change-Id: I2830772de8046e6b8000624c9d0e3907fa7903da Signed-off-by: jongmyeongko --- src/pkg_getsize.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pkg_getsize.c b/src/pkg_getsize.c index 6b68a7a..5877f23 100644 --- a/src/pkg_getsize.c +++ b/src/pkg_getsize.c @@ -530,8 +530,10 @@ static int __calculate_pkg_size_info(STORAGE_TYPE type, LOGE("Calculating data directory failed."); goto error; } - *data_size += size; - LOGD("data_size: %lld", *data_size); + if (type != STORAGE_TYPE_INTERNAL_GLOBAL_PATH) { + *data_size += size; + LOGD("data_size: %lld", *data_size); + } } else if (strncmp(name, "cache", strlen("cache")) == 0) { LOGD("traverse path: %s/%s", app_root_dir, name); ret = fstat(subfd, &st); @@ -546,8 +548,10 @@ static int __calculate_pkg_size_info(STORAGE_TYPE type, LOGE("Calculating cache directory failed."); goto error; } - *cache_size += size; - LOGD("cache_size: %lld", *cache_size); + if (type != STORAGE_TYPE_INTERNAL_GLOBAL_PATH) { + *cache_size += size; + LOGD("cache_size: %lld", *cache_size); + } } else if (strncmp(name, "shared", strlen("shared")) == 0) { ret = __calculate_shared_dir_size(dfd, app_root_dir, data_size, app_size, cache_size); -- 2.7.4 From 117a94d9aacd253b92fd0b64300f214459e84c13 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Wed, 17 May 2017 16:29:48 +0900 Subject: [PATCH 13/16] Release version 0.3.5 Changes: - Modify calculation logic for data and cache Change-Id: Ib6c7ddd6debbaadea36650e417ac9a1b2dd0f753 Signed-off-by: jongmyeongko --- packaging/pkgmgr-tool.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/pkgmgr-tool.spec b/packaging/pkgmgr-tool.spec index 7cace6d..186a4e0 100644 --- a/packaging/pkgmgr-tool.spec +++ b/packaging/pkgmgr-tool.spec @@ -1,6 +1,6 @@ Name: pkgmgr-tool Summary: Packager Manager Tool package -Version: 0.3.4 +Version: 0.3.5 Release: 1 Group: Application Framework/Package Management License: Apache-2.0 -- 2.7.4 From f58e1ec4645dece664606217783e518fa6b867ee Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Thu, 18 May 2017 21:22:49 +0900 Subject: [PATCH 14/16] Fix bug on pkg_getsize - Signal for uid doesn't work Change-Id: Iebdf076ec74c011b6c74582de7b7f4d1e3f62897 Signed-off-by: jongmyeongko --- src/pkg_getsize.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pkg_getsize.c b/src/pkg_getsize.c index 5877f23..fb47829 100644 --- a/src/pkg_getsize.c +++ b/src/pkg_getsize.c @@ -792,7 +792,7 @@ static int __send_sizeinfo_cb(const pkgmgrinfo_pkginfo_h handle, if (ret) return ret; - ret = pkgmgr_installer_send_signal_for_uid(pi, caller_uid, + ret = pkgmgr_installer_send_signal_for_uid(pi, target_uid, PKGMGR_INSTALLER_GET_SIZE_KEY_STR, pkgid, data_buf, total_buf); @@ -817,7 +817,7 @@ static int __send_result_to_signal(pkgmgr_installer *pi, const char *req_key, return ret; } - ret = pkgmgr_installer_send_signal_for_uid(pi, caller_uid, + ret = pkgmgr_installer_send_signal_for_uid(pi, target_uid, PKGMGR_INSTALLER_GET_SIZE_KEY_STR, pkgid, PKGMGR_INSTALLER_GET_SIZE_KEY_STR, info_str); free(info_str); @@ -970,7 +970,7 @@ int main(int argc, char *argv[]) PKGMGR_INSTALLER_GET_SIZE_KEY_STR, PKGMGR_INSTALLER_END_KEY_STR)) LOGE("failed to send finished signal"); - if (pkgmgr_installer_send_signal_for_uid(pi, caller_uid, + if (pkgmgr_installer_send_signal_for_uid(pi, target_uid, PKGMGR_INSTALLER_GET_SIZE_KEY_STR, pkgid, PKGMGR_INSTALLER_GET_SIZE_KEY_STR, -- 2.7.4 From 61adad28150b6f157740fe7a3aadd474e6e22d03 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Thu, 1 Jun 2017 09:26:10 +0900 Subject: [PATCH 15/16] Release version 0.3.6 Changes: - Fix bug on pkg_getsize Change-Id: Ifa8aa46811ea2e2d69203597fd6899dd7922711a Signed-off-by: Junghyun Yeon --- packaging/pkgmgr-tool.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/pkgmgr-tool.spec b/packaging/pkgmgr-tool.spec index 186a4e0..27ab229 100644 --- a/packaging/pkgmgr-tool.spec +++ b/packaging/pkgmgr-tool.spec @@ -1,6 +1,6 @@ Name: pkgmgr-tool Summary: Packager Manager Tool package -Version: 0.3.5 +Version: 0.3.6 Release: 1 Group: Application Framework/Package Management License: Apache-2.0 -- 2.7.4 From 056e3d08492cfe1963606cebcdf5135364f603b1 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Wed, 31 May 2017 19:00:57 +0900 Subject: [PATCH 16/16] Change scripts - Remove scripts for pkg_initdb - Add initial label change script Change-Id: Ifcf7aceb5f08c10dc0658e3da29cae5ba21b9e08 Signed-off-by: Junghyun Yeon --- CMakeLists.txt | 2 ++ data/pkgmgr-label-initial-image.sh.in | 49 +++++++++++++++++++++++++++++++++++ packaging/pkgmgr-tool.spec | 15 +---------- 3 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 data/pkgmgr-label-initial-image.sh.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ed804d..f663436 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,8 @@ CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/data/pkgmgr-create-delta.sh.in pkgmgr-create- INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pkgmgr-create-delta.sh DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/data/pkgmgr-clear-skel.sh.in pkgmgr-clear-skel.sh @ONLY) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pkgmgr-clear-skel.sh DESTINATION /usr/share/fixed_multiuser/scripts/) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/data/pkgmgr-label-initial-image.sh.in pkgmgr-label-initial-image.sh @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pkgmgr-label-initial-image.sh DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/data/700.pkgmgr.patch.sh.in 700.pkgmgr.patch.sh @ONLY) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/700.pkgmgr.patch.sh DESTINATION /usr/share/upgrade/scripts/) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/data/701.app2sd.patch.sh.in 701.app2sd.patch.sh @ONLY) diff --git a/data/pkgmgr-label-initial-image.sh.in b/data/pkgmgr-label-initial-image.sh.in new file mode 100644 index 0000000..610c88f --- /dev/null +++ b/data/pkgmgr-label-initial-image.sh.in @@ -0,0 +1,49 @@ +#!/bin/sh +PATH=/bin:/usr/bin:/sbin:/usr/sbin + +echo "----------------------------------" +echo " Labeling for some installed files" +echo "----------------------------------" + +_ro_packages_dir="/usr/share/packages" +_rw_packages_dir="/opt/share/packages" +_skel_dir="/etc/skel/apps_rw" +_subdir_list="$(dir $_skel_dir)" + +for entry in "$_ro_packages_dir"/*.xml; do + if [ -f "$entry" ]; then + chsmack -a "System" $entry + fi +done + +for entry in "$_rw_packages_dir"/*.xml; do + if [ -f "$entry" ]; then + chsmack -a "System" $entry + fi +done + +for entry in $_subdir_list; do + _bin_symlink="$_skel_dir/$entry/bin" + _lib_symlink="$_skel_dir/$entry/lib" + _res_symlink="$_skel_dir/$entry/res" + _shared_res_symlink="$_skel_dir/$entry/shared/res" + + _target_list=" \ + $_bin_symlink \ + $_lib_symlink \ + $_res_symlink \ + $_shared_res_symlink" + + for sub_entry in $_target_list; do + if [ -h "$sub_entry" ]; then + chsmack -a "User::Home" $sub_entry + fi + done + + for sub_entry in "$_skel_dir/$entry"/*.xml; do + if [ -h "$sub_entry" ]; then + chsmack -a "User::Home" $sub_entry + fi + done +done + diff --git a/packaging/pkgmgr-tool.spec b/packaging/pkgmgr-tool.spec index 27ab229..e060666 100644 --- a/packaging/pkgmgr-tool.spec +++ b/packaging/pkgmgr-tool.spec @@ -55,20 +55,6 @@ mkdir -p %{buildroot}%{_sysconfdir}/opt/upgrade # Update mime database to support package mime types update-mime-database %{_datadir}/mime -%posttrans -if [ ! -f %{TZ_SYS_DB}/.pkgmgr_parser.db ]; then - pkg_initdb --ro - install_preload_pkg - if [ -f /tmp/.preload_install_error ]; then - if [ ! -d /tmp/.postscript/error ]; then - mkdir -p /tmp/.postscript/error - fi - echo "preload install failed" > /tmp/.postscript/error/%{name}_error - else - pkgcmd -l - fi -fi - %files %manifest %{name}.manifest %license LICENSE @@ -89,3 +75,4 @@ fi %attr(0700,root,root) /usr/share/upgrade/scripts/701.app2sd.patch.sh %attr(0700,root,root) %{_sysconfdir}/opt/upgrade/pkgmgr.patch.sh %attr(0700,root,root) /usr/share/fixed_multiuser/scripts/pkgmgr-clear-skel.sh +%attr(0700,root,root) %{_sysconfdir}/package-manager/pkgmgr-label-initial-image.sh -- 2.7.4