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.
|
* Check for props.plist metadata file.
|
||||||
*/
|
*/
|
||||||
path = xbps_xasprintf("%s/%s/metadata/%s/%s", xbps_get_rootdir(),
|
propsd = xbps_get_pkg_dict_from_metadata_plist(pkgname, XBPS_PKGPROPS);
|
||||||
XBPS_META_PATH, pkgname, XBPS_PKGPROPS);
|
|
||||||
if (path == NULL) {
|
|
||||||
rv = errno;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
propsd = prop_dictionary_internalize_from_zfile(path);
|
|
||||||
free(path);
|
|
||||||
if (propsd == NULL) {
|
if (propsd == NULL) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"E: %s: unexistent %s metadata file.\n", pkgname,
|
"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.
|
* Check for files.plist metadata file.
|
||||||
*/
|
*/
|
||||||
path = xbps_xasprintf("%s/%s/metadata/%s/%s", xbps_get_rootdir(),
|
filesd = xbps_get_pkg_dict_from_metadata_plist(pkgname, XBPS_PKGFILES);
|
||||||
XBPS_META_PATH, pkgname, XBPS_PKGFILES);
|
|
||||||
if (path == NULL) {
|
|
||||||
rv = errno;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
filesd = prop_dictionary_internalize_from_zfile(path);
|
|
||||||
free(path);
|
|
||||||
if (filesd == NULL) {
|
if (filesd == NULL) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"E: %s: unexistent %s metadata file.\n", pkgname,
|
"E: %s: unexistent %s metadata file.\n", pkgname,
|
||||||
|
@ -75,7 +75,7 @@ find_files_in_packages(const char *pattern)
|
|||||||
prop_array_t files_keys;
|
prop_array_t files_keys;
|
||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
struct dirent *dp;
|
struct dirent *dp;
|
||||||
char *path, *filesplist;
|
char *path;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
unsigned int i, count;
|
unsigned int i, count;
|
||||||
|
|
||||||
@ -94,16 +94,9 @@ find_files_in_packages(const char *pattern)
|
|||||||
(strcmp(dp->d_name, "..") == 0))
|
(strcmp(dp->d_name, "..") == 0))
|
||||||
continue;
|
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);
|
XBPS_PKGFILES);
|
||||||
if (filesplist == NULL) {
|
|
||||||
rv = -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
pkg_filesd = prop_dictionary_internalize_from_zfile(filesplist);
|
|
||||||
if (pkg_filesd == NULL) {
|
if (pkg_filesd == NULL) {
|
||||||
free(filesplist);
|
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
continue;
|
continue;
|
||||||
rv = -1;
|
rv = -1;
|
||||||
@ -118,7 +111,6 @@ find_files_in_packages(const char *pattern)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
prop_object_release(pkg_filesd);
|
prop_object_release(pkg_filesd);
|
||||||
free(filesplist);
|
|
||||||
if (rv == -1)
|
if (rv == -1)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2009 Juan Romero Pardines.
|
* Copyright (c) 2009-2010 Juan Romero Pardines.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -37,7 +37,6 @@ int
|
|||||||
xbps_show_pkg_deps(const char *pkgname)
|
xbps_show_pkg_deps(const char *pkgname)
|
||||||
{
|
{
|
||||||
prop_dictionary_t pkgd, propsd;
|
prop_dictionary_t pkgd, propsd;
|
||||||
char *path;
|
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
assert(pkgname != NULL);
|
assert(pkgname != NULL);
|
||||||
@ -47,17 +46,12 @@ xbps_show_pkg_deps(const char *pkgname)
|
|||||||
printf("Package %s is not installed.\n", pkgname);
|
printf("Package %s is not installed.\n", pkgname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
prop_object_release(pkgd);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for props.plist metadata file.
|
* Check for props.plist metadata file.
|
||||||
*/
|
*/
|
||||||
path = xbps_xasprintf("%s/%s/metadata/%s/%s", xbps_get_rootdir(),
|
propsd = xbps_get_pkg_dict_from_metadata_plist(pkgname, XBPS_PKGPROPS);
|
||||||
XBPS_META_PATH, pkgname, XBPS_PKGPROPS);
|
|
||||||
if (path == NULL)
|
|
||||||
return errno;
|
|
||||||
|
|
||||||
propsd = prop_dictionary_internalize_from_zfile(path);
|
|
||||||
free(path);
|
|
||||||
if (propsd == NULL) {
|
if (propsd == NULL) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%s: unexistent %s metadata file.\n", pkgname,
|
"%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",
|
rv = xbps_callback_array_iter_in_dict(propsd, "run_depends",
|
||||||
list_strings_sep_in_array, NULL);
|
list_strings_sep_in_array, NULL);
|
||||||
prop_object_release(propsd);
|
prop_object_release(propsd);
|
||||||
prop_object_release(pkgd);
|
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2008-2009 Juan Romero Pardines.
|
* Copyright (c) 2008-2010 Juan Romero Pardines.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -37,23 +37,14 @@
|
|||||||
int
|
int
|
||||||
show_pkg_info_from_metadir(const char *pkgname)
|
show_pkg_info_from_metadir(const char *pkgname)
|
||||||
{
|
{
|
||||||
prop_dictionary_t pkgd;
|
prop_dictionary_t d;
|
||||||
char *plist;
|
|
||||||
|
|
||||||
plist = xbps_xasprintf("%s/%s/metadata/%s/%s", xbps_get_rootdir(),
|
d = xbps_get_pkg_dict_from_metadata_plist(pkgname, XBPS_PKGPROPS);
|
||||||
XBPS_META_PATH, pkgname, XBPS_PKGPROPS);
|
if (d == NULL)
|
||||||
if (plist == NULL)
|
|
||||||
return EINVAL;
|
|
||||||
|
|
||||||
pkgd = prop_dictionary_internalize_from_zfile(plist);
|
|
||||||
if (pkgd == NULL) {
|
|
||||||
free(plist);
|
|
||||||
return errno;
|
return errno;
|
||||||
}
|
|
||||||
|
|
||||||
show_pkg_info(pkgd);
|
show_pkg_info(d);
|
||||||
prop_object_release(pkgd);
|
prop_object_release(d);
|
||||||
free(plist);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -61,24 +52,15 @@ show_pkg_info_from_metadir(const char *pkgname)
|
|||||||
int
|
int
|
||||||
show_pkg_files_from_metadir(const char *pkgname)
|
show_pkg_files_from_metadir(const char *pkgname)
|
||||||
{
|
{
|
||||||
prop_dictionary_t pkgd;
|
prop_dictionary_t d;
|
||||||
char *plist;
|
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
plist = xbps_xasprintf("%s/%s/metadata/%s/%s", xbps_get_rootdir(),
|
d = xbps_get_pkg_dict_from_metadata_plist(pkgname, XBPS_PKGFILES);
|
||||||
XBPS_META_PATH, pkgname, XBPS_PKGFILES);
|
if (d == NULL)
|
||||||
if (plist == NULL)
|
|
||||||
return EINVAL;
|
|
||||||
|
|
||||||
pkgd = prop_dictionary_internalize_from_zfile(plist);
|
|
||||||
if (pkgd == NULL) {
|
|
||||||
free(plist);
|
|
||||||
return errno;
|
return errno;
|
||||||
}
|
|
||||||
free(plist);
|
|
||||||
|
|
||||||
rv = show_pkg_files(pkgd);
|
rv = show_pkg_files(d);
|
||||||
prop_object_release(pkgd);
|
prop_object_release(d);
|
||||||
|
|
||||||
return rv;
|
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,
|
prop_object_iterator_t xbps_get_array_iter_from_dict(prop_dictionary_t dict,
|
||||||
const char *key);
|
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
|
* Finds a proplib dictionary in an archive, matching a specific
|
||||||
* entry on it.
|
* entry on it.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2009 Juan Romero Pardines.
|
* Copyright (c) 2009-2010 Juan Romero Pardines.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* 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
|
* Get original hash for the file from current
|
||||||
* installed package.
|
* installed package.
|
||||||
*/
|
*/
|
||||||
buf = xbps_xasprintf(".%s/metadata/%s/%s", XBPS_META_PATH,
|
forigd = xbps_get_pkg_dict_from_metadata_plist(pkgname, XBPS_PKGFILES);
|
||||||
pkgname, XBPS_PKGFILES);
|
|
||||||
if (buf == NULL)
|
|
||||||
return errno;
|
|
||||||
|
|
||||||
forigd = prop_dictionary_internalize_from_zfile(buf);
|
|
||||||
free(buf);
|
|
||||||
if (forigd == NULL) {
|
if (forigd == NULL) {
|
||||||
install_new = true;
|
install_new = true;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -137,7 +137,6 @@ int
|
|||||||
xbps_purge_pkg(const char *pkgname, bool check_state)
|
xbps_purge_pkg(const char *pkgname, bool check_state)
|
||||||
{
|
{
|
||||||
prop_dictionary_t dict, pkgd;
|
prop_dictionary_t dict, pkgd;
|
||||||
char *path;
|
|
||||||
int rv = 0, flags;
|
int rv = 0, flags;
|
||||||
pkg_state_t state = 0;
|
pkg_state_t state = 0;
|
||||||
|
|
||||||
@ -170,20 +169,11 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
|
|||||||
/*
|
/*
|
||||||
* Remove unmodified configuration files.
|
* Remove unmodified configuration files.
|
||||||
*/
|
*/
|
||||||
path = xbps_xasprintf("%s/%s/metadata/%s/%s",
|
dict = xbps_get_pkg_dict_from_metadata_plist(pkgname, XBPS_PKGFILES);
|
||||||
xbps_get_rootdir(), XBPS_META_PATH, pkgname, XBPS_PKGFILES);
|
|
||||||
if (path == NULL) {
|
|
||||||
rv = errno;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
dict = prop_dictionary_internalize_from_zfile(path);
|
|
||||||
if (dict == NULL) {
|
if (dict == NULL) {
|
||||||
free(path);
|
|
||||||
rv = errno;
|
rv = errno;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
free(path);
|
|
||||||
if ((rv = xbps_remove_pkg_files(dict, "conf_files")) != 0) {
|
if ((rv = xbps_remove_pkg_files(dict, "conf_files")) != 0) {
|
||||||
prop_object_release(dict);
|
prop_object_release(dict);
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -192,7 +192,7 @@ int
|
|||||||
xbps_remove_pkg(const char *pkgname, const char *version, bool update)
|
xbps_remove_pkg(const char *pkgname, const char *version, bool update)
|
||||||
{
|
{
|
||||||
prop_dictionary_t dict;
|
prop_dictionary_t dict;
|
||||||
char *path, *buf;
|
char *buf;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
assert(pkgname != NULL);
|
assert(pkgname != NULL);
|
||||||
@ -240,19 +240,11 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update)
|
|||||||
/*
|
/*
|
||||||
* Remove links, files and dirs.
|
* Remove links, files and dirs.
|
||||||
*/
|
*/
|
||||||
path = xbps_xasprintf(".%s/metadata/%s/%s",
|
dict = xbps_get_pkg_dict_from_metadata_plist(pkgname, XBPS_PKGFILES);
|
||||||
XBPS_META_PATH, pkgname, XBPS_PKGFILES);
|
|
||||||
if (path == NULL) {
|
|
||||||
free(buf);
|
|
||||||
return errno;
|
|
||||||
}
|
|
||||||
dict = prop_dictionary_internalize_from_zfile(path);
|
|
||||||
if (dict == NULL) {
|
if (dict == NULL) {
|
||||||
free(path);
|
|
||||||
free(buf);
|
free(buf);
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
free(path);
|
|
||||||
|
|
||||||
/* Remove links */
|
/* Remove links */
|
||||||
if ((rv = xbps_remove_pkg_files(dict, "links")) != 0) {
|
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);
|
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
|
int
|
||||||
xbps_remove_string_from_array(prop_array_t array, const char *str)
|
xbps_remove_string_from_array(prop_array_t array, const char *str)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user