From 0047bd1387d6f1764fa6812e3fbea18a0863db01 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Thu, 2 Mar 2017 18:28:45 +0900 Subject: [PATCH] Fix cleardata and getsize - Remove hardcoded path - Fix wrong path of pkg_cleardata - Fix coding rule Change-Id: I9044d376b97d9fe6d20f5af286fe60b2556b396e Signed-off-by: Junghyun Yeon --- CMakeLists.txt | 2 +- packaging/pkgmgr-tool.spec | 1 + src/pkg_cleardata.c | 38 +++++++++++++++++++++++++++++--------- src/pkg_getsize.c | 32 ++++++++++++++++++++++++++------ 4 files changed, 57 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1865446..9ed804d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/client/include) INCLUDE(FindPkgConfig) pkg_check_modules(pkgs_test REQUIRED dlog glib-2.0 bundle pkgmgr pkgmgr-parser pkgmgr-info pkgmgr-installer iniparser -libtzplatform-config aul) +libtzplatform-config aul storage) FOREACH(flag ${pkgs_test_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) diff --git a/packaging/pkgmgr-tool.spec b/packaging/pkgmgr-tool.spec index bd580a7..094a142 100644 --- a/packaging/pkgmgr-tool.spec +++ b/packaging/pkgmgr-tool.spec @@ -25,6 +25,7 @@ BuildRequires: pkgconfig(db-util) BuildRequires: pkgconfig(pkgmgr) BuildRequires: pkgconfig(pkgmgr-installer) BuildRequires: pkgconfig(aul) +BuildRequires: pkgconfig(storage) BuildRequires: pkgmgr-info-parser-devel BuildRequires: pkgmgr-info-parser BuildRequires: fdupes diff --git a/src/pkg_cleardata.c b/src/pkg_cleardata.c index 88696b6..355dc9f 100644 --- a/src/pkg_cleardata.c +++ b/src/pkg_cleardata.c @@ -35,10 +35,10 @@ #include #include #include +#include #define MAX_PKG_NAME_LEN 256 #define INTERNAL_CACHE_PATH_PREFIX tzplatform_getenv(TZ_USER_APP) -#define EXTERNAL_CACHE_PATH_PREFIX tzplatform_mkpath(TZ_SYS_MEDIA, "SDCardA1/apps") #define CACHE_PATH_POSTFIX "/cache" #define SHARED_PATH_POSTFIX "/shared/cache" #define REGULAR_USER 5000 @@ -63,6 +63,23 @@ static uid_t uid; static pkgmgr_installer *pi; +static int __get_sdcard_path(char **sdpath) +{ + int ret; + int storage_id; + + if (sdpath == NULL) + return -1; + + ret = storage_get_primary_sdcard(&storage_id, sdpath); + if (ret != STORAGE_ERROR_NONE) { + if (*sdpath) + free(*sdpath); + return -1; + } + return 0; +} + static void __send_signal(const char *pkgid, const char *event_type, const char *key, const char *val) { @@ -151,6 +168,7 @@ static int __clear_cache_dir(const char *pkgid) { int ret = 0; char dirname[PATH_MAX] = {0,}; + char *sdpath = NULL; if (pkgid == NULL) { LOGE("pkgid is NULL\n"); @@ -176,23 +194,25 @@ static int __clear_cache_dir(const char *pkgid) LOGE("Failed to clear internal shared cache dir."); /* cache external */ + ret = __get_sdcard_path(&sdpath); + if (ret != 0 || sdpath == NULL) + LOGE("Failed to get external storage path"); - snprintf(dirname, sizeof(dirname), "%s%s%s", - EXTERNAL_CACHE_PATH_PREFIX, - tzplatform_mkpath(TZ_USER_NAME, pkgid), + snprintf(dirname, sizeof(dirname), "%s/%s%s%s", + sdpath, "apps", + tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid), CACHE_PATH_POSTFIX); - ret = __clear_dir(dirname); if (ret < 0) LOGE("Failed to clear external cache dir."); /* shared/cache external */ - snprintf(dirname, sizeof(dirname), "%s%s%s", - EXTERNAL_CACHE_PATH_PREFIX, - tzplatform_mkpath(TZ_USER_NAME, pkgid), + snprintf(dirname, sizeof(dirname), "%s/%s%s%s", + sdpath, "apps", + tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid), SHARED_PATH_POSTFIX); - tzplatform_reset_user(); + free(sdpath); ret = __clear_dir(dirname); if (ret < 0) diff --git a/src/pkg_getsize.c b/src/pkg_getsize.c index d3edd12..1a1d757 100644 --- a/src/pkg_getsize.c +++ b/src/pkg_getsize.c @@ -38,6 +38,7 @@ #include #include #include +#include #undef LOG_TAG #ifndef LOG_TAG @@ -53,8 +54,6 @@ #define OWNER_ROOT 0 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) -#define APP_BASE_EXTERNAL_PATH tzplatform_mkpath(TZ_SYS_MEDIA, "SDCardA1/apps") - typedef enum { STORAGE_TYPE_INTERNAL_GLOBAL_PATH, STORAGE_TYPE_INTERNAL_USER_PATH, @@ -76,6 +75,23 @@ long long __stat_size(struct stat *s) return size; } +static int __get_sdcard_path(char **sdpath) +{ + int ret; + int storage_id; + + if (sdpath == NULL) + return -1; + + ret = storage_get_primary_sdcard(&storage_id, sdpath); + if (ret != STORAGE_ERROR_NONE) { + if (*sdpath) + free(*sdpath); + return -1; + } + return 0; +} + static long long __calculate_directory_size(int dfd, bool include_itself) { long long size = 0; @@ -262,6 +278,7 @@ static int __calculate_pkg_size_info(STORAGE_TYPE type, const char *pkgid, { char app_root_dir[MAX_PATH_LENGTH] = {0, }; char buf[1024] = {0, }; + char *sdpath = NULL; DIR *dir; int dfd; int subfd = -1; @@ -285,9 +302,13 @@ static int __calculate_pkg_size_info(STORAGE_TYPE type, const char *pkgid, tzplatform_reset_user(); } else if (type == STORAGE_TYPE_EXTERNAL_USER_PATH) { tzplatform_set_user(target_uid); - snprintf(app_root_dir, MAX_PATH_LENGTH, "%s%s", - APP_BASE_EXTERNAL_PATH, + ret = __get_sdcard_path(&sdpath); + if (ret != 0 || sdpath == NULL) + return -1; + snprintf(app_root_dir, MAX_PATH_LENGTH, "%s/%s%s", + sdpath, "apps", tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid)); + free(sdpath); tzplatform_reset_user(); } else { LOGE("Invalid STORAGE_TYPE"); @@ -627,9 +648,8 @@ int main(int argc, char *argv[]) caller_uid = atoi(argv[3]); req_key = argv[5]; - if (argv[8] && !strcmp("--sync", argv[8])) { + if (argv[8] && !strcmp("--sync", argv[8])) fifo_exist = 1; - } pi = pkgmgr_installer_new(); if (pi == NULL) { -- 2.7.4