4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
30 #include "libdebinternals.h"
32 #define EXTRACT_MENIFEST "/usr/bin/extract_manifest.sh"
33 #define FIND_PACKAGE "/usr/bin/find_package.sh"
34 #define MANIFEST_FILE_NAME "control"
35 #define BASEDIR "/opt/share"
36 #define THIRD_PARTY_DESKTOP_FILE_PATH \
37 BASEDIR"/install-info/application"
38 #define INHOUSE_DESKTOP_FILE_PATH \
39 BASEDIR"/applications"
42 void pkg_native_plugin_on_unload(void)
47 int pkg_plugin_app_is_installed(const char *pkg_name)
53 char buff[512] = { 0, };
54 /* Check for valid arguments */
55 if (pkg_name == NULL) {
58 "[pkg_plugin_app_is_installed] pkg_name is NULL\n");
61 fp = fopen(PKGMETAINFO, "r");
63 _libdeb_print(DEBUG_ERR,
64 "failed to open file(%s)\n", PKGMETAINFO);
67 snprintf(buff, 512, "Package: %s", pkg_name);
68 /*allocate memory for lineptr. If it is less
69 getline will realloc it */
70 lineptr = (char *)malloc(sizeof(char)*512);
72 _libdeb_print(DEBUG_ERR,
77 memset(lineptr, 0x00, sizeof(char)*512);
80 read = getline(&lineptr, &len, fp);
83 _libdeb_print(DEBUG_ERR, "EOF reached"
84 "Package not installed\n");
87 _libdeb_print(DEBUG_ERR, "getline failed\n");
92 if (lineptr && (strncmp(lineptr, buff, strlen(buff)) == 0) &&
93 (strlen(lineptr) == strlen(buff) + 1)) {
96 "[pkg_plugin_app_is_installed] "
97 "package is installed\n");
99 return LIBDEB_SUCCESS;
102 memset(lineptr, 0x00, len);
105 } while (lineptr != NULL);
107 _libdeb_print(DEBUG_INFO,"[pkg_plugin_app_is_installed] "
108 "package is not installed\n");
113 int pkg_plugin_get_installed_apps_list(const char *category,
115 package_manager_pkg_info_t **list,
118 return LIBDEB_SUCCESS;
121 int pkg_plugin_get_app_detail_info(const char *pkg_name,
122 package_manager_pkg_detail_info_t
125 _libdeb_print(DEBUG_INFO,
126 "pkg_plugin_get_app_detail_info() is called\n");
127 /* Check for valid arguments */
128 if (pkg_name == NULL || pkg_detail_info == NULL) {
129 _libdeb_print(DEBUG_ERR,
130 "[pkg_plugin_get_app_detail_info_from_package] "
131 "args supplied is NULL\n");
134 char dirname[BUFFSIZE] = { '\0' };
136 long long data_size = 0;
137 char buff[256] = {'\0'};
138 time_t install_time = 0;
140 /*As Installed Size field is optional, it may not be present in control file.
141 So Initialize it to 0. If present it will be populated with app_size*/
142 pkg_detail_info->app_size = 0;
144 /* pkgtype is by default deb */
145 strncpy(pkg_detail_info->pkg_type, "deb", sizeof(pkg_detail_info->pkg_type));
147 /* Populate the structure now */
150 snprintf(dirname, BUFFSIZE-1, "/opt/apps/%s/data", pkg_name);
151 data_size = _libdeb_calculate_dir_size(dirname);
153 _libdeb_print(DEBUG_ERR,
154 "Calculate dir size failed\n");
155 pkg_detail_info->data_size = 0 ;
158 data_size += BLOCK_SIZE; /* the function does not adds 4096
159 bytes for the directory size itself*/
160 pkg_detail_info->data_size = data_size/1024 ;
162 ret = _libdeb_populate_control_info(pkg_name, pkg_detail_info,
165 _libdeb_print(DEBUG_ERR,
166 "[pkg_plugin_get_app_detail_info] "
167 "_libdeb_populate_control_info returns %d\n",
172 /* Min Platform Version */
173 pkg_detail_info->min_platform_version[0] = '\0';
176 pkg_detail_info->optional_id[0] = '\0';
178 /* Total Installed Size*/
179 pkg_detail_info->installed_size = pkg_detail_info->app_size +
180 pkg_detail_info->data_size;
182 snprintf(buff, 256, "db/app-info/%s/installed-time", pkg_name);
183 ret = vconf_get_int(buff, (int *)&install_time);
185 _libdeb_print(DEBUG_ERR, "get installed time failed\n");
186 pkg_detail_info->installed_time = 0;
189 pkg_detail_info->installed_time = install_time;
192 return LIBDEB_SUCCESS;
195 int pkg_plugin_get_app_detail_info_from_package(const char *pkg_path,
196 package_manager_pkg_detail_info_t
199 _libdeb_print(DEBUG_INFO,
200 "pkg_plugin_get_app_detail_info_from_package() is called\n");
202 /* Check for valid arguments */
203 if (pkg_path == NULL || pkg_detail_info == NULL) {
204 _libdeb_print(DEBUG_ERR,
205 "[pkg_plugin_get_app_detail_info_from_package]"
206 "args supplied is NULL\n");
210 const char *argv[] = { EXTRACT_MENIFEST, pkg_path, NULL };
212 long long data_size = 0;
213 char *pkg_filename = NULL;
215 char controlfilepath[BUFFSIZE] = { '\0' };
216 char dirname[BUFFSIZE] = { '\0' };
217 char buff[256] = {'\0'};
218 time_t install_time = 0;
220 /* populate pkg type */
221 str = strrchr(pkg_path, 46); /* 46 is ASCII for . */
222 strncpy(pkg_detail_info->pkg_type, (str + 1), strlen(str + 1));
224 /* extract the control file from the deb package */
225 ret = _libdeb_xsystem(argv);
227 _libdeb_print(DEBUG_ERR,
228 "[pkg_plugin_get_app_detail_info_from_package] "
229 "xsystem returns %d\n", ret);
233 /* Extract file name from file path */
234 pkg_filename = _libdeb_get_filename(pkg_path);
236 _libdeb_print(DEBUG_ERR,
237 "[pkg_plugin_get_app_detail_info_from_package] "
238 " _libdeb_get_filename returns %s\n",
242 snprintf(controlfilepath, BUFFSIZE - 1, "/var/pkgmgr/%s/metainfo/%s",
243 pkg_filename, MANIFEST_FILE_NAME);
249 _libdeb_populate_control_info(NULL, pkg_detail_info,
252 _libdeb_print(DEBUG_ERR,
253 "[pkg_plugin_get_app_detail_info_from_package] "
254 " _libdeb_populate_control_info returns %d\n",
260 /*get data_size. If pkg is not installed it will be 0*/
261 snprintf(dirname, BUFFSIZE-1, "/opt/apps/%s/data",
262 pkg_detail_info->pkg_name);
264 data_size = _libdeb_calculate_dir_size(dirname);
266 _libdeb_print(DEBUG_ERR,
267 "Calculate dir size failed\n");
268 pkg_detail_info->data_size = 0 ;
271 data_size += BLOCK_SIZE; /* the function does not adds 4096
272 bytes for the directory size itself*/
274 pkg_detail_info->data_size = data_size/1024 ;
277 /* Min Platform Version */
278 pkg_detail_info->min_platform_version[0] = '\0';
281 pkg_detail_info->optional_id[0] = '\0';
283 /* Total Installed Size*/
284 pkg_detail_info->installed_size = pkg_detail_info->app_size +
285 pkg_detail_info->data_size;
288 snprintf(buff, 256, "db/app-info/%s/installed-time", pkg_detail_info->pkg_name);
289 ret = vconf_get_int(buff, (int *)&install_time);
291 _libdeb_print(DEBUG_ERR, "get installed time failed\n");
292 pkg_detail_info->installed_time = 0;
295 pkg_detail_info->installed_time = install_time;
298 return LIBDEB_SUCCESS;
301 API int pkg_plugin_on_load(pkg_plugin_set *set)
307 memset(set, 0x00, sizeof(pkg_plugin_set));
309 set->plugin_on_unload = pkg_native_plugin_on_unload;
310 set->pkg_is_installed = pkg_plugin_app_is_installed;
311 set->get_installed_pkg_list = pkg_plugin_get_installed_apps_list;
312 set->get_pkg_detail_info = pkg_plugin_get_app_detail_info;
313 set->get_pkg_detail_info_from_package =
314 pkg_plugin_get_app_detail_info_from_package;
316 return LIBDEB_SUCCESS;