From: Sangyoon Jang Date: Fri, 22 May 2020 06:04:00 +0000 (+0900) Subject: Convert relative path to absolute path for multi pkg install X-Git-Tag: submit/tizen/20200601.023448~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F27%2F234127%2F2;p=platform%2Fcore%2Fappfw%2Fpkgmgr-tool.git Convert relative path to absolute path for multi pkg install Change-Id: I42fd0540935c2538d5e982a8581e8a1ac71201d0 Signed-off-by: Sangyoon Jang --- diff --git a/src/pkg_cmd.c b/src/pkg_cmd.c index ff3ec65..930c051 100644 --- a/src/pkg_cmd.c +++ b/src/pkg_cmd.c @@ -296,48 +296,37 @@ static int __app_return_cb(uid_t target_uid, int req_id, const char *pkg_type, static int __convert_to_absolute_path(pm_tool_args *data) { char abs[PATH_MAX] = {'\0'}; - char temp[PATH_MAX] = {'\0'}; + char *temp; char *ptr = NULL; int ret; - if (data->pkg_path[0] == '\0') { - printf("path is NULL\n"); + GList *list; + + ptr = realpath(data->pkg_path, abs); + if (ptr == NULL) { + printf("realpath fail: %d\n", errno); return -1; } - ret = snprintf(temp, PATH_MAX - 1, "%s", data->pkg_path); - if (ret < 0 || ret > PATH_MAX - 1) { + ret = snprintf(data->pkg_path, PKG_NAME_STRING_LEN_MAX - 1, "%s", abs); + if (ret < 0 || ret > PKG_NAME_STRING_LEN_MAX - 1) { printf("snprintf fail\n"); return -1; } - if (strchr(data->pkg_path, '/') == NULL) { - if (getcwd(abs, PKG_NAME_STRING_LEN_MAX - 1) == NULL) { - printf("getcwd() failed\n"); - return -1; - } - memset(data->pkg_path, '\0', PKG_NAME_STRING_LEN_MAX); - ret = snprintf(data->pkg_path, PKG_NAME_STRING_LEN_MAX - 1, - "%s/%s", abs, temp); - if (ret < 0 || ret > PKG_NAME_STRING_LEN_MAX - 1) { - printf("snprintf fail\n"); - return -1; - } - return 0; - } - if (strncmp(data->pkg_path, "./", 2) == 0) { - ptr = temp; - if (getcwd(abs, PKG_NAME_STRING_LEN_MAX - 1) == NULL) { - printf("getcwd() failed\n"); + + for (list = data->pkgs; list; list = list->next) { + ptr = realpath(list->data, abs); + if (ptr == NULL) { + printf("realpath fail: %d\n", errno); return -1; } - ptr = ptr + 2; - memset(data->pkg_path, '\0', PKG_NAME_STRING_LEN_MAX); - ret = snprintf(data->pkg_path, PKG_NAME_STRING_LEN_MAX - 1, - "%s/%s", abs, ptr); - if (ret < 0 || ret > PKG_NAME_STRING_LEN_MAX - 1) { - printf("snprintf fail\n"); + temp = list->data; + list->data = strdup(abs); + if (list->data == NULL) { + printf("out of memory\n"); return -1; } - return 0; + free(temp); } + return 0; } @@ -1693,6 +1682,7 @@ int main(int argc, char *argv[]) if (optarg) snprintf(data.pkg_path, sizeof(data.pkg_path), "%s", optarg); + __parse_multiple_pkgs(&data, argc, argv); ret = __convert_to_absolute_path(&data); if (ret == -1) { printf("conversion of relative path to absolute path failed\n"); @@ -1700,8 +1690,6 @@ int main(int argc, char *argv[]) return -1; } printf("path is %s\n", data.pkg_path); - - __parse_multiple_pkgs(&data, argc, argv); break; case 'X': /* old_tpk */