Fix pkg_upgrade tool to handle wgt packages 38/177838/4
authorSangyoon Jang <jeremy.jang@samsung.com>
Fri, 4 May 2018 04:17:12 +0000 (13:17 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Mon, 14 May 2018 05:32:29 +0000 (05:32 +0000)
Change-Id: I7490454a0d08303f141cadc2ae3ca573fffe55fa
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/pkg_upgrade.c

index 6ca29db..eb7b1c9 100644 (file)
@@ -408,7 +408,8 @@ char *__manifest_to_package(const char *manifest)
        return package;
 }
 
-static void __send_args_to_backend(char *pkgid, int operation)
+static void __send_args_to_backend(char *pkgid, const char *pkgtype,
+               int operation)
 {
        int ret = 0;
 
@@ -418,13 +419,14 @@ static void __send_args_to_backend(char *pkgid, int operation)
        gettimeofday(&tv, NULL);
        starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
        char buf[BUF_SIZE];
+       char backend_cmd[BUF_SIZE];
 
-       const char *install_ro[] = { "/usr/bin/tpk-backend", "-y", pkgid,
+       const char *install_ro[] = { backend_cmd, "-y", pkgid,
                                "--preload", "--partial-rw", NULL };
-       const char *uninstall_ro[] = { "/usr/bin/tpk-backend", "-d", pkgid,
+       const char *uninstall_ro[] = { backend_cmd, "-d", pkgid,
                                "--preload", "--force-remove",
                                "--partial-rw", NULL };
-       const char *uninstall_ro_update[] = { "/usr/bin/tpk-backend", "-d",
+       const char *uninstall_ro_update[] = { backend_cmd, "-d",
                                pkgid, "--keep-rwdata", NULL };
        const char *db_update_to_normal_pkg[] = {"/usr/bin/sqlite3",
                                NULL, NULL, NULL};
@@ -435,6 +437,9 @@ static void __send_args_to_backend(char *pkgid, int operation)
        if (__compare_builtin_removable_pkgid(pkgid) < 0)
                return;
 
+       snprintf(backend_cmd, sizeof(backend_cmd), "/usr/bin/%s-backend",
+                       pkgtype);
+
        switch (operation) {
        case PKG_NEED_INSTALL:
        case PKG_NEED_ROUPDATE:
@@ -652,6 +657,7 @@ static int __find_matched_pkgid_from_list(const char *source_file,
        char buf[BUF_SIZE] = {0};
        char *pkgid = NULL;
        char *version = NULL;
+       char *pkgtype = NULL;
 
        int same_pkg_cnt = 0;
        int update_pkg_cnt = 0;
@@ -676,6 +682,7 @@ static int __find_matched_pkgid_from_list(const char *source_file,
                        continue;
 
                version = __getvalue(buf, TOKEN_VERSION_STR, 1);
+               pkgtype = __getvalue(buf, TOKEN_TYPE_STR, 1);
 
                compare_result = __compare_pkgid((char *)target_file, pkgid,
                                                version, &db_update);
@@ -701,11 +708,12 @@ static int __find_matched_pkgid_from_list(const char *source_file,
                }
 
                total_pkg_cnt++;
-               __send_args_to_backend(pkgid, operation);
+               __send_args_to_backend(pkgid, pkgtype, operation);
 
                memset(buf, 0x00, BUF_SIZE);
                FREE_AND_NULL(pkgid);
                FREE_AND_NULL(version);
+               FREE_AND_NULL(pkgtype);
        }
 
        _LOG("-------------------------------------------------------\n");
@@ -730,6 +738,7 @@ static int __find_deleted_pkgid_from_list(const char *source_file,
        char buf[BUF_SIZE] = {0};
        char *pkgid = NULL;
        char *version = NULL;
+       char *pkgtype = NULL;
        char *update = NULL;
        bool xml_update;
        int deleted_pkg_cnt = 0;
@@ -751,6 +760,7 @@ static int __find_deleted_pkgid_from_list(const char *source_file,
                        continue;
 
                version = __getvalue(buf, TOKEN_VERSION_STR, 1);
+               pkgtype = __getvalue(buf, TOKEN_TYPE_STR, 1);
 
                compare_result = __compare_pkgid((char *)target_file, pkgid,
                                                version, &xml_update);
@@ -762,11 +772,11 @@ static int __find_deleted_pkgid_from_list(const char *source_file,
                                continue;
                        }
                        if (!strncmp(update, "false", strlen("false"))) {
-                               __send_args_to_backend(pkgid,
+                               __send_args_to_backend(pkgid, pkgtype,
                                                PKG_NEED_UNINSTALL);
                                deleted_pkg_cnt++;
                        } else {
-                               __send_args_to_backend(pkgid,
+                               __send_args_to_backend(pkgid, pkgtype,
                                                PKG_NEED_UPDATE_TO_RW);
                                modified_pkg_cnt++;
                        }
@@ -776,6 +786,7 @@ static int __find_deleted_pkgid_from_list(const char *source_file,
                memset(buf, 0x00, BUF_SIZE);
                FREE_AND_NULL(pkgid);
                FREE_AND_NULL(version);
+               FREE_AND_NULL(pkgtype);
                FREE_AND_NULL(update);
        }
 
@@ -861,7 +872,7 @@ static int __process_ro_fota()
        return 0;
 }
 
-static int __process_rw_fota(const char *directory)
+static int __process_rw_fota(const char *directory, const char *pkgtype)
 {
        retvm_if(directory == NULL, -1, "directory is null\n");
 
@@ -870,12 +881,13 @@ static int __process_rw_fota(const char *directory)
        DIR *dir;
        struct dirent *entry = NULL;
        long total_time = 0;
+       char backend_cmd[BUF_SIZE];
 
        dir = opendir(directory);
        retvm_if(dir == NULL, -1, "Failed to access the [%s]\n", directory);
 
        _LOG("=======================================================\n");
-       _LOG("RW preload package fota\n");
+       _LOG("RW preload package fota (%s)\n", pkgtype);
        _LOG("=======================================================\n");
 
        while ((entry = readdir(dir)) != NULL) {
@@ -968,8 +980,10 @@ static int __process_rw_fota(const char *directory)
                        _LOG("pkgid[%s] is new\n", pkg_info->pkgid);
                }
 
-               const char *install_rw[] = { "/usr/bin/tpk-backend", "-y",
+               const char *install_rw[] = { backend_cmd, "-y",
                        pkg_info->pkgid, "--preload-rw", NULL };
+               snprintf(backend_cmd, sizeof(backend_cmd),
+                               "/usr/bin/%s-backend", pkgtype);
                ret = __xsystem(install_rw);
                if (ret == 0)
                        _LOG("success request\n");
@@ -1005,10 +1019,10 @@ int main(int argc, char *argv[])
                        retvm_if(ret < 0, EXIT_FAILURE,
                                "__process_ro_fota is failed.\n");
                } else if (strcmp(argv[1], "-rwf") == 0) {
-                       ret = __process_rw_fota(PRELOAD_RW_TPK_PATH);
+                       ret = __process_rw_fota(PRELOAD_RW_TPK_PATH, "tpk");
                        retvm_if(ret < 0, EXIT_FAILURE,
                                "PRELOAD_RW_TPK_PATH is failed.\n");
-                       ret = __process_rw_fota(PRELOAD_RW_WGT_PATH);
+                       ret = __process_rw_fota(PRELOAD_RW_WGT_PATH, "wgt");
                        retvm_if(ret < 0, EXIT_FAILURE,
                                "PRELOAD_RW_WGT_PATH is failed.\n");
                } else {