diff --git a/bin/xbps-bin/check.c b/bin/xbps-bin/check.c index ab41b547..84ed0a75 100644 --- a/bin/xbps-bin/check.c +++ b/bin/xbps-bin/check.c @@ -110,15 +110,7 @@ xbps_check_pkg_integrity(const char *pkgname) /* * Check for props.plist metadata file. */ - path = xbps_xasprintf("%s/%s/metadata/%s/%s", xbps_get_rootdir(), - XBPS_META_PATH, pkgname, XBPS_PKGPROPS); - if (path == NULL) { - rv = errno; - goto out; - } - - propsd = prop_dictionary_internalize_from_zfile(path); - free(path); + propsd = xbps_get_pkg_dict_from_metadata_plist(pkgname, XBPS_PKGPROPS); if (propsd == NULL) { fprintf(stderr, "E: %s: unexistent %s metadata file.\n", pkgname, @@ -142,15 +134,7 @@ xbps_check_pkg_integrity(const char *pkgname) /* * Check for files.plist metadata file. */ - path = xbps_xasprintf("%s/%s/metadata/%s/%s", xbps_get_rootdir(), - XBPS_META_PATH, pkgname, XBPS_PKGFILES); - if (path == NULL) { - rv = errno; - goto out; - } - - filesd = prop_dictionary_internalize_from_zfile(path); - free(path); + filesd = xbps_get_pkg_dict_from_metadata_plist(pkgname, XBPS_PKGFILES); if (filesd == NULL) { fprintf(stderr, "E: %s: unexistent %s metadata file.\n", pkgname, diff --git a/bin/xbps-bin/find-files.c b/bin/xbps-bin/find-files.c index 5c5bb01c..6b8acdd2 100644 --- a/bin/xbps-bin/find-files.c +++ b/bin/xbps-bin/find-files.c @@ -75,7 +75,7 @@ find_files_in_packages(const char *pattern) prop_array_t files_keys; DIR *dirp; struct dirent *dp; - char *path, *filesplist; + char *path; int rv = 0; unsigned int i, count; @@ -94,16 +94,9 @@ find_files_in_packages(const char *pattern) (strcmp(dp->d_name, "..") == 0)) continue; - filesplist = xbps_xasprintf("%s/%s/%s", path, dp->d_name, + pkg_filesd = xbps_get_pkg_dict_from_metadata_plist(dp->d_name, XBPS_PKGFILES); - if (filesplist == NULL) { - rv = -1; - break; - } - - pkg_filesd = prop_dictionary_internalize_from_zfile(filesplist); if (pkg_filesd == NULL) { - free(filesplist); if (errno == ENOENT) continue; rv = -1; @@ -118,7 +111,6 @@ find_files_in_packages(const char *pattern) break; } prop_object_release(pkg_filesd); - free(filesplist); if (rv == -1) break; } diff --git a/bin/xbps-bin/show-deps.c b/bin/xbps-bin/show-deps.c index 3c856e22..cf3f7b69 100644 --- a/bin/xbps-bin/show-deps.c +++ b/bin/xbps-bin/show-deps.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009 Juan Romero Pardines. + * Copyright (c) 2009-2010 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,7 +37,6 @@ int xbps_show_pkg_deps(const char *pkgname) { prop_dictionary_t pkgd, propsd; - char *path; int rv = 0; assert(pkgname != NULL); @@ -47,17 +46,12 @@ xbps_show_pkg_deps(const char *pkgname) printf("Package %s is not installed.\n", pkgname); return 0; } + prop_object_release(pkgd); /* * Check for props.plist metadata file. */ - path = xbps_xasprintf("%s/%s/metadata/%s/%s", xbps_get_rootdir(), - XBPS_META_PATH, pkgname, XBPS_PKGPROPS); - if (path == NULL) - return errno; - - propsd = prop_dictionary_internalize_from_zfile(path); - free(path); + propsd = xbps_get_pkg_dict_from_metadata_plist(pkgname, XBPS_PKGPROPS); if (propsd == NULL) { fprintf(stderr, "%s: unexistent %s metadata file.\n", pkgname, @@ -68,7 +62,6 @@ xbps_show_pkg_deps(const char *pkgname) rv = xbps_callback_array_iter_in_dict(propsd, "run_depends", list_strings_sep_in_array, NULL); prop_object_release(propsd); - prop_object_release(pkgd); return rv; } diff --git a/bin/xbps-bin/show-info-files.c b/bin/xbps-bin/show-info-files.c index d0571203..6d8fdddf 100644 --- a/bin/xbps-bin/show-info-files.c +++ b/bin/xbps-bin/show-info-files.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2008-2009 Juan Romero Pardines. + * Copyright (c) 2008-2010 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,23 +37,14 @@ int show_pkg_info_from_metadir(const char *pkgname) { - prop_dictionary_t pkgd; - char *plist; + prop_dictionary_t d; - plist = xbps_xasprintf("%s/%s/metadata/%s/%s", xbps_get_rootdir(), - XBPS_META_PATH, pkgname, XBPS_PKGPROPS); - if (plist == NULL) - return EINVAL; - - pkgd = prop_dictionary_internalize_from_zfile(plist); - if (pkgd == NULL) { - free(plist); + d = xbps_get_pkg_dict_from_metadata_plist(pkgname, XBPS_PKGPROPS); + if (d == NULL) return errno; - } - show_pkg_info(pkgd); - prop_object_release(pkgd); - free(plist); + show_pkg_info(d); + prop_object_release(d); return 0; } @@ -61,24 +52,15 @@ show_pkg_info_from_metadir(const char *pkgname) int show_pkg_files_from_metadir(const char *pkgname) { - prop_dictionary_t pkgd; - char *plist; + prop_dictionary_t d; int rv = 0; - plist = xbps_xasprintf("%s/%s/metadata/%s/%s", xbps_get_rootdir(), - XBPS_META_PATH, pkgname, XBPS_PKGFILES); - if (plist == NULL) - return EINVAL; - - pkgd = prop_dictionary_internalize_from_zfile(plist); - if (pkgd == NULL) { - free(plist); + d = xbps_get_pkg_dict_from_metadata_plist(pkgname, XBPS_PKGFILES); + if (d == NULL) return errno; - } - free(plist); - rv = show_pkg_files(pkgd); - prop_object_release(pkgd); + rv = show_pkg_files(d); + prop_object_release(d); return rv; } diff --git a/include/xbps_api.h b/include/xbps_api.h index 83c800eb..2d9c0296 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -510,6 +510,19 @@ bool xbps_find_string_in_array(prop_array_t array, const char *val); prop_object_iterator_t xbps_get_array_iter_from_dict(prop_dictionary_t dict, const char *key); +/** + * Get a proplib object dictionary associated with the installed package + * \a pkgn, by internalizing its plist file defined by \a plist. + * + * @param[in] pkgn Package name of installed package. + * @param[in] plist Package metadata property list file. + * + * @return The proplib object dictionary on success, NULL otherwise and + * errno is set appropiately. + */ +prop_dictionary_t xbps_get_pkg_dict_from_metadata_plist(const char *pkgn, + const char *plist); + /** * Finds a proplib dictionary in an archive, matching a specific * entry on it. diff --git a/lib/package_config_files.c b/lib/package_config_files.c index 39de213c..2334f08d 100644 --- a/lib/package_config_files.c +++ b/lib/package_config_files.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009 Juan Romero Pardines. + * Copyright (c) 2009-2010 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -58,13 +58,7 @@ xbps_config_file_from_archive_entry(prop_dictionary_t d, * Get original hash for the file from current * installed package. */ - buf = xbps_xasprintf(".%s/metadata/%s/%s", XBPS_META_PATH, - pkgname, XBPS_PKGFILES); - if (buf == NULL) - return errno; - - forigd = prop_dictionary_internalize_from_zfile(buf); - free(buf); + forigd = xbps_get_pkg_dict_from_metadata_plist(pkgname, XBPS_PKGFILES); if (forigd == NULL) { install_new = true; goto out; diff --git a/lib/package_purge.c b/lib/package_purge.c index d3737b4a..991376e6 100644 --- a/lib/package_purge.c +++ b/lib/package_purge.c @@ -137,7 +137,6 @@ int xbps_purge_pkg(const char *pkgname, bool check_state) { prop_dictionary_t dict, pkgd; - char *path; int rv = 0, flags; pkg_state_t state = 0; @@ -170,20 +169,11 @@ xbps_purge_pkg(const char *pkgname, bool check_state) /* * Remove unmodified configuration files. */ - path = xbps_xasprintf("%s/%s/metadata/%s/%s", - xbps_get_rootdir(), XBPS_META_PATH, pkgname, XBPS_PKGFILES); - if (path == NULL) { - rv = errno; - goto out; - } - - dict = prop_dictionary_internalize_from_zfile(path); + dict = xbps_get_pkg_dict_from_metadata_plist(pkgname, XBPS_PKGFILES); if (dict == NULL) { - free(path); rv = errno; goto out; } - free(path); if ((rv = xbps_remove_pkg_files(dict, "conf_files")) != 0) { prop_object_release(dict); goto out; diff --git a/lib/package_remove.c b/lib/package_remove.c index 3787e248..050879ed 100644 --- a/lib/package_remove.c +++ b/lib/package_remove.c @@ -192,7 +192,7 @@ int xbps_remove_pkg(const char *pkgname, const char *version, bool update) { prop_dictionary_t dict; - char *path, *buf; + char *buf; int rv = 0; assert(pkgname != NULL); @@ -240,19 +240,11 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update) /* * Remove links, files and dirs. */ - path = xbps_xasprintf(".%s/metadata/%s/%s", - XBPS_META_PATH, pkgname, XBPS_PKGFILES); - if (path == NULL) { - free(buf); - return errno; - } - dict = prop_dictionary_internalize_from_zfile(path); + dict = xbps_get_pkg_dict_from_metadata_plist(pkgname, XBPS_PKGFILES); if (dict == NULL) { - free(path); free(buf); return errno; } - free(path); /* Remove links */ if ((rv = xbps_remove_pkg_files(dict, "links")) != 0) { diff --git a/lib/plist.c b/lib/plist.c index 6c69e608..f77a3685 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -287,6 +287,26 @@ xbps_get_array_iter_from_dict(prop_dictionary_t dict, const char *key) return prop_array_iterator(array); } +prop_dictionary_t +xbps_get_pkg_dict_from_metadata_plist(const char *pkgn, const char *plist) +{ + prop_dictionary_t plistd = NULL; + char *plistf; + + assert(pkgn != NULL); + assert(plist != NULL); + + plistf = xbps_xasprintf("%s/%s/metadata/%s/%s", + xbps_get_rootdir(), XBPS_META_PATH, pkgn, plist); + if (plistf == NULL) + return NULL; + + plistd = prop_dictionary_internalize_from_zfile(plistf); + free(plistf); + + return plistd; +} + int xbps_remove_string_from_array(prop_array_t array, const char *str) {