From 96573decd544e69f81ef0b31bb4112be50da533d Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Thu, 16 Mar 2017 15:15:18 +0900 Subject: [PATCH] Get pkgtype from contents of file - There are some wgt package packed as tpk file at store so fix to get pkg type from contents of file. Change-Id: Ie9fbf4df03134946631fb55ec0d135d92c33cc37 Signed-off-by: Junghyun Yeon --- client/CMakeLists.txt | 3 ++- client/src/pkgmgr.c | 41 ++++++++++++++++++++----------------- client/src/pkgmgr_client_internal.h | 5 +++++ packaging/pkgmgr.spec | 1 + 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index ab19c7b..7d893de 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -10,7 +10,8 @@ pkg_check_modules(CLIENT_DEPS REQUIRED pkgmgr-info iniparser xdgmime - libtzplatform-config) + libtzplatform-config + minizip) FOREACH(CLIENT_FLAGS ${CLIENT_DEPS_CFLAGS}) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CLIENT_FLAGS}") ENDFOREACH(CLIENT_FLAGS) diff --git a/client/src/pkgmgr.c b/client/src/pkgmgr.c index e23748a..a7c2d87 100644 --- a/client/src/pkgmgr.c +++ b/client/src/pkgmgr.c @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -345,33 +346,35 @@ API int pkgmgr_client_free(pkgmgr_client *pc) return PKGMGR_R_OK; } +struct manifest_and_type type_map[] = { + { "res/wgt/config.xml", "wgt" }, + { "config.xml", "wgt" }, + { "tizen-manifest.xml", "tpk" }, + { NULL, NULL } +}; + static char *__get_type_from_path(const char *pkg_path) { - int ret; - char mimetype[255] = { '\0', }; - char extlist[256] = { '\0', }; - char *pkg_type; + const char *type = NULL; + unzFile uf; + int i; - ret = _get_mime_from_file(pkg_path, mimetype, sizeof(mimetype)); - if (ret) { - ERR("_get_mime_from_file() failed - error code[%d]\n", ret); + uf = unzOpen(pkg_path); + if (uf == NULL) { + ERR("failed to open zip file %s", pkg_path); return NULL; } - ret = _get_mime_extension(mimetype, extlist, sizeof(extlist)); - if (ret) { - ERR("_get_mime_extension() failed - error code[%d]\n", ret); - return NULL; + for (i = 0; type_map[i].manifest != NULL; i++) { + if (unzLocateFile(uf, type_map[i].manifest, 0) == UNZ_OK) { + DBG("pkgtype of %s: [%s]", pkg_path, type_map[i].type); + type = type_map[i].type; + break; + } } + unzClose(uf); - if (strlen(extlist) == 0) - return NULL; - - if (strchr(extlist, ',')) - extlist[strlen(extlist) - strlen(strchr(extlist, ','))] = '\0'; - - pkg_type = strchr(extlist, '.') + 1; - return strdup(pkg_type); + return strdup(type); } API int pkgmgr_client_set_tep_path(pkgmgr_client *pc, const char *tep_path, diff --git a/client/src/pkgmgr_client_internal.h b/client/src/pkgmgr_client_internal.h index 7f5766d..921ae65 100644 --- a/client/src/pkgmgr_client_internal.h +++ b/client/src/pkgmgr_client_internal.h @@ -56,6 +56,11 @@ struct pkgmgr_client_t { bool debug_mode; }; +struct manifest_and_type { + const char *manifest; + const char *type; +}; + int pkgmgr_client_connection_connect(struct pkgmgr_client_t *pc); void pkgmgr_client_connection_disconnect(struct pkgmgr_client_t *pc); int pkgmgr_client_connection_set_callback(struct pkgmgr_client_t *pc, diff --git a/packaging/pkgmgr.spec b/packaging/pkgmgr.spec index 6b6caa1..d9ef24e 100644 --- a/packaging/pkgmgr.spec +++ b/packaging/pkgmgr.spec @@ -34,6 +34,7 @@ BuildRequires: pkgconfig(xdgmime) BuildRequires: pkgconfig(db-util) BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(libsystemd-daemon) +BuildRequires: pkgconfig(minizip) BuildRequires: pkgmgr-info-parser-devel BuildRequires: pkgmgr-info-parser BuildRequires: fdupes -- 2.7.4