From 5642ffa86e5749900d9e9c1fb0896e9f00bc5b5f Mon Sep 17 00:00:00 2001 From: Juan RP Date: Mon, 17 Oct 2011 12:37:15 +0200 Subject: [PATCH] New configuration scheme changes, round 1. - Configuration file 'xbps-conf.plist' has been splitted off into two files: conf.plist and repositories.plist. By default they are stored in etc/xbps. - Changed some members in xbps_handle struct, mostly to make it easy to change its value in {cache,root}dir and conffile. - Made xbps_init() release proplib objects as soon as we don't need them, that way it uses 35% less of memory or in some cases even more. There will be another commit that will implement to read new virtualpkg settings by the user, as specified in: http://code.google.com/p/xbps/issues/detail?id=12 --- bin/xbps-bin/check.c | 14 +++--- bin/xbps-bin/find-files.c | 4 +- bin/xbps-bin/main.c | 11 +++-- bin/xbps-dgraph/main.c | 12 +++-- bin/xbps-repo/main.c | 9 ++-- bin/xbps-uhelper/main.c | 6 ++- configure | 4 +- etc/Makefile | 2 +- etc/conf.plist | 27 ++++++++++++ etc/repositories.plist | 25 +++++++++++ etc/xbps-conf.plist | 83 ----------------------------------- include/xbps_api.h | 84 ++++++++++++++++++++--------------- lib/initend.c | 87 ++++++++++++++++++++++--------------- lib/package_configure.c | 5 ++- lib/package_purge.c | 5 ++- lib/package_register.c | 6 ++- lib/package_remove.c | 5 ++- lib/package_requiredby.c | 3 +- lib/package_state.c | 3 +- lib/package_unpack.c | 2 +- lib/plist.c | 6 ++- lib/plist_find.c | 4 +- lib/regpkgdb_dictionary.c | 3 +- lib/repository_pool.c | 12 ++--- lib/repository_sync_index.c | 5 ++- lib/transaction_commit.c | 10 +++-- lib/util.c | 6 ++- 27 files changed, 236 insertions(+), 207 deletions(-) create mode 100644 etc/conf.plist create mode 100644 etc/repositories.plist delete mode 100644 etc/xbps-conf.plist diff --git a/bin/xbps-bin/check.c b/bin/xbps-bin/check.c index b0036148..8cc046ec 100644 --- a/bin/xbps-bin/check.c +++ b/bin/xbps-bin/check.c @@ -155,7 +155,8 @@ check_pkg_integrity(const char *pkgname) "empty target object!\n", pkgname, file); continue; } - path = xbps_xasprintf("%s/%s", xhp->rootdir, file); + path = xbps_xasprintf("%s/%s", + prop_string_cstring_nocopy(xhp->rootdir), file); if (path == NULL) abort(); @@ -168,8 +169,9 @@ check_pkg_integrity(const char *pkgname) } free(path); - if (strcmp(xhp->rootdir, "/") && strstr(buf, xhp->rootdir)) - path = buf + strlen(xhp->rootdir); + if (!prop_string_equals_cstring(xhp->rootdir, "/") && + strstr(buf, prop_string_cstring_nocopy(xhp->rootdir))) + path = buf + prop_string_size(xhp->rootdir); else path = buf; @@ -201,7 +203,8 @@ check_pkg_integrity(const char *pkgname) while ((obj = prop_object_iterator_next(iter))) { prop_dictionary_get_cstring_nocopy(obj, "file", &file); - path = xbps_xasprintf("%s/%s", xhp->rootdir, file); + path = xbps_xasprintf("%s/%s", + prop_string_cstring_nocopy(xhp->rootdir), file); if (path == NULL) { prop_object_iterator_release(iter); abort(); @@ -250,7 +253,8 @@ check_pkg_integrity(const char *pkgname) while ((obj = prop_object_iterator_next(iter))) { prop_dictionary_get_cstring_nocopy(obj, "file", &file); - path = xbps_xasprintf("%s/%s", xhp->rootdir, file); + path = xbps_xasprintf("%s/%s", + prop_string_cstring_nocopy(xhp->rootdir), file); if (path == NULL) { prop_object_iterator_release(iter); abort(); diff --git a/bin/xbps-bin/find-files.c b/bin/xbps-bin/find-files.c index 7ef90f22..1a86a340 100644 --- a/bin/xbps-bin/find-files.c +++ b/bin/xbps-bin/find-files.c @@ -81,8 +81,8 @@ find_files_in_packages(const char *pattern) unsigned int i, count; xhp = xbps_handle_get(); - path = xbps_xasprintf("%s/%s/metadata", xhp->rootdir, - XBPS_META_PATH); + path = xbps_xasprintf("%s/%s/metadata", + prop_string_cstring_nocopy(xhp->rootdir), XBPS_META_PATH); if (path == NULL) return -1; diff --git a/bin/xbps-bin/main.c b/bin/xbps-bin/main.c index f36357c6..c22f3731 100644 --- a/bin/xbps-bin/main.c +++ b/bin/xbps-bin/main.c @@ -285,10 +285,15 @@ main(int argc, char **argv) xhp->xbps_unpack_cb = unpack_progress_cb_verbose; else xhp->xbps_unpack_cb = unpack_progress_cb; - xhp->rootdir = rootdir; - xhp->cachedir = cachedir; + + if (rootdir) + xhp->rootdir = prop_string_create_cstring(rootdir); + if (cachedir) + xhp->cachedir = prop_string_create_cstring(cachedir); + if (conffile) + xhp->conffile = prop_string_create_cstring(conffile); + xhp->flags = flags; - xhp->conffile = conffile; xhp->install_reason_manual = install_manual; xhp->install_reason_auto = install_auto; diff --git a/bin/xbps-dgraph/main.c b/bin/xbps-dgraph/main.c index 62ed079b..63d8eebd 100644 --- a/bin/xbps-dgraph/main.c +++ b/bin/xbps-dgraph/main.c @@ -442,7 +442,7 @@ int main(int argc, char **argv) { prop_dictionary_t plistd, confd = NULL; - struct xbps_handle xh; + struct xbps_handle *xhp; FILE *f = NULL; char *outfile = NULL; const char *conf_file = NULL, *rootdir = NULL; @@ -484,9 +484,13 @@ main(int argc, char **argv) usage(); /* Initialize libxbps */ - memset(&xh, 0, sizeof(xh)); - xh.rootdir = rootdir; - xbps_init(&xh); + xhp = xbps_handle_alloc(); + if (xhp == NULL) + die("failed to allocate resources"); + if (rootdir) + xhp->rootdir = prop_string_create_cstring(rootdir); + if (xbps_init(xhp)) + die("failed to initialize libxbps"); /* * Output file will be .dot if not specified. diff --git a/bin/xbps-repo/main.c b/bin/xbps-repo/main.c index 739751b2..b03099be 100644 --- a/bin/xbps-repo/main.c +++ b/bin/xbps-repo/main.c @@ -139,9 +139,12 @@ main(int argc, char **argv) xhp->xbps_transaction_err_cb = transaction_err_cb; xhp->xbps_fetch_cb = fetch_file_progress_cb; xhp->xfcd->cookie = &xfer; - xhp->rootdir = rootdir; - xhp->cachedir = cachedir; - xhp->conffile = conffile; + if (rootdir) + xhp->rootdir = prop_string_create_cstring(rootdir); + if (cachedir) + xhp->cachedir = prop_string_create_cstring(cachedir); + if (conffile) + xhp->conffile = prop_string_create_cstring(conffile); if ((rv = xbps_init(xhp)) != 0) { xbps_error_printf("xbps-repo: couldn't initialize library: %s\n", diff --git a/bin/xbps-uhelper/main.c b/bin/xbps-uhelper/main.c index 9384a123..e32b548e 100644 --- a/bin/xbps-uhelper/main.c +++ b/bin/xbps-uhelper/main.c @@ -156,8 +156,10 @@ main(int argc, char **argv) xhp->debug = debug; xhp->xbps_fetch_cb = fetch_file_progress_cb; xhp->xfcd->cookie = &xfer; - xhp->rootdir = rootdir; - xhp->conffile = conffile; + if (rootdir) + xhp->rootdir = prop_string_create_cstring(rootdir); + if (conffile) + xhp->conffile = prop_string_create_cstring(conffile); if ((rv = xbps_init(xhp)) != 0) { xbps_error_printf("xbps-uhelper: failed to " diff --git a/configure b/configure index b26b3c95..df9709a8 100755 --- a/configure +++ b/configure @@ -136,6 +136,8 @@ echo "INCLUDEDIR ?= $INCLUDEDIR" >>$CONFIG_MK echo "LIBDIR ?= $LIBDIR" >>$CONFIG_MK echo "MANDIR ?= $MANDIR" >>$CONFIG_MK echo "SHAREDIR ?= $SHAREDIR" >>$CONFIG_MK + +ETCDIR="${ETCDIR}/xbps" echo "ETCDIR ?= $ETCDIR" >>$CONFIG_MK [ -z "$DEBUG" ] && DEBUG=no @@ -172,7 +174,7 @@ if [ -n "$LDFLAGS" ]; then fi echo "CPPFLAGS = -I. -I\$(TOPDIR) -I\$(TOPDIR)/include" >>$CONFIG_MK echo "CPPFLAGS += -DHAVE_CONFIG_H" >>$CONFIG_MK -echo "CPPFLAGS += -DXBPS_CONF_PATH=\\\"${ETCDIR}\\\"" >>$CONFIG_MK +echo "CPPFLAGS += -DXBPS_SYSCONF_PATH=\\\"${ETCDIR}\\\"" >>$CONFIG_MK if [ -n "$DEBUG" -a "$DEBUG" != no -a "$DEBUG" != false ]; then echo "Building with debugging symbols." diff --git a/etc/Makefile b/etc/Makefile index b3c69e61..f603b944 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -1,6 +1,6 @@ -include ../config.mk -CONF_FILE = xbps-conf.plist +CONF_FILE = conf.plist repositories.plist .PHONY: all all: diff --git a/etc/conf.plist b/etc/conf.plist new file mode 100644 index 00000000..cd55fcd1 --- /dev/null +++ b/etc/conf.plist @@ -0,0 +1,27 @@ + + + + + + root-directory + / + + + cache-directory + var/cache/xbps + + + fetch-cache-connections + 10 + + + fetch-cache-connections-per-host + 6 + + + fetch-timeout-connection + 30 + + diff --git a/etc/repositories.plist b/etc/repositories.plist new file mode 100644 index 00000000..364a8f18 --- /dev/null +++ b/etc/repositories.plist @@ -0,0 +1,25 @@ + + + + + + http://xbps.nopcode.org/repos/current + + diff --git a/etc/xbps-conf.plist b/etc/xbps-conf.plist deleted file mode 100644 index 4d425275..00000000 --- a/etc/xbps-conf.plist +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - root-directory - / - - - cache-directory - var/cache/xbps - - - fetch-cache-connections - 10 - - - fetch-cache-connections-per-host - 6 - - - fetch-timeout-connection - 30 - - - repositories - - - http://xbps.nopcode.org/repos/current - - - - virtual-packages - - - - virtual-pkgver - cron-daemon-0 - target-pkgpattern - dcron>=0 - - - - - - - - diff --git a/include/xbps_api.h b/include/xbps_api.h index 05df0b8d..801fd653 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -55,7 +55,7 @@ */ #define XBPS_PKGINDEX_VERSION "1.2" -#define XBPS_API_VERSION "20111016-1" +#define XBPS_API_VERSION "20111017" #define XBPS_VERSION "0.10.0" /** @@ -103,18 +103,32 @@ #define XBPS_PKGINDEX "pkg-index.plist" /** - * @def XBPS_CONF_PATH + * @def XBPS_SYSCONF_PATH * Default configuration PATH to find XBPS_CONF_PLIST. */ -#ifndef XBPS_CONF_PATH -#define XBPS_CONF_PATH "/etc" +#define XBPS_SYSDIR "/xbps" +#ifndef XBPS_SYSCONF_PATH +#define XBPS_SYSCONF_PATH "/etc" XBPS_SYSDIR #endif /** * @def XBPS_CONF_PLIST * Filename for the XBPS plist configuration file. */ -#define XBPS_CONF_PLIST "xbps-conf.plist" +#define XBPS_CONF_PLIST "conf.plist" + +/** + * @def XBPS_CONF_REPOS_PLIST + * Filename for the XBPS repositories plist configuration file. + */ +#define XBPS_CONF_REPOS_PLIST "repositories.plist" + +/** + * @def XBPS_VIRTUALPKGD_PATH + * Default directory to load virtualpkg plist files, by default set + * to XBPS_SYSCONF_PATH + "/" + XBPS_VIRTUALPKGD_PATH. + */ +#define XBPS_VIRTUALPKGD_PATH "virtualpkg.d.wants" /** * @def XBPS_FLAG_VERBOSE @@ -372,12 +386,16 @@ struct xbps_unpack_cb_data { */ struct xbps_handle { /** - * @private conf_dictionary - * - * Internalized proplib dictionary from conffile member. - * Used internally by xbps_init(). + * @private */ - prop_dictionary_t conf_dictionary; + prop_dictionary_t virtualpkg_dictionary; + /** + * @private repos_array + * + * Internalized proplib array from XBPS_CONF_REPOS_PLIST file. + * Used internally by xbps_init(), do not use it. + */ + prop_array_t repos_array; /** * @var regpkgdb_dictionary. * @@ -435,6 +453,26 @@ struct xbps_handle { * as argument to the \a xbps_fetch_cb function callback. */ struct xbps_fetch_cb_data *xfcd; + /** + * @var rootdir + * + * Root directory for all operations in XBPS. If NULL, + * by default it's set to /. + */ + prop_string_t rootdir; + /** + * @var cachedir + * + * Cache directory to store downloaded binary packages. + * If NULL default value in \a XBPS_CACHE_PATH is used. + */ + prop_string_t cachedir; + /** + * @var conffile + * + * Full path to the XBPS_CONF_PLIST configuration file. + */ + prop_string_t conffile; /** * @private fetch_timeout * @@ -453,32 +491,6 @@ struct xbps_handle { * - XBPS_FLAG_FORCE */ int flags; - /** - * @var rootdir - * - * Root directory for all operations in XBPS. If NULL, - * by default it's set to /. - */ - const char *rootdir; - /** - * @var cachedir - * - * Cache directory to store downloaded binary packages. - * If NULL default value in \a XBPS_CACHE_PATH is used. - */ - const char *cachedir; - /** - * @private pstring_cachedir - * - * Used internally by xbps_init(), do not use it. - */ - prop_string_t pstring_cachedir; - /** - * @var conffile - * - * Full path to the XBPS_CONF_PLIST configuration file. - */ - const char *conffile; /** * @var debug * diff --git a/lib/initend.c b/lib/initend.c index 15269d51..2d58245b 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -42,9 +42,13 @@ static bool debug; static struct xbps_handle *xhp; +#define _CONFFILE XBPS_SYSCONF_PATH "/" XBPS_CONF_PLIST +#define _REPOFILE XBPS_SYSCONF_PATH "/" XBPS_CONF_REPOS_PLIST + int xbps_init(struct xbps_handle *xh) { + prop_dictionary_t confd; const char *conf_rootdir = NULL, *conf_cachedir = NULL; uint16_t fetch_cache_conn = 0, fetch_cache_conn_host = 0; int rv; @@ -54,16 +58,19 @@ xbps_init(struct xbps_handle *xh) xhp = xh; debug = xhp->debug; - /* If conffile not set, defaults to XBPS_CONF_PATH */ - if (xhp->conffile == NULL) - xhp->conffile = XBPS_CONF_PATH "/" XBPS_CONF_PLIST; - + /* If conffile not set, defaults to XBPS_SYSCONF_PATH */ + if (prop_object_type(xhp->conffile) != PROP_TYPE_STRING) + xhp->conffile = prop_string_create_cstring(_CONFFILE); + /* + * Internalize the XBPS_CONF_REPOS_PLIST array. + */ + xhp->repos_array = prop_array_internalize_from_file(_REPOFILE); /* * Internalize the XBPS_CONF_PLIST dictionary. */ - xhp->conf_dictionary = - prop_dictionary_internalize_from_file(xhp->conffile); - if (xhp->conf_dictionary == NULL) { + confd = prop_dictionary_internalize_from_file( + prop_string_cstring_nocopy(xhp->conffile)); + if (confd == NULL) { if (errno != ENOENT) { xbps_dbg_printf("%s: cannot internalize conf " "dictionary: %s\n", strerror(errno)); @@ -76,15 +83,15 @@ xbps_init(struct xbps_handle *xh) /* * Get defaults from configuration file. */ - prop_dictionary_get_cstring_nocopy(xhp->conf_dictionary, + prop_dictionary_get_cstring_nocopy(confd, "root-directory", &conf_rootdir); - prop_dictionary_get_cstring_nocopy(xhp->conf_dictionary, + prop_dictionary_get_cstring_nocopy(confd, "cache-directory", &conf_cachedir); - prop_dictionary_get_uint16(xhp->conf_dictionary, + prop_dictionary_get_uint16(confd, "fetch-cache-connections", &fetch_cache_conn); - prop_dictionary_get_uint16(xhp->conf_dictionary, + prop_dictionary_get_uint16(confd, "fetch-cache-connections-per-host", &fetch_cache_conn_host); - prop_dictionary_get_uint16(xhp->conf_dictionary, + prop_dictionary_get_uint16(confd, "fetch-timeout-connection", &xhp->fetch_timeout); } @@ -92,33 +99,32 @@ xbps_init(struct xbps_handle *xh) * Client supplied values in xbps_handle will be choosen over the * same values in configuration file. If not specified, use defaults. */ - if (xhp->rootdir == NULL) { + if (prop_object_type(xhp->rootdir) != PROP_TYPE_STRING) { if (conf_rootdir != NULL) - xhp->rootdir = conf_rootdir; + xhp->rootdir = prop_string_create_cstring(conf_rootdir); else { /* If rootdir not set, defaults to '/' */ - xhp->rootdir = "/"; + xhp->rootdir = prop_string_create_cstring("/"); } } - if (xhp->cachedir == NULL) { + if (prop_object_type(xhp->cachedir) != PROP_TYPE_STRING) { if (conf_cachedir != NULL) { if (conf_cachedir[0] == '/') { /* full path */ - xhp->cachedir = conf_cachedir; + xhp->cachedir = + prop_string_create_cstring(conf_cachedir); } else { /* relative to rootdir */ - xhp->pstring_cachedir = - prop_string_create_cstring(xhp->rootdir); + xhp->cachedir = prop_string_copy(xhp->rootdir); prop_string_append_cstring( - xhp->pstring_cachedir, "/"); + xhp->cachedir, "/"); prop_string_append_cstring( - xhp->pstring_cachedir, conf_cachedir); - xhp->cachedir = prop_string_cstring_nocopy( - xhp->pstring_cachedir); + xhp->cachedir, conf_cachedir); } } else { /* If cachedir not set, defaults to XBPS_CACHE_PATH */ - xhp->cachedir = XBPS_CACHE_PATH; + xhp->cachedir = + prop_string_create_cstring(XBPS_CACHE_PATH); } } if (fetch_cache_conn == 0) @@ -129,12 +135,16 @@ xbps_init(struct xbps_handle *xh) xbps_fetch_set_cache_connection(fetch_cache_conn, fetch_cache_conn_host); - xbps_dbg_printf("%s: rootdir: `%s' cachedir: `%s' conf: `%s'\n", - __func__, xhp->rootdir, xhp->cachedir, xhp->conffile); - xbps_dbg_printf("%s: fetch_cache_conn: %zu fetch_cache_host: %zu\n", - __func__, fetch_cache_conn, fetch_cache_conn_host); - xbps_dbg_printf("%s: fetch_timeout: %zu\n", __func__, - xhp->fetch_timeout); + xbps_dbg_printf("rootdir: %s\n", + prop_string_cstring_nocopy(xhp->rootdir)); + xbps_dbg_printf("cachedir: %s\n", + prop_string_cstring_nocopy(xhp->cachedir)); + xbps_dbg_printf("conffile: %s\n", + prop_string_cstring_nocopy(xhp->conffile)); + xbps_dbg_printf("repofile: %s\n", _REPOFILE); + xbps_dbg_printf("fetch_cache_conn: %zu\n", fetch_cache_conn); + xbps_dbg_printf("fetch_cacche_conn_host: %zu\n", fetch_cache_conn_host); + xbps_dbg_printf("fetch_timeout: %zu\n", xhp->fetch_timeout); /* * Initialize regpkgdb dictionary. @@ -147,6 +157,12 @@ xbps_init(struct xbps_handle *xh) return rv; } } + /* We don't need the confd dictionary internalized anymore */ + if (prop_object_type(confd) == PROP_TYPE_DICTIONARY) + prop_object_release(confd); + /* We don't need the conffile string anymore */ + if (prop_object_type(xh->conffile) == PROP_TYPE_STRING) + prop_object_release(xh->conffile); return 0; } @@ -157,14 +173,13 @@ xbps_end(struct xbps_handle *xh) xbps_regpkgdb_dictionary_release(); xbps_repository_pool_release(); xbps_fetch_unset_cache_connection(); + if (xh == NULL) return; - - if (prop_object_type(xh->conf_dictionary) == PROP_TYPE_DICTIONARY) - prop_object_release(xh->conf_dictionary); - if (prop_object_type(xh->pstring_cachedir) == PROP_TYPE_STRING) - prop_object_release(xh->pstring_cachedir); - + if (prop_object_type(xh->rootdir) == PROP_TYPE_STRING) + prop_object_release(xh->rootdir); + if (prop_object_type(xh->cachedir) == PROP_TYPE_STRING) + prop_object_release(xh->cachedir); if (xh->xfcd != NULL) free(xh->xfcd); if (xh->xucd != NULL) diff --git a/lib/package_configure.c b/lib/package_configure.c index bf3620b2..6e39d48b 100644 --- a/lib/package_configure.c +++ b/lib/package_configure.c @@ -127,9 +127,10 @@ xbps_configure_pkg(const char *pkgname, return ENOMEM; } - if (chdir(xhp->rootdir) == -1) { + if (chdir(prop_string_cstring_nocopy(xhp->rootdir)) == -1) { xbps_dbg_printf("%s: [configure] chdir to '%s' returned %s\n", - pkgname, xhp->rootdir, strerror(errno)); + pkgname, prop_string_cstring_nocopy(xhp->rootdir), + strerror(errno)); free(buf); free(pkgver); return EINVAL; diff --git a/lib/package_purge.c b/lib/package_purge.c index 8ac81f28..333028ff 100644 --- a/lib/package_purge.c +++ b/lib/package_purge.c @@ -160,7 +160,7 @@ xbps_purge_pkg(const char *pkgname, bool check_state) /* * Execute the purge action in REMOVE script (if found). */ - if (chdir(xhp->rootdir) == -1) { + if (chdir(prop_string_cstring_nocopy(xhp->rootdir)) == -1) { rv = errno; prop_object_release(dict); xbps_error_printf("[purge] %s: cannot change to rootdir: %s.\n", @@ -194,7 +194,8 @@ xbps_purge_pkg(const char *pkgname, bool check_state) /* * Remove metadata dir and unregister package. */ - if ((rv = remove_pkg_metadata(pkgname, xhp->rootdir)) != 0) { + if ((rv = remove_pkg_metadata(pkgname, + prop_string_cstring_nocopy(xhp->rootdir))) != 0) { xbps_error_printf("%s: couldn't remove metadata files: %s\n", pkgname, strerror(rv)); return rv; diff --git a/lib/package_register.c b/lib/package_register.c index b75c57ea..c90470eb 100644 --- a/lib/package_register.c +++ b/lib/package_register.c @@ -51,7 +51,8 @@ xbps_register_pkg(prop_dictionary_t pkgrd) bool autoinst = false; xhp = xbps_handle_get(); - plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir, + plist = xbps_xasprintf("%s/%s/%s", + prop_string_cstring_nocopy(xhp->rootdir), XBPS_META_PATH, XBPS_REGPKGDB); if (plist == NULL) return ENOMEM; @@ -162,7 +163,8 @@ xbps_unregister_pkg(const char *pkgname) assert(pkgname != NULL); xhp = xbps_handle_get(); - plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir, + plist = xbps_xasprintf("%s/%s/%s", + prop_string_cstring_nocopy(xhp->rootdir), XBPS_META_PATH, XBPS_REGPKGDB); if (plist == NULL) return ENOMEM; diff --git a/lib/package_remove.c b/lib/package_remove.c index e6bf430b..7a5afe7e 100644 --- a/lib/package_remove.c +++ b/lib/package_remove.c @@ -106,7 +106,8 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key) while ((obj = prop_object_iterator_next(iter))) { prop_dictionary_get_cstring_nocopy(obj, "file", &file); - path = xbps_xasprintf("%s/%s", xhp->rootdir, file); + path = xbps_xasprintf("%s/%s", + prop_string_cstring_nocopy(xhp->rootdir), file); if (path == NULL) { rv = ENOMEM; break; @@ -194,7 +195,7 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update) if (buf == NULL) return ENOMEM; - if (chdir(xhp->rootdir) == -1) { + if (chdir(prop_string_cstring_nocopy(xhp->rootdir)) == -1) { free(buf); return EINVAL; } diff --git a/lib/package_requiredby.c b/lib/package_requiredby.c index b87f758a..b0f99500 100644 --- a/lib/package_requiredby.c +++ b/lib/package_requiredby.c @@ -110,7 +110,8 @@ xbps_requiredby_pkg_remove(const char *pkgname) assert(pkgname != NULL); xhp = xbps_handle_get(); - plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir, + plist = xbps_xasprintf("%s/%s/%s", + prop_string_cstring_nocopy(xhp->rootdir), XBPS_META_PATH, XBPS_REGPKGDB); if (plist == NULL) return ENOMEM; diff --git a/lib/package_state.c b/lib/package_state.c index dcf60ead..5a7bd8cc 100644 --- a/lib/package_state.c +++ b/lib/package_state.c @@ -175,7 +175,8 @@ xbps_set_pkg_state_installed(const char *pkgname, assert(pkgname != NULL); xhp = xbps_handle_get(); - metadir = xbps_xasprintf("%s/%s", xhp->rootdir, XBPS_META_PATH); + metadir = xbps_xasprintf("%s/%s", + prop_string_cstring_nocopy(xhp->rootdir), XBPS_META_PATH); if (metadir == NULL) return ENOMEM; plist = xbps_xasprintf("%s/%s", metadir, XBPS_REGPKGDB); diff --git a/lib/package_unpack.c b/lib/package_unpack.c index c67021c4..55cf7bf5 100644 --- a/lib/package_unpack.c +++ b/lib/package_unpack.c @@ -172,7 +172,7 @@ unpack_archive(prop_dictionary_t pkg_repod, preserve = update = false; - if (chdir(xhp->rootdir) == -1) { + if (chdir(prop_string_cstring_nocopy(xhp->rootdir)) == -1) { xbps_error_printf("cannot chdir to rootdir for " "`%s-%s': %s\n", pkgname, version, strerror(errno)); return errno; diff --git a/lib/plist.c b/lib/plist.c index e5efcfe6..90629b67 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -196,7 +196,8 @@ xbps_dictionary_from_metadata_plist(const char *pkgname, xhp = xbps_handle_get(); plistf = xbps_xasprintf("%s/%s/metadata/%s/%s", - xhp->rootdir, XBPS_META_PATH, pkgname, plist); + prop_string_cstring_nocopy(xhp->rootdir), + XBPS_META_PATH, pkgname, plist); if (plistf == NULL) return NULL; @@ -209,7 +210,8 @@ xbps_dictionary_from_metadata_plist(const char *pkgname, } free(plistf); plistf = xbps_xasprintf("%s/%s/metadata/%s/%s", - xhp->rootdir, XBPS_META_PATH, pkgname, plist); + prop_string_cstring_nocopy(xhp->rootdir), + XBPS_META_PATH, pkgname, plist); if (plistf == NULL) return NULL; } diff --git a/lib/plist_find.c b/lib/plist_find.c index 094f79ad..1e450658 100644 --- a/lib/plist_find.c +++ b/lib/plist_find.c @@ -127,10 +127,10 @@ find_virtualpkg_user_in_conf(const char *vpkg, bool bypattern) char *vpkgname = NULL; xhp = xbps_handle_get(); - if (xhp->conf_dictionary == NULL) + if (xhp->virtualpkg_dictionary == NULL) return NULL; - if ((iter = xbps_array_iter_from_dict(xhp->conf_dictionary, + if ((iter = xbps_array_iter_from_dict(xhp->virtualpkg_dictionary, "virtual-packages")) == NULL) return NULL; diff --git a/lib/regpkgdb_dictionary.c b/lib/regpkgdb_dictionary.c index c70eead3..8c2afab3 100644 --- a/lib/regpkgdb_dictionary.c +++ b/lib/regpkgdb_dictionary.c @@ -66,7 +66,8 @@ xbps_regpkgdb_dictionary_init(struct xbps_handle *xhp) if (regpkgdb_initialized) return 0; - plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir, + plist = xbps_xasprintf("%s/%s/%s", + prop_string_cstring_nocopy(xhp->rootdir), XBPS_META_PATH, XBPS_REGPKGDB); if (plist == NULL) return ENOMEM; diff --git a/lib/repository_pool.c b/lib/repository_pool.c index 457246b7..e4cb2fe3 100644 --- a/lib/repository_pool.c +++ b/lib/repository_pool.c @@ -73,7 +73,6 @@ int HIDDEN xbps_repository_pool_init(void) { struct xbps_handle *xhp; - prop_array_t array; prop_object_t obj; prop_object_iterator_t iter = NULL; struct repository_pool *rpool; @@ -84,20 +83,16 @@ xbps_repository_pool_init(void) bool duprepo; xhp = xbps_handle_get(); - if (xhp->conf_dictionary == NULL) + if (xhp->repos_array == NULL) return ENOTSUP; if (repolist_initialized) return 0; - array = prop_dictionary_get(xhp->conf_dictionary, "repositories"); - if (array == NULL) - return errno; - - if (prop_array_count(array) == 0) + if (prop_array_count(xhp->repos_array) == 0) return ENOTSUP; - iter = prop_array_iterator(array); + iter = prop_array_iterator(xhp->repos_array); if (iter == NULL) { rv = errno; goto out; @@ -189,6 +184,7 @@ xbps_repository_pool_init(void) } repolist_initialized = true; + prop_object_release(xhp->repos_array); xbps_dbg_printf("[rpool] initialized ok.\n"); out: if (iter) diff --git a/lib/repository_sync_index.c b/lib/repository_sync_index.c index c7f33f73..0a913953 100644 --- a/lib/repository_sync_index.c +++ b/lib/repository_sync_index.c @@ -122,7 +122,8 @@ xbps_repository_sync_pkg_index(const char *uri) /* * Create metadir if necessary. */ - metadir = xbps_xasprintf("%s/%s", xhp->rootdir, XBPS_META_PATH); + metadir = xbps_xasprintf("%s/%s", + prop_string_cstring_nocopy(xhp->rootdir), XBPS_META_PATH); if (metadir == NULL) { rv = -1; goto out; @@ -154,7 +155,7 @@ xbps_repository_sync_pkg_index(const char *uri) * file. */ lrepodir = xbps_xasprintf("%s/%s/%s", - xhp->rootdir, XBPS_META_PATH, uri_fixedp); + prop_string_cstring_nocopy(xhp->rootdir), XBPS_META_PATH, uri_fixedp); if (lrepodir == NULL) { rv = -1; goto out; diff --git a/lib/transaction_commit.c b/lib/transaction_commit.c index 3a2d9a1a..5c0f91f7 100644 --- a/lib/transaction_commit.c +++ b/lib/transaction_commit.c @@ -137,9 +137,12 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter) /* * Create cachedir. */ - if (xbps_mkpath(xhp->cachedir, 0755) == -1) { + if (xbps_mkpath(prop_string_cstring_nocopy(xhp->cachedir), + 0755) == -1) { xbps_error_printf("xbps-bin: cannot mkdir cachedir " - "`%s': %s.\n", xhp->cachedir, strerror(errno)); + "`%s': %s.\n", + prop_string_cstring_nocopy(xhp->cachedir), + strerror(errno)); free(binfile); rv = errno; break; @@ -149,7 +152,8 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter) /* * Fetch binary package. */ - rv = xbps_fetch_file(binfile, xhp->cachedir, false, NULL); + rv = xbps_fetch_file(binfile, + prop_string_cstring_nocopy(xhp->cachedir), false, NULL); if (rv == -1) { RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_DOWNLOAD, pkgver, errno); free(binfile); diff --git a/lib/util.c b/lib/util.c index dfe45667..7e7cb579 100644 --- a/lib/util.c +++ b/lib/util.c @@ -214,7 +214,8 @@ get_pkg_index_remote_plist(const char *uri) return NULL; repodir = xbps_xasprintf("%s/%s/%s/%s", - xhp->rootdir, XBPS_META_PATH, uri_fixed, XBPS_PKGINDEX); + prop_string_cstring_nocopy(xhp->rootdir), + XBPS_META_PATH, uri_fixed, XBPS_PKGINDEX); if (repodir == NULL) { free(uri_fixed); return NULL; @@ -261,7 +262,8 @@ xbps_path_from_repository_uri(prop_dictionary_t pkg_repod, const char *repoloc) /* * First check if binpkg is available in cachedir. */ - lbinpkg = xbps_xasprintf("%s/%s", xhp->cachedir, filen); + lbinpkg = xbps_xasprintf("%s/%s", + prop_string_cstring_nocopy(xhp->cachedir), filen); if (lbinpkg == NULL) return NULL;