New "metadir" member in xbps_handle to override default metadata dir.

This commit is contained in:
Juan RP 2012-03-13 10:22:35 +01:00
parent 749e03aa29
commit 9bada162a1
8 changed files with 58 additions and 59 deletions

View File

@ -1,5 +1,5 @@
/*- /*-
* Copyright (c) 2010 Juan Romero Pardines. * Copyright (c) 2010-2012 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
@ -87,7 +87,7 @@ find_files_in_packages(int npatterns, char **patterns)
unsigned int i, count; unsigned int i, count;
xhp = xbps_handle_get(); xhp = xbps_handle_get();
path = xbps_xasprintf("%s/%s/metadata", xhp->rootdir, XBPS_META_PATH); path = xbps_xasprintf("%s/metadata", xhp->metadir);
if (path == NULL) if (path == NULL)
return -1; return -1;

View File

@ -371,8 +371,7 @@ main(int argc, char **argv)
} }
} else if (strcasecmp(argv[0], "updatepkgdb") == 0) { } else if (strcasecmp(argv[0], "updatepkgdb") == 0) {
/* update regpkgdb to pkgdb */ /* update regpkgdb to pkgdb */
plist = xbps_xasprintf("%s/%s/regpkgdb.plist", plist = xbps_xasprintf("%s/regpkgdb.plist", xh.metadir);
xh.rootdir, XBPS_META_PATH);
if (plist == NULL) { if (plist == NULL) {
rv = ENOMEM; rv = ENOMEM;
goto out; goto out;

View File

@ -56,7 +56,7 @@
*/ */
#define XBPS_PKGINDEX_VERSION "1.4" #define XBPS_PKGINDEX_VERSION "1.4"
#define XBPS_API_VERSION "20120312-1" #define XBPS_API_VERSION "20120313"
#define XBPS_VERSION "0.15" #define XBPS_VERSION "0.15"
/** /**
@ -520,10 +520,18 @@ struct xbps_handle {
* If NULL default value in \a XBPS_CACHE_PATH is used. * If NULL default value in \a XBPS_CACHE_PATH is used.
*/ */
const char *cachedir; const char *cachedir;
/**
* @var metadir
*
* Metadata directory for all operations in XBPS.
* If NULL, defaults to \a XBPS_CACHE_PATH (relative to rootdir).
*/
const char *metadir;
/** /**
* @private * @private
*/ */
char *cachedir_priv; char *cachedir_priv;
char *metadir_priv;
/** /**
* @var conffile * @var conffile
* *

View File

@ -43,24 +43,35 @@ static bool debug;
static bool xbps_initialized; static bool xbps_initialized;
static struct xbps_handle *xhp; static struct xbps_handle *xhp;
static void static char *
get_cachedir(struct xbps_handle *xh) set_cachedir(struct xbps_handle *xh)
{ {
if (xh->cachedir[0] == '/') if (xh->cachedir[0] == '/') {
/* full path */ /* full path */
xh->cachedir_priv = strdup(xh->cachedir); return strdup(xh->cachedir);
else { } else {
/* relative to rootdir */ /* relative to rootdir */
if (strcmp(xh->rootdir, "/") == 0) if (strcmp(xh->rootdir, "/") == 0)
xh->cachedir_priv = return xbps_xasprintf("/%s", xh->cachedir);
xbps_xasprintf("/%s", xh->cachedir);
else else
xh->cachedir_priv = return xbps_xasprintf("%s/%s", xh->rootdir,
xbps_xasprintf("%s/%s", xh->rootdir,
xh->cachedir); xh->cachedir);
} }
} }
static char *
set_metadir(struct xbps_handle *xh)
{
if (xh->metadir == NULL) {
if (strcmp(xh->rootdir, "/") == 0)
return xbps_xasprintf("/%s", XBPS_META_PATH);
else
return xbps_xasprintf("%s/%s", xh->rootdir, XBPS_META_PATH);
} else {
return strdup(xh->metadir);
}
}
static int static int
cb_validate_virtual(cfg_t *cfg, cfg_opt_t *opt) cb_validate_virtual(cfg_t *cfg, cfg_opt_t *opt)
{ {
@ -156,12 +167,14 @@ xbps_init(struct xbps_handle *xh)
else else
xhp->cachedir = cfg_getstr(xhp->cfg, "cachedir"); xhp->cachedir = cfg_getstr(xhp->cfg, "cachedir");
} }
get_cachedir(xhp); if ((xhp->cachedir_priv = set_cachedir(xhp)) == NULL)
if (xhp->cachedir_priv == NULL)
return ENOMEM; return ENOMEM;
xhp->cachedir = xhp->cachedir_priv; xhp->cachedir = xhp->cachedir_priv;
if ((xhp->metadir_priv = set_metadir(xhp)) == NULL)
return ENOMEM;
xhp->metadir = xhp->metadir_priv;
if (xhp->cfg == NULL) { if (xhp->cfg == NULL) {
xhp->flags |= XBPS_FLAG_SYSLOG; xhp->flags |= XBPS_FLAG_SYSLOG;
xhp->fetch_timeout = XBPS_FETCH_TIMEOUT; xhp->fetch_timeout = XBPS_FETCH_TIMEOUT;
@ -183,6 +196,7 @@ xbps_init(struct xbps_handle *xh)
xbps_fetch_set_cache_connection(cc, cch); xbps_fetch_set_cache_connection(cc, cch);
xbps_dbg_printf("Rootdir=%s\n", xhp->rootdir); xbps_dbg_printf("Rootdir=%s\n", xhp->rootdir);
xbps_dbg_printf("Metadir=%s\n", xhp->metadir);
xbps_dbg_printf("Cachedir=%s\n", xhp->cachedir); xbps_dbg_printf("Cachedir=%s\n", xhp->cachedir);
xbps_dbg_printf("FetchTimeout=%u\n", xhp->fetch_timeout); xbps_dbg_printf("FetchTimeout=%u\n", xhp->fetch_timeout);
xbps_dbg_printf("FetchCacheconn=%u\n", cc); xbps_dbg_printf("FetchCacheconn=%u\n", cc);
@ -210,6 +224,8 @@ xbps_end(void)
cfg_free(xhp->cfg); cfg_free(xhp->cfg);
if (xhp->cachedir_priv != NULL) if (xhp->cachedir_priv != NULL)
free(xhp->cachedir_priv); free(xhp->cachedir_priv);
if (xhp->metadir_priv != NULL)
free(xhp->metadir_priv);
xhp = NULL; xhp = NULL;
xbps_initialized = false; xbps_initialized = false;

View File

@ -80,30 +80,23 @@ int
xbps_pkgdb_update(bool flush) xbps_pkgdb_update(bool flush)
{ {
struct xbps_handle *xhp = xbps_handle_get(); struct xbps_handle *xhp = xbps_handle_get();
char *plist, *metadir; char *plist;
int rv = 0; int rv = 0;
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir, plist = xbps_xasprintf("%s/%s", xhp->metadir, XBPS_PKGDB);
XBPS_META_PATH, XBPS_PKGDB);
if (plist == NULL) if (plist == NULL)
return ENOMEM; return ENOMEM;
if (xhp->pkgdb != NULL && flush) { if (xhp->pkgdb != NULL && flush) {
metadir = xbps_xasprintf("%s/%s", xhp->rootdir,
XBPS_META_PATH);
if (metadir == NULL) {
free(plist);
return ENOMEM;
}
/* Create metadir if doesn't exist */ /* Create metadir if doesn't exist */
if (access(metadir, X_OK) == -1) { if (access(xhp->metadir, X_OK) == -1) {
if (errno == ENOENT) { if (errno == ENOENT) {
if (xbps_mkpath(metadir, 0755) != 0) { if (xbps_mkpath(xhp->metadir, 0755) != 0) {
xbps_dbg_printf("[pkgdb] failed to " xbps_dbg_printf("[pkgdb] failed to "
"create metadir %s: %s\n", metadir, "create metadir %s: %s\n",
xhp->metadir,
strerror(errno)); strerror(errno));
rv = errno; rv = errno;
free(metadir);
free(plist); free(plist);
return rv; return rv;
} }
@ -112,7 +105,6 @@ xbps_pkgdb_update(bool flush)
return errno; return errno;
} }
} }
free(metadir);
/* flush dictionary to storage */ /* flush dictionary to storage */
if (!prop_array_externalize_to_zfile(xhp->pkgdb, plist)) { if (!prop_array_externalize_to_zfile(xhp->pkgdb, plist)) {
free(plist); free(plist);

View File

@ -272,8 +272,8 @@ xbps_dictionary_from_metadata_plist(const char *pkgname,
xhp = xbps_handle_get(); xhp = xbps_handle_get();
savedpkgname = pkgname; savedpkgname = pkgname;
plistf = xbps_xasprintf("%s/%s/metadata/%s/%s", xhp->rootdir, plistf = xbps_xasprintf("%s/metadata/%s/%s", xhp->metadir,
XBPS_META_PATH, savedpkgname, plist); savedpkgname, plist);
if (plistf == NULL) if (plistf == NULL)
return NULL; return NULL;
@ -283,9 +283,8 @@ xbps_dictionary_from_metadata_plist(const char *pkgname,
free(plistf); free(plistf);
prop_dictionary_get_cstring_nocopy(pkgd, prop_dictionary_get_cstring_nocopy(pkgd,
"pkgname", &savedpkgname); "pkgname", &savedpkgname);
plistf = xbps_xasprintf("%s/%s/metadata/%s/%s", plistf = xbps_xasprintf("%s/metadata/%s/%s",
xhp->rootdir, xhp->metadir, savedpkgname, plist);
XBPS_META_PATH, savedpkgname, plist);
prop_object_release(pkgd); prop_object_release(pkgd);
if (plistf == NULL) if (plistf == NULL)
return NULL; return NULL;

View File

@ -94,7 +94,7 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
struct stat st; struct stat st;
const char *fetch_outputdir, *fetchstr = NULL; const char *fetch_outputdir, *fetchstr = NULL;
char *rpidx, *lrepodir, *uri_fixedp; char *rpidx, *lrepodir, *uri_fixedp;
char *metadir, *tmp_metafile, *lrepofile; char *tmp_metafile, *lrepofile;
int rv = 0; int rv = 0;
bool only_sync = false; bool only_sync = false;
@ -117,16 +117,11 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
/* /*
* Create metadir if necessary. * Create metadir if necessary.
*/ */
metadir = xbps_xasprintf("%s/%s", xhp->rootdir, XBPS_META_PATH); if ((rv = xbps_mkpath(xhp->metadir, 0755)) == -1) {
if (metadir == NULL) {
rv = -1;
goto out;
}
if ((rv = xbps_mkpath(metadir, 0755)) == -1) {
xbps_set_cb_state(XBPS_STATE_REPOSYNC_FAIL, xbps_set_cb_state(XBPS_STATE_REPOSYNC_FAIL,
errno, NULL, NULL, errno, NULL, NULL,
"[reposync] failed to create metadir `%s': %s", "[reposync] failed to create metadir `%s': %s",
metadir, strerror(errno)); xhp->metadir, strerror(errno));
goto out; goto out;
} }
/* /*
@ -138,10 +133,10 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
goto out; goto out;
} }
/* /*
* Save temporary file in XBPS_META_PATH, and rename if it * Save temporary file in metadir, and rename if it
* was downloaded successfully. * was downloaded successfully.
*/ */
tmp_metafile = xbps_xasprintf("%s/%s", metadir, plistf); tmp_metafile = xbps_xasprintf("%s/%s", xhp->metadir, plistf);
if (tmp_metafile == NULL) { if (tmp_metafile == NULL) {
rv = -1; rv = -1;
goto out; goto out;
@ -150,8 +145,7 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
* Full path to repository directory to store the plist * Full path to repository directory to store the plist
* index file. * index file.
*/ */
lrepodir = xbps_xasprintf("%s/%s/%s", lrepodir = xbps_xasprintf("%s/%s", xhp->metadir, uri_fixedp);
xhp->rootdir, XBPS_META_PATH, uri_fixedp);
if (lrepodir == NULL) { if (lrepodir == NULL) {
rv = -1; rv = -1;
goto out; goto out;
@ -165,7 +159,7 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
only_sync = true; only_sync = true;
fetch_outputdir = lrepodir; fetch_outputdir = lrepodir;
} else } else
fetch_outputdir = metadir; fetch_outputdir = xhp->metadir;
/* reposync start cb */ /* reposync start cb */
xbps_set_cb_state(XBPS_STATE_REPOSYNC, 0, NULL, NULL, xbps_set_cb_state(XBPS_STATE_REPOSYNC, 0, NULL, NULL,
@ -232,8 +226,6 @@ out:
free(rpidx); free(rpidx);
if (lrepodir) if (lrepodir)
free(lrepodir); free(lrepodir);
if (metadir)
free(metadir);
if (tmp_metafile) if (tmp_metafile)
free(tmp_metafile); free(tmp_metafile);
if (lrepofile) if (lrepofile)

View File

@ -213,14 +213,7 @@ get_pkg_index_remote_plist(const char *uri, const char *plistf)
if (uri_fixed == NULL) if (uri_fixed == NULL)
return NULL; return NULL;
if (strcmp(xhp->rootdir, "/") == 0) { repodir = xbps_xasprintf("%s/%s/%s", xhp->metadir, uri_fixed, plistf);
repodir = xbps_xasprintf("/%s/%s/%s",
XBPS_META_PATH, uri_fixed, plistf);
} else {
repodir = xbps_xasprintf("%s/%s/%s/%s",
xhp->rootdir,
XBPS_META_PATH, uri_fixed, plistf);
}
free(uri_fixed); free(uri_fixed);
return repodir; return repodir;
} }