Fix cleardata tool 63/126663/4
authorJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 6 Mar 2017 01:25:40 +0000 (10:25 +0900)
committerjongmyeong ko <jongmyeong.ko@samsung.com>
Tue, 25 Apr 2017 04:15:35 +0000 (04:15 +0000)
- Fix to remove external data folder if exists
- Add some usage at help message

Change-Id: I308faac8988dfa31e1fffe7870896fcc3fee0ad8
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
(cherry picked from commit 2d68017e46577fedcb51ce760c2f7bc71d7acd69)
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
src/pkg_cleardata.c

index 363bf8247578a7c590fcf3e0bba87d4a7f76d5cf..1f8159aac307d1488fd987cf52bf69b825cc6d04 100644 (file)
@@ -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 <pkgid> \n");
-       printf("pkg_cleardata -d -n <pkgid> \n");
-       printf("pkg_cleardata -cd -n <pkgid> \n");
+       printf("pkg_cleardata -c -n <pkgid> -u <uid>\n");
+       printf("pkg_cleardata -d -n <pkgid> -u <uid>\n");
+       printf("pkg_cleardata -cd -n <pkgid> -u <uid>\n");
        printf("\n");
 }