Add --clear-all option to pkgcmd 24/89024/1
authorPiotr Dabrowski <p.dabrowski2@samsung.com>
Wed, 21 Sep 2016 12:07:14 +0000 (14:07 +0200)
committerPiotr Dabrowski <p.dabrowski2@samsung.com>
Wed, 21 Sep 2016 12:51:39 +0000 (14:51 +0200)
Usage:
  pkgcmd --clear-all
  pkgcmd --clear-all -t wgt
  pkgcmd --clear-all -t tpk

Change-Id: Idae766ed8b98f04efe4667cdba2f3fc232434430

src/pkg_cmd.c

index f2191de4ff764e4e912c25a6f0c3fc8c758ce65b..332dca2af0e3decf6700a845319c7396e581d7af 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
  * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
@@ -53,6 +53,7 @@
 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
 
 #define OPTVAL_GLOBAL 1000
+#define OPTVAL_CLEAR_ALL 1001
 
 static int __process_request(uid_t uid);
 static void __print_usage();
@@ -72,6 +73,7 @@ const struct option long_options[] = {
        {"mount-install", 0, NULL, 'w'},
        {"move", 0, NULL, 'm'},
        {"clear", 0, NULL, 'c'},
+       {"clear-all", 0, NULL, OPTVAL_CLEAR_ALL},
        {"getsize", 0, NULL, 'g'},
        {"activate", 0, NULL, 'A'},
        {"deactivate", 0, NULL, 'D'},
@@ -107,6 +109,7 @@ enum pm_tool_request_e {
        MOUNT_INSTALL_REQ,
        GETSIZE_REQ,
        CLEAR_REQ,
+       CLEAR_ALL_REQ,
        MOVE_REQ,
        ACTIVATE_REQ,
        DEACTIVATE_REQ,
@@ -382,16 +385,20 @@ static int __is_app_installed(char *pkgid, uid_t uid)
 
 static void __print_usage()
 {
-       printf("\nPackage Manager Tool Version: %s\n\n", PKG_TOOL_VERSION);
+       printf("\nPackage Manager Tool Version: %s\n", PKG_TOOL_VERSION);
+
+       printf("\n");
        printf("-i, --install           install the package\n");
        printf("-u, --uninstall         uninstall the package\n");
        printf("-r, --reinstall         reinstall the package\n");
        printf("-w, --mount-install     mount install the package\n");
        printf("-c, --clear             clear user data\n");
+       printf("    --clear-all         clear user data for all packages or packages type\n");
        printf("-m, --move              move package\n");
        printf("-g, --getsize           get size of given package\n");
-       printf("-T, --getsize-type      get type [0 : total size /1: data size]\n");
-       printf("-l, --list              display list of installed packages available for the current user [i.e. User's specific Apps and Global Apps] \n");
+       printf("-T, --getsize-type      get type [0: total size / 1: data size]\n");
+       printf("-l, --list              display list of installed packages available for the current user\n");
+       printf("                        i.e. user's specific apps and global apps\n");
        printf("-s, --show              show detail package info\n");
        printf("-a, --app-path          show app installation path\n");
        printf("-C, --check             check if applications belonging to a package are running or not\n");
@@ -400,33 +407,37 @@ static void __print_usage()
        printf("-p, --package-path      provide package path\n");
        printf("-n, --package-name      provide package name\n");
        printf("-t, --package-type      provide package type\n");
-       printf("-T, --move-type provide move type [0 : move to internal /1: move to external]\n");
-       printf("--global                Global Mode [Warning user should be privilegied to use this mode] \n");
-       printf("-e, --tep-path provide TEP package path\n");
-       printf("-M, --tep-move decide move/copy of TEP package[0:copy TEP package /1 : move TEP package, \n");
+       printf("-T, --move-type         provide move type [0: move to internal / 1: move to external]\n");
+       printf("    --global            Global Mode [Warning: user should be privilegied to use this mode]\n");
+       printf("-e, --tep-path          provide TEP package path\n");
+       printf("-M, --tep-move          decide move/copy of TEP package [0: copy TEP package / 1: move TEP package]\n");
        printf("-G, --debug-mode        install the package with debug mode for sdk\n");
-       printf("-h, --help      .       print this help\n\n");
+       printf("-h, --help              print this help\n");
 
+       printf("\n");
        printf("Usage: pkgcmd [options]\n");
        printf("pkgcmd -i -t <pkg type> (-d <descriptor path>) -p <pkg path> (--global)\n");
        printf("pkgcmd -u -n <pkgid> (--global)\n");
-       printf("pkgcmd -r -t <pkg type> -n <pkgid> (--global) \n");
+       printf("pkgcmd -r -t <pkg type> -n <pkgid> (--global)\n");
        printf("pkgcmd -w -t <pkg type> (-d <descriptor path>) -p <pkg path> (--global)\n");
-       printf("pkgcmd -l (-t <pkg type>) \n");
+       printf("pkgcmd -l (-t <pkg type>)\n");
        printf("pkgcmd -s -t <pkg type> -p <pkg path>\n");
        printf("pkgcmd -s -t <pkg type> -n <pkg name>\n");
-       printf("pkgcmd -m -t <pkg type> -T <move type> -n <pkg name>\n\n");
-       printf("pkgcmd -g -T <getsize type> -n <pkgid> \n");
-       printf("pkgcmd -C -n <pkgid> \n");
-       printf("pkgcmd -k -n <pkgid> \n");
-       printf("pkgcmd -X <old_pkg> -Y <new_pkg> -Z <delta_pkg> \n");
-
+       printf("pkgcmd -m -t <pkg type> -T <move type> -n <pkg name>\n");
+       printf("pkgcmd -g -T <getsize type> -n <pkgid>\n");
+       printf("pkgcmd -C -n <pkgid>\n");
+       printf("pkgcmd -k -n <pkgid>\n");
+       printf("pkgcmd --clear-all (-t <pkg type>)\n");
+       printf("pkgcmd -X <old_pkg> -Y <new_pkg> -Z <delta_pkg>\n");
+
+       printf("\n");
        printf("Example:\n");
        printf("pkgcmd -u -n org.example.hello\n");
        printf("pkgcmd -i -t tpk -p /tmp/org.example.hello-1.0.0-arm.tpk\n");
        printf("pkgcmd -r -t tpk -n org.example.hello\n");
        printf("pkgcmd -w -t tpk -p /tmp/org.example.hello-1.0.0-arm.tpk\n");
        printf("pkgcmd -c -t tpk -n org.example.hello\n");
+       printf("pkgcmd --clear-all -t wgt\n");
        printf("pkgcmd -m -t tpk -T 1 -n org.example.hello\n");
        printf("pkgcmd -C -n org.example.hello\n");
        printf("pkgcmd -k -n org.example.hello\n");
@@ -436,8 +447,8 @@ static void __print_usage()
        printf("pkgcmd -l -t tpk\n");
        printf("pkgcmd -g -T 0 -n org.example.hello\n");
 
+       printf("\n");
        exit(0);
-
 }
 
 static int __pkgmgr_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data)
@@ -535,6 +546,40 @@ static void __total_pkg_size_info_recv_cb(pkgmgr_client *pc, const pkg_size_info
        g_main_loop_quit(main_loop);
 }
 
+static int __pkgmgr_list_clear_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+       int ret = -1;
+       char *pkgid = NULL;
+       char *pkg_type = NULL;
+
+       ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+       if (ret == -1) {
+               printf("Failed to get pkgmgrinfo_pkginfo_get_pkgid\n");
+               return ret;
+       }
+       ret = pkgmgrinfo_pkginfo_get_type(handle, &pkg_type);
+       if (ret == -1) {
+               printf("Failed to get pkgmgrinfo_pkginfo_get_type\n");
+               return ret;
+       }
+
+       pkgmgrinfo_uidinfo_t *uid_info = (pkgmgrinfo_uidinfo_t *) handle;
+       uid_t uid = uid_info->uid;
+
+       pkgmgr_client *pc = pkgmgr_client_new(PC_REQUEST);
+       if (pc == NULL) {
+               printf("PkgMgr Client Creation Failed\n");
+               return -1;
+       }
+       ret = pkgmgr_client_usr_clear_user_data(pc, pkg_type, pkgid, PM_QUIET,
+                                               uid);
+       if (ret >= 0)
+         ret = data.result;
+       pkgmgr_client_free(pc);
+
+       return ret;
+}
+
 static int __process_request(uid_t uid)
 {
        int ret = -1;
@@ -757,6 +802,45 @@ static int __process_request(uid_t uid)
                ret = data.result;
                break;
 
+       case CLEAR_ALL_REQ:
+               if (data.pkg_type[0] == '\0') {
+                       ret = 0;
+                       if (uid != GLOBAL_USER)
+                               ret = pkgmgrinfo_pkginfo_get_usr_list(__pkgmgr_list_clear_cb, NULL, uid);
+                       else
+                               ret = pkgmgrinfo_pkginfo_get_list(__pkgmgr_list_clear_cb, NULL);
+
+                       if (ret == -1)
+                               printf("no packages found\n");
+                       break;
+               } else {
+                       pkgmgrinfo_pkginfo_filter_h handle;
+
+                       ret = pkgmgrinfo_pkginfo_filter_create(&handle);
+                       if (ret == -1) {
+                               printf("Failed to get package filter handle\n");
+                               break;
+                       }
+
+                       ret = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_TYPE, data.pkg_type);
+                       if (ret == -1) {
+                               printf("Failed to add package type filter\n");
+                               pkgmgrinfo_pkginfo_filter_destroy(handle);
+                               break;
+                       }
+
+                       if (uid != GLOBAL_USER)
+                               ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, __pkgmgr_list_clear_cb, NULL, uid);
+                       else
+                               ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, __pkgmgr_list_clear_cb, NULL);
+
+                       if (ret != PMINFO_R_OK)
+                               printf("no package filter list\n");
+
+                       pkgmgrinfo_pkginfo_filter_destroy(handle);
+                       break;
+               }
+
        case ACTIVATE_REQ:
                if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') {
                        printf("Please provide the arguments.\n");
@@ -1147,6 +1231,10 @@ int main(int argc, char *argv[])
                        data.request = CLEAR_REQ;
                        break;
 
+               case OPTVAL_CLEAR_ALL:  /* clear all */
+                       data.request = CLEAR_ALL_REQ;
+                       break;
+
                case 'g':  /* get pkg size */
                        data.request = GETSIZE_REQ;
                        break;