From: greatim Date: Fri, 9 Dec 2016 07:47:09 +0000 (+0900) Subject: Modify the path that is copied package file X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3c6f28bf29001464f1842a00afb5d6e683aa5346;p=sdk%2Ftools%2Fsdb.git Modify the path that is copied package file - Change the path to copy the package file to the SDK too path in platform Change-Id: I9a4f58f79898139ed604b06ff6c8b60823b1aa9c Signed-off-by: greatim --- diff --git a/src/command_function.c b/src/command_function.c index e14d8b9..e36874b 100644 --- a/src/command_function.c +++ b/src/command_function.c @@ -59,7 +59,7 @@ static void __inline__ format_host_command(char* buffer, size_t buflen, const c static int get_pkgtype_file_name(const char* file_name); static int kill_gdbserver_if_running(const char* process_cmd); static int verify_gdbserver_exist(); -static int get_pkg_tmp_dir(char* pkg_tmp_dir); +static int get_pkg_tmp_dir(char* pkg_tmp_dir, int len); int da(int argc, char ** argv) { char full_cmd[PATH_MAX] = "shell:/usr/bin/da_command"; @@ -703,9 +703,10 @@ static int is_support_debug_option(void){ char cap_buffer[CAPBUF_SIZE] = {0,}; uint16_t len = 0; int ret = -1; + char* failmsg = NULL; snprintf(full_cmd, sizeof(full_cmd), "capability:"); - int fd = sdb_connect(full_cmd); + int fd = sdb_connect_getfailmsg(full_cmd, &failmsg); if (fd >= 0) { readx(fd, &len, sizeof(uint16_t)); if (len > CAPBUF_SIZE-1) { @@ -722,6 +723,12 @@ static int is_support_debug_option(void){ if (ret == 1) { return ret; } + } else { + D("This platform does not support the capability service.\n"); + if (failmsg != NULL) { + D("sdb_connect() fail message : %s\n", failmsg); + SAFE_FREE(failmsg); + } } /* This routine is temporarily coded in a state that the app @@ -778,8 +785,8 @@ int install(int argc, char **argv) { char* srcpath = argv[1]; const char* filename = sdb_dirstop(srcpath); - char destination[PATH_MAX]; - if(get_pkg_tmp_dir(destination) < 0) { + char destination[PATH_MAX] = {0,}; + if(get_pkg_tmp_dir(destination, sizeof(destination)) < 0) { return 1; } @@ -886,28 +893,91 @@ int get_capability(int argc, char ** argv) { return 1; } -// Get the package temporary path. Returns minus if exception happens. -static int get_pkg_tmp_dir(char* pkg_tmp_dir){ +static int get_pkg_tmp_dir_from_capability(char* pkg_tmp_dir, int len) { + char cap_buffer[CAPBUF_SIZE] = {0,}; + const char* GET_CAPABILITY_CMD = "capability:"; + int fd = -1; + int cap_data_size = 0; + int ret = -1; + char* failmsg = NULL; - char buf[512] = {}; + fd = sdb_connect_getfailmsg(GET_CAPABILITY_CMD, &failmsg); + if(fd < 0) { + D("This platform does not support the capability service.\n"); + if (failmsg != NULL) { + D("sdb_connect() fail message : %s\n", failmsg); + SAFE_FREE(failmsg); + } + return -1; + } + + readx(fd, &cap_data_size, sizeof(uint16_t)); + if (cap_data_size > CAPBUF_SIZE-1) { + cap_data_size = CAPBUF_SIZE-1; + } + readx(fd, cap_buffer, cap_data_size); + sdb_close(fd); + + ret = parse_capability_key_value(cap_buffer, "sdk_toolpath", pkg_tmp_dir, len); + if (ret > 0) { + D("capability sdk_toolpath = %s\n", pkg_tmp_dir); + + if (!strncmp(pkg_tmp_dir, "unknown", 7)) { + D("sdk_toolpath is not available value : %s\n", pkg_tmp_dir); + ret = -1; + } else { + int dir_len = strlen(pkg_tmp_dir); + if(dir_len > 0 && dir_len < len + && pkg_tmp_dir[dir_len -1] != '/' && pkg_tmp_dir[dir_len -1] != '\\') { + pkg_tmp_dir[dir_len] = '/'; + } + ret = 0; + } + } + + return ret; +} +static int get_pkg_tmp_dir_from_pkgcmd(char* pkg_tmp_dir, int len) { + char pkgcmd_out_data[512] = {0,}; const char* SHELL_GET_PKG_TMP_DIR_CMD ="shell:/usr/bin/pkgcmd -a | head -1 | awk '{print $5}'"; - int fd = sdb_connect(SHELL_GET_PKG_TMP_DIR_CMD); + int fd = -1; + int ret = -1; + fd = sdb_connect(SHELL_GET_PKG_TMP_DIR_CMD); if(fd < 0) { + D("failed to get the package temporary path from pkgcmd\n"); return -1; } - if (read_line(fd, buf, sizeof(buf)) > 0) { - D("package dir = %s\n", buf); - append_file(pkg_tmp_dir, buf, "/tmp/", PATH_MAX); - D("package tmp dir = %s\n", pkg_tmp_dir); - sdb_close(fd); - return 0; + + if (read_line(fd, pkgcmd_out_data, sizeof(pkgcmd_out_data)) > 0) { + D("\'pkgcmd -a\' result = %s\n", pkgcmd_out_data); + append_file(pkg_tmp_dir, pkgcmd_out_data, "/tmp/", len); + ret = 0; } - print_error(SDB_MESSAGE_ERROR, F(ERR_PACKAGE_GET_TEMP_PATH_FAIL, buf), NULL); sdb_close(fd); - return -1; + return ret; +} + +// Get the package temporary path. Returns minus if exception happens. +static int get_pkg_tmp_dir(char* pkg_tmp_dir, int len){ + int ret = -1; + + ret = get_pkg_tmp_dir_from_capability(pkg_tmp_dir, len); + if (ret < 0) { + D("failed to get the package temporary path from capability\n"); + D("retry using the pkgcmd shell command.\n"); + ret = get_pkg_tmp_dir_from_pkgcmd(pkg_tmp_dir, len); + } + + if (ret < 0) { + print_error(SDB_MESSAGE_ERROR, ERR_PACKAGE_GET_TEMP_PATH_FAIL, NULL); + } else { + D("package tmp dir = %s\n", pkg_tmp_dir); + } + + return ret; } // Returns 0 if pkg type is wgt. Returns 1 if pkg type is tpk. Returns minus if exception happens. diff --git a/src/commandline.c b/src/commandline.c index 7984553..2041bd9 100755 --- a/src/commandline.c +++ b/src/commandline.c @@ -420,6 +420,52 @@ static void sync_winsz() { } } +/* Parse the key/value with the platform capability. + * Return value + * 1 : if parsing is successful. + * -1 : if exception happens. */ +int parse_capability_key_value(char* cap, char* key, char* value, int len) { + char *p_str = NULL; + int offset = 0; + char *k = NULL; + char *v = NULL; + int ret = -1; + + if (cap == NULL || key == NULL || value == NULL) { + return -1; + } + + while ((p_str = strchr(cap+offset, ':')) != NULL) { + p_str[0] = 0; + k = cap+offset; + offset += strlen(cap+offset)+1; + + p_str = strchr(cap+offset, '\n'); + if (p_str != NULL) { + p_str[0] = 0; + v = cap+offset; + offset += strlen(cap+offset)+1; + } + + if (k == NULL || v == NULL) { + k = NULL; + v = NULL; + continue; + } + + if (!strcmp(k, key)) { + strncpy(value, v, len); + ret = 1; + break; + } + + k = NULL; + v = NULL; + } + + return ret; +} + /* Check whether the key/value matches with the platform capability. * Return value * 1 : if key/value matches with capability. diff --git a/src/commandline.h b/src/commandline.h index 8f5784e..10a4e7a 100644 --- a/src/commandline.h +++ b/src/commandline.h @@ -73,5 +73,6 @@ int get_server_port(); int get_platform_version(struct sdb_version *pversion); int __sdb_command(const char* cmd); int match_capability_key_value(char* cap, char* key, char* value); +int parse_capability_key_value(char* cap, char* key, char* value, int len); #endif /* COMMANDLINE_H_ */