int q = 0; /*quotient*/
int r = 0; /*remainder*/
DIR *dp = NULL;
- struct dirent *ep = NULL;
+ struct dirent ep, *result;
struct stat fileinfo;
char abs_filename[FILENAME_MAX] = { 0, };
retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
dp = opendir(dirname);
- if (dp != NULL) {
- while ((ep = readdir(dp)) != NULL) {
- if (!strcmp(ep->d_name, ".") ||
- !strcmp(ep->d_name, "..")) {
+ if (dp == NULL) {
+ _LOGE("Couldn't open the directory\n");
+ return -1;
+ }
+
+ for (ret = readdir_r(dp, &ep, &result);
+ ret == 0 && result != NULL;
+ ret = readdir_r(dp, &ep, &result)) {
+ if (!strcmp(ep.d_name, ".") ||
+ !strcmp(ep.d_name, "..")) {
+ continue;
+ }
+ snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
+ ep.d_name);
+ if (lstat(abs_filename, &fileinfo) < 0)
+ perror(abs_filename);
+ else {
+ if (S_ISDIR(fileinfo.st_mode)) {
+ total += fileinfo.st_size;
+ if (strcmp(ep.d_name, ".")
+ && strcmp(ep.d_name, "..")) {
+ ret = _pkgmgr_calculate_dir_size
+ (abs_filename);
+ total = total + ret;
+ }
+ } else if (S_ISLNK(fileinfo.st_mode)) {
continue;
+ } else {
+ /*It is a file. Calculate the actual
+ size occupied (in terms of 4096 blocks)*/
+ q = (fileinfo.st_size / BLOCK_SIZE);
+ r = (fileinfo.st_size % BLOCK_SIZE);
+ if (r) {
+ q = q + 1;
}
- snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
- ep->d_name);
- if (lstat(abs_filename, &fileinfo) < 0)
- perror(abs_filename);
- else {
- if (S_ISDIR(fileinfo.st_mode)) {
- total += fileinfo.st_size;
- if (strcmp(ep->d_name, ".")
- && strcmp(ep->d_name, "..")) {
- ret = _pkgmgr_calculate_dir_size
- (abs_filename);
- total = total + ret;
- }
- } else if (S_ISLNK(fileinfo.st_mode)) {
- continue;
- } else {
- /*It is a file. Calculate the actual
- size occupied (in terms of 4096 blocks)*/
- q = (fileinfo.st_size / BLOCK_SIZE);
- r = (fileinfo.st_size % BLOCK_SIZE);
- if (r) {
- q = q + 1;
- }
- total += q * BLOCK_SIZE;
- }
+ total += q * BLOCK_SIZE;
}
}
- (void)closedir(dp);
- } else {
- _LOGE("Couldn't open the directory\n");
- return -1;
}
+ (void)closedir(dp);
return total;
}
}
while (sqlite3_step(stmt) == SQLITE_ROW) {
- _save_column_str(stmt, 0, (const char **)&pkgid);
+ _save_column_str(stmt, 0, &pkgid);
if (pkgid != NULL)
*list = g_list_insert_sorted(*list, pkgid,
__list_strcmp);
int ret;
char *query;
sqlite3_stmt *stmt;
- const char *privilege;
+ char *privilege;
query = sqlite3_mprintf(query_raw, pkgid);
if (query == NULL) {
"installed_storage, storeclient_id, mainapp_id, package_url, "
"root_path, csc_path, package_nodisplay, package_api_version, "
"package_support_disable, package_tep_name "
- "FROM package_info WHERE package=%Q";
+ "FROM package_info WHERE package=%Q AND package_disable='false'";
int ret;
char *query;
sqlite3_stmt *stmt;
if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
return PMINFO_R_ERROR;
+ if (strlen(info->pkg_info->tep_name) == 0)
+ return PMINFO_R_ERROR;
+
*tep_name = (char *)info->pkg_info->tep_name;
return PMINFO_R_OK;
}
return PMINFO_R_OK;
}
-
-API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
-{
- retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
- char *manifest = NULL;
- manifest_x *mfx = NULL;
- *handle = NULL;
- manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
- retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
-
- mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
- if (manifest) {
- free(manifest);
- manifest = NULL;
- }
- retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
-
- *handle = (void *)mfx;
-
- return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
-{
- retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
- char *manifest = NULL;
- manifest_x *mfx = NULL;
- *handle = NULL;
- manifest = pkgmgr_parser_get_manifest_file(pkgid);
- retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
-
- mfx = pkgmgr_parser_process_manifest_xml(manifest);
- if (manifest) {
- free(manifest);
- manifest = NULL;
- }
- retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
-
- *handle = (void *)mfx;
-
- return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
-{
- int len;
- manifest_x *mfx = (manifest_x *)handle;
-
- retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
- len = strlen(type);
- retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
-
- if (mfx->type)
- free((void *)mfx->type);
-
- mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
-
- return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
-{
- int len;
- manifest_x *mfx = (manifest_x *)handle;
-
- retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
- len = strlen(version);
- retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
-
- if (mfx->version)
- free((void *)mfx->version);
-
- mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
- return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
-{
- manifest_x *mfx = (manifest_x *)handle;
-
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
- retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
-
- if (mfx->installlocation)
- free((void *)mfx->installlocation);
-
- if (location == INSTALL_INTERNAL)
- mfx->installlocation = strdup("internal-only");
- else if (location == INSTALL_EXTERNAL)
- mfx->installlocation = strdup("prefer-external");
-
- return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
-{
- manifest_x *mfx = (manifest_x *)handle;
-
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
- retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
- if (mfx->package_size)
- free((void *)mfx->package_size);
-
- mfx->package_size = strdup(size);
-
- return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
-{
- int len;
- manifest_x *mfx = (manifest_x *)handle;
- label_x *label;
-
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
- retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
- len = strlen(label_txt);
- retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
-
- label = calloc(1, sizeof(label_x));
- retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
-
- if (locale)
- label->lang = strdup(locale);
- else
- label->lang = strdup(DEFAULT_LOCALE);
- label->text = strdup(label_txt);
- mfx->label = g_list_append(mfx->label, label);
-
- return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
-{
- int len;
- manifest_x *mfx = (manifest_x *)handle;
- icon_x *icon;
-
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
- retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
- len = strlen(icon_txt);
- retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
-
- icon = calloc(1, sizeof(icon_x));
- retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
-
- if (locale)
- icon->lang = strdup(locale);
- else
- icon->lang = strdup(DEFAULT_LOCALE);
- icon->text = strdup(icon_txt);
- mfx->icon = g_list_append(mfx->icon, icon);
-
- return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
-{
- int len = strlen(desc_txt);
- manifest_x *mfx = (manifest_x *)handle;
- description_x *description;
-
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
- retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
- len = strlen(desc_txt);
- retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
-
- description = calloc(1, sizeof(description_x));
- retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
-
- if (locale)
- description->lang = strdup(locale);
- else
- description->lang = strdup(DEFAULT_LOCALE);
- description->text = strdup(desc_txt);
- mfx->description = g_list_append(mfx->description, description);
-
- return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
- const char *author_email, const char *author_href, const char *locale)
-{
- manifest_x *mfx = (manifest_x *)handle;
- author_x *author;
-
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
- author = calloc(1, sizeof(author_x));
- retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
- if (author_name)
- author->text = strdup(author_name);
- if (author_email)
- author->email = strdup(author_email);
- if (author_href)
- author->href = strdup(author_href);
- if (locale)
- author->lang = strdup(locale);
- else
- author->lang = strdup(DEFAULT_LOCALE);
- mfx->author = g_list_append(mfx->author, author);
- return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
-{
- manifest_x *mfx = (manifest_x *)handle;
-
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
- retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
-
- if (mfx->removable)
- free((void *)mfx->removable);
-
- if (removable == 0)
- mfx->removable = strdup("false");
- else if (removable == 1)
- mfx->removable = strdup("true");
-
- return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
-{
- manifest_x *mfx = (manifest_x *)handle;
-
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
- retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
-
- if (mfx->preload)
- free((void *)mfx->preload);
-
- if (preload == 0)
- mfx->preload = strdup("false");
- else if (preload == 1)
- mfx->preload = strdup("true");
-
- return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
-{
- manifest_x *mfx = (manifest_x *)handle;
-
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
- retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
-
- if (mfx->installed_storage)
- free((void *)mfx->installed_storage);
-
- if (location == INSTALL_INTERNAL)
- mfx->installed_storage = strdup("installed_internal");
- else if (location == INSTALL_EXTERNAL)
- mfx->installed_storage = strdup("installed_external");
-
- return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
-{
- int ret;
- manifest_x *mfx = (manifest_x *)handle;
- mfx = (manifest_x *)handle;
-
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
- ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
- if (ret == 0) {
- _LOGE("Successfully stored info in DB\n");
- return PMINFO_R_OK;
- } else {
- _LOGE("Failed to store info in DB\n");
- return PMINFO_R_ERROR;
- }
-}
-
-API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
-{
- int ret;
- manifest_x *mfx = (manifest_x *)handle;
-
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
- ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
- if (ret == 0) {
- _LOGE("Successfully stored info in DB\n");
- return PMINFO_R_OK;
- } else {
- _LOGE("Failed to store info in DB\n");
- return PMINFO_R_ERROR;
- }
-}
-
-API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
-{
- manifest_x *mfx = (manifest_x *)handle;
-
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
- pkgmgrinfo_basic_free_package(mfx);
-
- return PMINFO_R_OK;
-}