Get pkgtype from contents of file 41/119241/2
authorJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 16 Mar 2017 06:15:18 +0000 (15:15 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 16 Mar 2017 08:34:25 +0000 (17:34 +0900)
- 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 <jungh.yeon@samsung.com>
client/CMakeLists.txt
client/src/pkgmgr.c
client/src/pkgmgr_client_internal.h
packaging/pkgmgr.spec

index 5154bbd..a59ff50 100644 (file)
@@ -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)
index 4cfddd0..76584f9 100644 (file)
@@ -29,6 +29,7 @@
 #include <fcntl.h>
 #include <sys/wait.h>
 #include <sys/time.h>
+#include <unzip.h>
 
 #include <glib.h>
 
@@ -337,33 +338,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,
index 7f5766d..921ae65 100644 (file)
@@ -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,
index 0d3fd2d..496608c 100644 (file)
@@ -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