From 32fdb35c56a9a0187b74e22ad3e04b59283bd5f7 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Thu, 15 Dec 2011 14:24:10 +0100 Subject: [PATCH] libxbps: make xh->cachedir to always use a full path after xbps_init(). --- include/xbps_api.h | 6 +++++- lib/initend.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/xbps_api.h b/include/xbps_api.h index 6f8e74a7..58f8d27e 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -56,7 +56,7 @@ */ #define XBPS_PKGINDEX_VERSION "1.3" -#define XBPS_API_VERSION "20111215-1" +#define XBPS_API_VERSION "20111215-2" #define XBPS_VERSION "0.11.0" /** @@ -481,6 +481,10 @@ struct xbps_handle { * If NULL default value in \a XBPS_CACHE_PATH is used. */ const char *cachedir; + /** + * @private + */ + char *cachedir_priv; /** * @var confdir * diff --git a/lib/initend.c b/lib/initend.c index 49389a52..fc379d40 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -42,6 +42,24 @@ static bool debug; static struct xbps_handle *xhp; +static void +get_cachedir(struct xbps_handle *xh) +{ + if (xh->cachedir[0] == '/') + /* full path */ + xh->cachedir_priv = strdup(xh->cachedir); + else { + /* relative to rootdir */ + if (strcmp(xh->rootdir, "/") == 0) + xh->cachedir_priv = + xbps_xasprintf("/%s", xh->cachedir); + else + xh->cachedir_priv = + xbps_xasprintf("%s/%s", xh->rootdir, + xh->cachedir); + } +} + static int cb_validate_virtual(cfg_t *cfg, cfg_opt_t *opt) { @@ -133,6 +151,9 @@ xbps_init(struct xbps_handle *xh) else xhp->cachedir = cfg_getstr(xhp->cfg, "cachedir"); } + get_cachedir(xhp); + xhp->cachedir = xhp->cachedir_priv; + if (xhp->cfg == NULL) { xhp->syslog_enabled = true; xhp->fetch_timeout = XBPS_FETCH_TIMEOUT; @@ -179,6 +200,7 @@ xbps_end(struct xbps_handle *xh) if (xh->cfg != NULL) cfg_free(xh->cfg); + free(xh->cachedir_priv); free(xh); xh = NULL; xhp = NULL;