From 8b2fe3efe3f37660998d3d7300974749afdc7a69 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sat, 8 Aug 2009 22:14:42 +0200 Subject: [PATCH] Introduce xbps_callback_array_iter_reverse_in_dict(). This function works by iterating an array in a dictionary in reverse order, i.e from down to top. --HG-- extra : convert_revision : 5e655c2edf3d42453f16830e2e944c7f6e2cd974 --- include/xbps_api.h | 31 +++++++++++++++++++--- lib/plist.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 4 deletions(-) diff --git a/include/xbps_api.h b/include/xbps_api.h index 777fa27ba64..a4b8d065c48 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -50,7 +50,7 @@ /* Filename of the packages register. */ #define XBPS_REGPKGDB "regpkgdb.plist" -/* Filename of the package properties plist file. */ +/* Package metadata files. */ #define XBPS_PKGPROPS "props.plist" #define XBPS_PKGFILES "files.plist" @@ -66,6 +66,9 @@ #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) #endif +/* From lib/configure.c */ +int xbps_configure_pkg(const char *, const char *); + /* from lib/cmpver.c */ int xbps_cmpver(const char *, const char *); @@ -99,14 +102,14 @@ void xbps_release_repolist_data(void); prop_dictionary_t xbps_get_pkg_props(void); /* From lib/register.c */ -int xbps_register_pkg(prop_dictionary_t, bool, bool); +int xbps_register_pkg(prop_dictionary_t, bool); /* From lib/requiredby.c */ int xbps_requiredby_pkg_add(prop_array_t, prop_dictionary_t); int xbps_requiredby_pkg_remove(const char *); /* From lib/unpack.c */ -int xbps_unpack_binary_pkg(prop_dictionary_t); +int xbps_unpack_binary_pkg(prop_dictionary_t, bool); /* From lib/depends.c */ int xbps_find_deps_in_pkg(prop_dictionary_t, prop_dictionary_t); @@ -120,6 +123,10 @@ int xbps_callback_array_iter_in_dict(prop_dictionary_t, const char *, int (*fn)(prop_object_t, void *, bool *), void *); +int xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t, + const char *, + int (*fn)(prop_object_t, void *, bool *), + void *); int xbps_callback_array_iter_in_repolist(int (*fn)(prop_object_t, void *, bool *), void *); @@ -134,13 +141,16 @@ void xbps_release_regpkgdb_dict(void); prop_object_iterator_t xbps_get_array_iter_from_dict(prop_dictionary_t, const char *); +prop_dictionary_t xbps_read_dict_from_archive_entry(struct archive *, + struct archive_entry *); + int xbps_remove_pkg_dict_from_file(const char *, const char *); int xbps_remove_pkg_from_dict(prop_dictionary_t, const char *, const char *); int xbps_remove_string_from_array(prop_array_t, const char *); /* From lib/remove.c */ -int xbps_remove_binary_pkg(const char *, bool); +int xbps_remove_pkg(const char *, const char *, bool); int xbps_unregister_pkg(const char *); /* From lib/repository.c */ @@ -150,6 +160,19 @@ int xbps_unregister_repository(const char *); /* From lib/sortdeps.c */ int xbps_sort_pkg_deps(prop_dictionary_t); +/* From lib/state.c */ +typedef enum pkg_state { + XBPS_PKG_STATE_UNPACKED = 1, + XBPS_PKG_STATE_INSTALLED, + XBPS_PKG_STATE_BROKEN, + XBPS_PKG_STATE_CONFIG_FILES, + XBPS_PKG_STATE_NOT_INSTALLED +} pkg_state_t; +int xbps_get_pkg_state_installed(const char *, pkg_state_t *); +int xbps_get_pkg_state_dictionary(prop_dictionary_t, pkg_state_t *); +int xbps_set_pkg_state_installed(const char *, pkg_state_t); +int xbps_set_pkg_state_dictionary(prop_dictionary_t, pkg_state_t); + /* From lib/util.c */ char * xbps_xasprintf(const char *, ...); char * xbps_get_file_hash(const char *); diff --git a/lib/plist.c b/lib/plist.c index 210cdf9cbce..83ce5727bf8 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -133,6 +133,37 @@ xbps_callback_array_iter_in_dict(prop_dictionary_t dict, const char *key, return rv; } +int +xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict, + const char *key, int (*fn)(prop_object_t, void *, bool *), void *arg) +{ + prop_array_t array; + prop_object_t obj; + int rv = 0; + bool cbloop_done = false; + unsigned int cnt = 0; + + assert(dict != NULL); + assert(key != NULL); + assert(fn != NULL); + + array = prop_dictionary_get(dict, key); + if (array == NULL || prop_object_type(array) != PROP_TYPE_ARRAY) + return EINVAL; + + if ((cnt = prop_array_count(array)) == 0) + return 0; + + while (cnt--) { + obj = prop_array_get(array, cnt); + rv = (*fn)(obj, arg, &cbloop_done); + if (rv != 0 || cbloop_done) + break; + } + + return rv; +} + prop_dictionary_t xbps_find_pkg_from_plist(const char *plist, const char *pkgname) { @@ -381,3 +412,38 @@ xbps_remove_pkg_dict_from_file(const char *pkg, const char *plist) return 0; } + +prop_dictionary_t +xbps_read_dict_from_archive_entry(struct archive *ar, + struct archive_entry *entry) +{ + prop_dictionary_t d; + size_t buflen = 0; + ssize_t nbytes = -1; + char *buf; + + assert(ar != NULL); + assert(entry != NULL); + + buflen = (size_t)archive_entry_size(entry); + buf = malloc(buflen); + if (buf == NULL) + return NULL; + + nbytes = archive_read_data(ar, buf, buflen); + if ((size_t)nbytes != buflen) { + free(buf); + return NULL; + } + + d = prop_dictionary_internalize(buf); + free(buf); + if (d == NULL) + return NULL; + else if (prop_object_type(d) != PROP_TYPE_DICTIONARY) { + prop_object_release(d); + return NULL; + } + + return d; +}