change input param on get size api, add smack label after pkg_initdb submit/tizen_2.1/20130514.054730
authorjunsuk77.oh <junsuk77.oh@samsung.com>
Mon, 13 May 2013 09:03:36 +0000 (18:03 +0900)
committerjunsuk77.oh <junsuk77.oh@samsung.com>
Mon, 13 May 2013 09:03:36 +0000 (18:03 +0900)
Change-Id: I10431458942366e8cc538e34866580784a5a8793
Signed-off-by: junsuk77.oh <junsuk77.oh@samsung.com>
client/include/package-manager.h
client/src/pkgmgr.c
packaging/pkgmgr.spec
tool/pkg_cmd.c
tool/pkg_getsize.c
tool/pkg_initdb.c

index 0f907100b6a9b5776cc748e3b2d1b630a82b6326..72f49396089a2df8d451bfa2ccfdd713313c7227 100755 (executable)
@@ -260,6 +260,11 @@ typedef enum {
        PM_REQUEST_MAX
 }pkgmgr_request_service_type;
 
+typedef enum {
+       PM_GET_TOTAL_SIZE= 0,
+       PM_GET_DATA_SIZE = 1,
+}pkgmgr_getsize_type;
+
 /**
  * @brief      This API creates pkgmgr client.
  *
index 79d6d59e8044e57458b7fe6631b3942b51cc6646..baf4a278d095814cdbafa47db0ac24e04357077c 100755 (executable)
@@ -578,10 +578,10 @@ static int __csc_process(const char *csc_path, char *result_path)
                if (ret != 0) {
                        char *errstr = NULL;
                        __error_to_string(ret, &errstr);
-                       snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = fail[%s]\n", cnt, pkgtype, errstr);
+                       snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = fail[%s]\n", cnt, errstr);
                }
                else
-                       snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = success\n", cnt, pkgtype);
+                       snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = success\n", cnt);
 
                fwrite(buf, 1, strlen(buf), file);
        }
@@ -597,7 +597,7 @@ catch:
        return ret;
 }
 
-static int __get_size_process(pkgmgr_client * pc, char *pkgid, pkgmgr_handler event_cb)
+static int __get_size_process(pkgmgr_client * pc, const char *pkgid, pkgmgr_getsize_type get_type, pkgmgr_handler event_cb)
 {
        char *req_key = NULL;
        int req_id = 0;
@@ -611,6 +611,7 @@ static int __get_size_process(pkgmgr_client * pc, char *pkgid, pkgmgr_handler ev
        int len = 0;
        char *temp = NULL;
        int i = 0;
+       char buf[128] = {'\0'};
 
        pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
        retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n");
@@ -626,6 +627,8 @@ static int __get_size_process(pkgmgr_client * pc, char *pkgid, pkgmgr_handler ev
        req_id = _get_request_id();
        __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL);
 
+
+       snprintf(buf, 128, "%d", get_type);
        argv[argcnt++] = installer_path;
        /* argv[1] */
        argv[argcnt++] = strdup("-k");
