New function: xbps_get_pkg_dict_from_metadata_plist.

This function returns and internalized dictionary from a package's metadata
plist file as specified by its arguments.

Update all code to use it where appropiate.
This commit is contained in:
Juan RP
2010-11-08 03:14:41 +01:00
parent 25ebcd53f8
commit c3afb4f4fb
9 changed files with 56 additions and 96 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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)
{