libxbps: make xh->cachedir to always use a full path after xbps_init().

This commit is contained in:
Juan RP 2011-12-15 14:24:10 +01:00
parent 70e95786dc
commit 32fdb35c56
2 changed files with 27 additions and 1 deletions

View File

@ -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
*

View File

@ -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;