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:
parent
25ebcd53f8
commit
c3afb4f4fb
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
20
lib/plist.c
20
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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user