Fix pkgmgr_installer to handle multiple request 77/222677/7
authorSangyoon Jang <jeremy.jang@samsung.com>
Tue, 20 Aug 2019 01:47:48 +0000 (10:47 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Thu, 19 Mar 2020 03:46:27 +0000 (12:46 +0900)
Change-Id: I6752c6037f38ee3602c802028fe42394133ed2c4
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
installer/pkgmgr_installer.c
installer/pkgmgr_installer.h

index 2521472fd62de3cc81a71dddbc5eebc7694d6d44..8962899b300466a9f84d05ad5b8d4001de937d5e 100644 (file)
@@ -119,6 +119,7 @@ struct pkgmgr_installer {
        int skip_optimization;
        GDBusConnection *conn;
        GHashTable *pkg_list;
+       GList *pkgs;
 };
 
 typedef struct pkg_signal_info {
@@ -407,6 +408,15 @@ API int pkgmgr_installer_free(pkgmgr_installer *pi)
        return 0;
 }
 
+static void __parse_multiple_pkgs(pkgmgr_installer *pi, int argc, char **argv)
+{
+       while ((optind <= argc) && (*argv[optind - 1] != '-')) {
+               pi->pkgs = g_list_append(pi->pkgs, strdup(argv[optind - 1]));
+               optind++;
+       }
+       optind--;
+}
+
 API int
 pkgmgr_installer_receive_request(pkgmgr_installer *pi,
                                 const int argc, char **argv)
@@ -425,6 +435,12 @@ pkgmgr_installer_receive_request(pkgmgr_installer *pi,
        g_target_uid = pi->target_uid;
        g_debug_mode = 0;
        g_skip_optimization = 0;
+
+       if (pi->pkgs) {
+               g_list_free_full(pi->pkgs, free);
+               pi->pkgs = NULL;
+       }
+
        while (1) {
                c = getopt_long(argc, argv, short_opts, long_opts, &opt_idx);
                /* printf("c=%d %c\n", c, c); //debug */
@@ -466,6 +482,7 @@ pkgmgr_installer_receive_request(pkgmgr_installer *pi,
                        if (pi->pkgmgr_info)
                                free(pi->pkgmgr_info);
                        pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
+                       __parse_multiple_pkgs(pi, argc, argv);
                        DBG("legacy extimg migration requested");
                        break;
                case OPTVAL_SKIP_CHECK_REFERENCE:
@@ -474,6 +491,7 @@ pkgmgr_installer_receive_request(pkgmgr_installer *pi,
                case OPTVAL_RECOVER_DB:
                        pi->request_type = PKGMGR_REQ_RECOVER_DB;
                        pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
+                       __parse_multiple_pkgs(pi, argc, argv);
                        break;
                case 'k':       /* session id */
                        if (pi->session_id)
@@ -497,6 +515,7 @@ pkgmgr_installer_receive_request(pkgmgr_installer *pi,
                        if (pi->pkgmgr_info)
                                free(pi->pkgmgr_info);
                        pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
+                       __parse_multiple_pkgs(pi, argc, argv);
                        DBG("option is [i] pkgid[%s]", pi->pkgmgr_info);
                        if (pi->pkgmgr_info && strlen(pi->pkgmgr_info) == 0) {
                                free(pi->pkgmgr_info);
@@ -532,6 +551,7 @@ pkgmgr_installer_receive_request(pkgmgr_installer *pi,
                        if (pi->pkgmgr_info)
                                free(pi->pkgmgr_info);
                        pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
+                       __parse_multiple_pkgs(pi, argc, argv);
                        break;
 
 
@@ -545,6 +565,7 @@ pkgmgr_installer_receive_request(pkgmgr_installer *pi,
                        if (pi->pkgmgr_info)
                                free(pi->pkgmgr_info);
                        pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
+                       __parse_multiple_pkgs(pi, argc, argv);
                        break;
 
                case 'm':       /* move */
@@ -557,6 +578,7 @@ pkgmgr_installer_receive_request(pkgmgr_installer *pi,
                        if (pi->pkgmgr_info)
                                free(pi->pkgmgr_info);
                        pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
+                       __parse_multiple_pkgs(pi, argc, argv);
                        break;
 
                case 'r':       /* reinstall */
@@ -569,6 +591,7 @@ pkgmgr_installer_receive_request(pkgmgr_installer *pi,
                        if (pi->pkgmgr_info)
                                free(pi->pkgmgr_info);
                        pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
+                       __parse_multiple_pkgs(pi, argc, argv);
                        break;
 
                case 't': /* move type*/
@@ -592,6 +615,7 @@ pkgmgr_installer_receive_request(pkgmgr_installer *pi,
                        if (pi->pkgmgr_info)
                                free(pi->pkgmgr_info);
                        pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
+                       __parse_multiple_pkgs(pi, argc, argv);
                        break;
 
                case 'o': /* optional data*/
@@ -602,12 +626,14 @@ pkgmgr_installer_receive_request(pkgmgr_installer *pi,
                        mode = 'y';
                        pi->request_type = PKGMGR_REQ_MANIFEST_DIRECT_INSTALL;
                        pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
+                       __parse_multiple_pkgs(pi, argc, argv);
                        break;
 
                case 'w': /* pkgid for mount installation */
                        mode = 'w';
                        pi->request_type = PKGMGR_REQ_MOUNT_INSTALL;
                        pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
+                       __parse_multiple_pkgs(pi, argc, argv);
                        break;
 
                case 'b': /* recovery */
@@ -620,6 +646,7 @@ pkgmgr_installer_receive_request(pkgmgr_installer *pi,
                        if (pi->pkgmgr_info)
                                free(pi->pkgmgr_info);
                        pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
+                       __parse_multiple_pkgs(pi, argc, argv);
                        break;
 
                case 'D': /* disable pkg */
@@ -627,6 +654,7 @@ pkgmgr_installer_receive_request(pkgmgr_installer *pi,
                        if (pi->pkgmgr_info)
                                free(pi->pkgmgr_info);
                        pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
+                       __parse_multiple_pkgs(pi, argc, argv);
                        break;
 
                case 'A': /* enable pkg */
@@ -634,6 +662,7 @@ pkgmgr_installer_receive_request(pkgmgr_installer *pi,
                        if (pi->pkgmgr_info)
                                free(pi->pkgmgr_info);
                        pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
+                       __parse_multiple_pkgs(pi, argc, argv);
                        break;
 
                case 'u': /* uid */
@@ -688,6 +717,19 @@ API const char *pkgmgr_installer_get_request_info(pkgmgr_installer *pi)
        return pi->pkgmgr_info;
 }
 
+API const char *pkgmgr_installer_get_request_info_at(pkgmgr_installer *pi,
+               int at)
+{
+       CHK_PI_RET(PKGMGR_REQ_INVALID);
+       return (const char *)g_list_nth_data(pi->pkgs, at);
+}
+
+API int pkgmgr_installer_get_request_info_count(pkgmgr_installer *pi)
+{
+       CHK_PI_RET(PKGMGR_REQ_INVALID);
+       return g_list_length(pi->pkgs);
+}
+
 API const char *pkgmgr_installer_get_tep_path(pkgmgr_installer *pi)
 {
        CHK_PI_RET(PKGMGR_REQ_INVALID);
index 3a4dfc5587c1897ff992914318383e76c0f8c580..87798df6390b729bb1ccd3f85be9b0d6978b38a3 100644 (file)
@@ -246,6 +246,74 @@ int main(int argc, char **argv)
  */
 const char *pkgmgr_installer_get_request_info(pkgmgr_installer *pi);
 
+/**
+       @brief          Get request info at specific position
+       @pre            pkgmgr_installer_receive_request() must be called.
+       @post           None
+       @see            pkgmgr_installer_receive_request
+       @see            pkgmgr_installer_get_request_info_count
+       @param[in]      pi      pkgmgr_installer object
+       @return         Request info. When PKGMGR_REQ_INSTALL, this is a package file path to be installed. When PKGMGR_REQ_UNINSTALL, this is a package name to be uninstalled.
+       @retval         NULL    on function failure
+       @remark         Returned string must not be modified.
+       @code
+#include <pkgmgr_installer.h>
+int main(int argc, char **argv)
+{
+       pkgmgr_installer *pi;
+       int r = 0;
+       char *req_info = NULL;
+
+       pi = pkgmgr_installer_new();
+       if(!pi) return -1;
+       if(pkgmgr_installer_receive_request(pi, argc, argv)) {
+               r = -1;
+               goto CLEANUP_RET;
+       }
+       req_info = (char *) pkgmgr_installer_get_request_info_at(pi, 1);
+
+       // Do something...
+
+       pkgmgr_installer_free(pi);
+       return r;
+}
+       @endcode
+ */
+const char *pkgmgr_installer_get_request_info_at(pkgmgr_installer *pi,
+               int at);
+
+/**
+       @brief          Get the number of request info
+       @pre            pkgmgr_installer_receive_request() must be called.
+       @post           None
+       @see            pkgmgr_installer_receive_request
+       @param[in]      pi      pkgmgr_installer object
+       @return         The number of request info.
+       @code
+#include <pkgmgr_installer.h>
+int main(int argc, char **argv)
+{
+       pkgmgr_installer *pi;
+       int r = 0;
+       int n;
+
+       pi = pkgmgr_installer_new();
+       if(!pi) return -1;
+       if(pkgmgr_installer_receive_request(pi, argc, argv)) {
+               r = -1;
+               goto CLEANUP_RET;
+       }
+       n = pkgmgr_installer_get_request_info_count(pi);
+
+       // Do something...
+
+       pkgmgr_installer_free(pi);
+       return r;
+}
+       @endcode
+ */
+int pkgmgr_installer_get_request_info_count(pkgmgr_installer *pi);
+
 /**
        @brief          Get TEP path
        @pre            pkgmgr_installer_receive_request() must be called.