@@ -635,6 +638,10 @@ static int __get_size_process(pkgmgr_client * pc, char *pkgid, pkgmgr_handler ev
        argv[argcnt++] = strdup("-d");
        /* argv[4] */
        argv[argcnt++] = strdup(pkgid);
+       /* argv[5] */
+       argv[argcnt++] = strdup("-t");
+       /* argv[6] */
+       argv[argcnt++] = strdup(buf);
 
        /*** add quote in all string for special charactor like '\n'***   FIX */
        for (i = 0; i < argcnt; i++) {
@@ -672,7 +679,7 @@ catch:
        return ret;
 }
 
-static int __move_pkg_process(pkgmgr_client * pc, char *pkgid, pkgmgr_move_type move_type, pkgmgr_handler event_cb)
+static int __move_pkg_process(pkgmgr_client * pc, const char *pkgid, pkgmgr_move_type move_type, pkgmgr_handler event_cb)
 {
        char *req_key = NULL;
        int req_id = 0;
@@ -1879,7 +1886,7 @@ API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type,
                tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
                tryvm_if((service_mode < PM_MOVE_TO_INTERNAL) || (service_mode > PM_MOVE_TO_SDCARD), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
 
-               ret = __move_pkg_process(pc, pkgid, service_mode, event_cb);
+               ret = __move_pkg_process(pc, pkgid, (pkgmgr_move_type)service_mode, event_cb);
                if (ret < 0)
                        _LOGE("__move_pkg_process fail \n");
                else
@@ -1890,8 +1897,9 @@ API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type,
        case PM_REQUEST_GET_SIZE:
                tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
                tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
+               tryvm_if((service_mode < PM_GET_TOTAL_SIZE) || (service_mode > PM_GET_DATA_SIZE), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
 
-               ret = __get_size_process(pc, pkgid, event_cb);
+               ret = __get_size_process(pc, pkgid, (pkgmgr_getsize_type)service_mode, event_cb);
                if (ret < 0)
                        _LOGE("__get_size_process fail \n");
                else
index cf419af212eec42ccf6cfee397d0b4f9be9380b2..9229439e0d06e99161a98fe62f6c4146e989d357 100755 (executable)
@@ -1,7 +1,7 @@
 #sbs-git:slp/pkgs/s/slp-pkgmgr pkgmgr 0.1.103 29b53909a5d6e8728429f0a188177eac691cb6ce
 Name:       pkgmgr
 Summary:    Packager Manager client library package
-Version:    0.2.85
+Version:    0.2.87
 Release:    1
 Group:      System/Libraries
 License:    Apache License, Version 2.0
index 576c42bbddff11575f21229bd3784f301077f237..b8d2de46392452a27efbb5d924d36919b10af84c 100755 (executable)
@@ -80,6 +80,7 @@ const struct option long_options[] = {
        {"package-type", 1, NULL, 't'},
        {"package-name", 1, NULL, 'n'},
        {"move-type", 1, NULL, 'T'},
+       {"getsize-type", 1, NULL, 'T'},
        {"csc", 1, NULL, 'S'},
        {"quiet", 0, NULL, 'q'},
        {"help", 0, NULL, 'h'},
@@ -113,7 +114,7 @@ struct pm_tool_args_t {
        char des_path[PKG_NAME_STRING_LEN_MAX];
        char label[PKG_NAME_STRING_LEN_MAX];
        int quiet;
-       int move_type;
+       int type;
        int result;
 };
 typedef struct pm_tool_args_t pm_tool_args;
@@ -429,6 +430,7 @@ static void __print_usage()
        printf("-c, --clear             clear user data\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\n");
        printf("-s, --show              show detail package info\n");
        printf("-a, --app-path          show app installation path\n");
@@ -450,21 +452,21 @@ static void __print_usage()
        printf("pkgcmd -s -t <pkg type> -p <pkg path> (-q)\n");
        printf("pkgcmd -s -t <pkg type> -n <pkg name> (-q)\n");
        printf("pkgcmd -m -t <pkg type> -T <move type> -n <pkg name> (-q)\n\n");
-       printf("pkgcmd -g -n <pkgid> \n");
+       printf("pkgcmd -g -T <getsize type> -n <pkgid> \n");
 
        printf("Example:\n");
-       printf("pkgcmd -u -t rpm -n org.tizen.calculator\n");
-       printf("pkgcmd -i -t rpm -p /mnt/nfs/org.tizen.calculator_0.1.2-95_armel.rpm\n");
-       printf("pkgcmd -r -t rpm -p org.tizen.calculator\n");
-       printf("pkgcmd -c -t rpm -n org.tizen.hello\n");
-       printf("pkgcmd -m -t rpm -T 1 -n org.tizen.hello\n");
-       printf("pkgcmd -C -t rpm -n org.tizen.hello\n");
-       printf("pkgcmd -k -t rpm -n org.tizen.hello\n");
+       printf("pkgcmd -u -n com.samsung.calculator\n");
+       printf("pkgcmd -i -t rpm -p /mnt/nfs/com.samsung.calculator_0.1.2-95_armel.rpm\n");
+       printf("pkgcmd -r -t rpm -n com.samsung.calculator\n");
+       printf("pkgcmd -c -t rpm -n com.samsung.hello\n");
+       printf("pkgcmd -m -t rpm -T 1 -n com.samsung.hello\n");
+       printf("pkgcmd -C -t rpm -n com.samsung.hello\n");
+       printf("pkgcmd -k -t rpm -n com.samsung.hello\n");
        printf("pkgcmd -a\n");
-       printf("pkgcmd -a -t rpm -n org.tizen.hello\n");
+       printf("pkgcmd -a -t rpm -n com.samsung.hello\n");
        printf("pkgcmd -l\n");
        printf("pkgcmd -l -t tpk\n");
-       printf("pkgcmd -g -n com.samsung.calculator\n");
+       printf("pkgcmd -g -T 0 -n com.samsung.calculator\n");
 
        exit(0);
 
@@ -824,7 +826,7 @@ static int __process_request()
                                ret = -1;
                                break;
                        }
-                       if (data.move_type < 0 || data.move_type > 1) {
+                       if (data.type < 0 || data.type > 1) {
                                printf("Invalid move type...See usage\n");
                                ret = -1;
                                break;
@@ -841,7 +843,7 @@ static int __process_request()
                                printf("package is not installed\n");
                                break;
                        }
-                       ret = pkgmgr_client_move(pc, data.pkg_type, data.pkgid,  data.move_type, mode);
+                       ret = pkgmgr_client_move(pc, data.pkg_type, data.pkgid,  data.type, mode);
                        if (ret < 0)
                                break;
                        ret = data.result;
@@ -852,7 +854,7 @@ static int __process_request()
                                ret = -1;
                                break;
                        }
-                       if (data.move_type < 0 || data.move_type > 1) {
+                       if (data.type < 0 || data.type > 1) {
                                printf("Invalid move type...See usage\n");
                                ret = -1;
                                break;
@@ -870,7 +872,7 @@ static int __process_request()
                                printf("package is not installed\n");
                                break;
                        }
-                       ret = pkgmgr_client_request_service(PM_REQUEST_MOVE, data.move_type, pc, NULL, data.pkgid, NULL, __return_cb, NULL);
+                       ret = pkgmgr_client_request_service(PM_REQUEST_MOVE, data.type, pc, NULL, data.pkgid, NULL, __return_cb, NULL);
                        if (ret < 0)
                                break;
                        g_main_loop_run(main_loop);
@@ -1019,6 +1021,11 @@ static int __process_request()
                        data.result = PKGCMD_ERR_ARGUMENT_INVALID;
                        break;
                }
+               if (data.type < 0 || data.type > 1) {
+                       printf("Invalid get type...See usage\n");
+                       ret = -1;
+                       break;
+               }
 
                g_type_init();
                main_loop = g_main_loop_new(NULL, FALSE);
@@ -1029,11 +1036,9 @@ static int __process_request()
                        break;
                }
 
-               ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, 0, pc, NULL, data.pkgid, NULL, __return_cb, NULL);
+               ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, data.type, pc, NULL, data.pkgid, NULL, __return_cb, NULL);
                if (ret < 0){
                        data.result = PKGCMD_ERR_FATAL_ERROR;
-                       if (access(data.pkg_path, F_OK) != 0)
-                               data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
                        break;
                }
                g_main_loop_run(main_loop);
@@ -1101,7 +1106,7 @@ int main(int argc, char *argv[])
        memset(data.label, '\0', PKG_TYPE_STRING_LEN_MAX);
        data.quiet = 0;
        data.result = 0;
-       data.move_type = -1;
+       data.type = -1;
        while (1) {
                c = getopt_long(argc, argv, short_options, long_options,
                                &opt_idx);
@@ -1205,7 +1210,7 @@ int main(int argc, char *argv[])
                        break;
 
                case 'T':       /* move type */
-                       data.move_type = atoi(optarg);
+                       data.type = atoi(optarg);
                        break;
 
                case 'h':       /* help */
index 11822e05f2eb367c9d727c8c4ac4dbe706c66774..1e3143a8855250839ca1c643a746534402b87ffc 100644 (file)
@@ -44,8 +44,9 @@ static int _pkg_getsize(int argc, char **argv)
        char *pkgid = NULL;
        char *type = NULL;
        pkgmgr_installer *pi = NULL;
-       pkgmgrinfo_pkginfo_h handle;
+       pkgmgrinfo_pkginfo_h handle = NULL;
        int size = 0;
+       int get_type = -1;
        char buf[MAX_PKG_BUF_LEN] = {'\0'};
 
        /*make new pkgmgr_installer handle*/
@@ -60,6 +61,9 @@ static int _pkg_getsize(int argc, char **argv)
        pkgid = pkgmgr_installer_get_request_info(pi);
        tryvm_if(pkgid == NULL, ret = PMINFO_R_ERROR, "pkgmgr_installer_get_request_info failed");
 
+       get_type = pkgmgr_installer_get_move_type(pi);
+       tryvm_if(pkgid < 0, ret = PMINFO_R_ERROR, "pkgmgr_installer_get_request_info failed");
+
        /*get pkgmgr handle from pkgid*/
        ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
        tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_pkginfo_get_pkginfo[pkgid=%s] failed", pkgid);
@@ -68,9 +72,20 @@ static int _pkg_getsize(int argc, char **argv)
        ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
        tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_pkginfo_get_type[pkgid=%s] failed", pkgid);
 
-       /*get size info from handle*/
-       ret = pkgmgrinfo_pkginfo_get_total_size(handle, &size);
-       tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_pkginfo_get_total_size[pkgid=%s] failed", pkgid);
+       /*get size info from handle
+       typedef enum {
+               PM_GET_TOTAL_SIZE= 0,
+               PM_GET_DATA_SIZE = 1,
+       }pkgmgr_getsize_type;
+
+       */
+       if (get_type == 0) {
+               ret = pkgmgrinfo_pkginfo_get_total_size(handle, &size);
+               tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_pkginfo_get_total_size[pkgid=%s] failed", pkgid);
+       } else {
+               ret = pkgmgrinfo_pkginfo_get_data_size(handle, &size);
+               tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_pkginfo_get_data_size[pkgid=%s] failed", pkgid);
+       }
 
        snprintf(buf, MAX_PKG_BUF_LEN - 1, "%d", size);
 
index 5601fb8ea0efec3b91b4fc88b72eb6ca89bbe6c9..50db299cb92f1a206cd8c0d82386706d6ea13bc8 100755 (executable)
 #define USR_MANIFEST_DIRECTORY "/usr/share/packages"
 #define PACKAGE_INFO_DB_FILE "/opt/dbspace/.pkgmgr_parser.db"
 
+#define PKG_PARSER_DB_FILE "/opt/dbspace/.pkgmgr_parser.db"
+#define PKG_PARSER_DB_FILE_JOURNAL "/opt/dbspace/.pkgmgr_parser.db-journal"
+#define PKG_CERT_DB_FILE "/opt/dbspace/.pkgmgr_cert.db"
+#define PKG_CERT_DB_FILE_JOURNAL "/opt/dbspace/.pkgmgr_cert.db-journal"
+#define PKG_INFO_DB_LABEL "pkgmgr::db"
+
 #ifdef _E
 #undef _E
 #endif
@@ -56,6 +62,38 @@ static int initdb_count_package(void)
        return total;
 }
 
+static int initdb_xsystem(const char *argv[])
+{
+       int status = 0;
+       pid_t pid;
+       pid = fork();
+       switch (pid) {
+       case -1:
+               perror("fork failed");
+               return -1;
+       case 0:
+               /* child */
+               execvp(argv[0], (char *const *)argv);
+               _exit(-1);
+       default:
+               /* parent */
+               break;
+       }
+       if (waitpid(pid, &status, 0) == -1) {
+               perror("waitpid failed");
+               return -1;
+       }
+       if (WIFSIGNALED(status)) {
+               perror("signal");
+               return -1;
+       }
+       if (!WIFEXITED(status)) {
+               /* shouldn't happen */
+               perror("should not happen");
+               return -1;
+       }
+       return WEXITSTATUS(status);
+}
 
 
 char* _manifest_to_package(const char* manifest)
@@ -224,6 +262,15 @@ int main(int argc, char *argv[])
                return -1;
        }
 
+       const char *argv_parser[] = { "/usr/bin/chsmack", "-a", PKG_INFO_DB_LABEL, PKG_PARSER_DB_FILE, NULL };
+       initdb_xsystem(argv_parser);
+       const char *argv_parserjn[] = { "/usr/bin/chsmack", "-a", PKG_INFO_DB_LABEL, PKG_PARSER_DB_FILE_JOURNAL, NULL };
+       initdb_xsystem(argv_parserjn);
+       const char *argv_cert[] = { "/usr/bin/chsmack", "-a", PKG_INFO_DB_LABEL, PKG_CERT_DB_FILE, NULL };
+       initdb_xsystem(argv_cert);
+       const char *argv_certjn[] = { "/usr/bin/chsmack", "-a", PKG_INFO_DB_LABEL, PKG_CERT_DB_FILE_JOURNAL, NULL };
+       initdb_xsystem(argv_certjn);
+
        return 0;
 }