New "metadir" member in xbps_handle to override default metadata dir.
This commit is contained in:
parent
749e03aa29
commit
9bada162a1
@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2010 Juan Romero Pardines.
|
||||
* Copyright (c) 2010-2012 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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;
|
||||
|
||||
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)
|
||||
return -1;
|
||||
|
||||
|
@ -371,8 +371,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
} else if (strcasecmp(argv[0], "updatepkgdb") == 0) {
|
||||
/* update regpkgdb to pkgdb */
|
||||
plist = xbps_xasprintf("%s/%s/regpkgdb.plist",
|
||||
xh.rootdir, XBPS_META_PATH);
|
||||
plist = xbps_xasprintf("%s/regpkgdb.plist", xh.metadir);
|
||||
if (plist == NULL) {
|
||||
rv = ENOMEM;
|
||||
goto out;
|
||||
|
@ -56,7 +56,7 @@
|
||||
*/
|
||||
#define XBPS_PKGINDEX_VERSION "1.4"
|
||||
|
||||
#define XBPS_API_VERSION "20120312-1"
|
||||
#define XBPS_API_VERSION "20120313"
|
||||
#define XBPS_VERSION "0.15"
|
||||
|
||||
/**
|
||||
@ -520,10 +520,18 @@ struct xbps_handle {
|
||||
* If NULL default value in \a XBPS_CACHE_PATH is used.
|
||||
*/
|
||||
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
|
||||
*/
|
||||
char *cachedir_priv;
|
||||
char *metadir_priv;
|
||||
/**
|
||||
* @var conffile
|
||||
*
|
||||
|
@ -43,24 +43,35 @@ static bool debug;
|
||||
static bool xbps_initialized;
|
||||
static struct xbps_handle *xhp;
|
||||
|
||||
static void
|
||||
get_cachedir(struct xbps_handle *xh)
|
||||
static char *
|
||||
set_cachedir(struct xbps_handle *xh)
|
||||
{
|
||||
if (xh->cachedir[0] == '/')
|
||||
if (xh->cachedir[0] == '/') {
|
||||
/* full path */
|
||||
xh->cachedir_priv = strdup(xh->cachedir);
|
||||
else {
|
||||
return strdup(xh->cachedir);
|
||||
} else {
|
||||
/* relative to rootdir */
|
||||
if (strcmp(xh->rootdir, "/") == 0)
|
||||
xh->cachedir_priv =
|
||||
xbps_xasprintf("/%s", xh->cachedir);
|
||||
return xbps_xasprintf("/%s", xh->cachedir);
|
||||
else
|
||||
xh->cachedir_priv =
|
||||
xbps_xasprintf("%s/%s", xh->rootdir,
|
||||
return xbps_xasprintf("%s/%s", xh->rootdir,
|
||||
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
|
||||
cb_validate_virtual(cfg_t *cfg, cfg_opt_t *opt)
|
||||
{
|
||||
@ -156,12 +167,14 @@ xbps_init(struct xbps_handle *xh)
|
||||
else
|
||||
xhp->cachedir = cfg_getstr(xhp->cfg, "cachedir");
|
||||
}
|
||||
get_cachedir(xhp);
|
||||
if (xhp->cachedir_priv == NULL)
|
||||
if ((xhp->cachedir_priv = set_cachedir(xhp)) == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
xhp->cachedir = xhp->cachedir_priv;
|
||||
|
||||
if ((xhp->metadir_priv = set_metadir(xhp)) == NULL)
|
||||
return ENOMEM;
|
||||
xhp->metadir = xhp->metadir_priv;
|
||||
|
||||
if (xhp->cfg == NULL) {
|
||||
xhp->flags |= XBPS_FLAG_SYSLOG;
|
||||
xhp->fetch_timeout = XBPS_FETCH_TIMEOUT;
|
||||
@ -183,6 +196,7 @@ xbps_init(struct xbps_handle *xh)
|
||||
xbps_fetch_set_cache_connection(cc, cch);
|
||||
|
||||
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("FetchTimeout=%u\n", xhp->fetch_timeout);
|
||||
xbps_dbg_printf("FetchCacheconn=%u\n", cc);
|
||||
@ -210,6 +224,8 @@ xbps_end(void)
|
||||
cfg_free(xhp->cfg);
|
||||
if (xhp->cachedir_priv != NULL)
|
||||
free(xhp->cachedir_priv);
|
||||
if (xhp->metadir_priv != NULL)
|
||||
free(xhp->metadir_priv);
|
||||
|
||||
xhp = NULL;
|
||||
xbps_initialized = false;
|
||||
|
20
lib/pkgdb.c
20
lib/pkgdb.c
@ -80,30 +80,23 @@ int
|
||||
xbps_pkgdb_update(bool flush)
|
||||
{
|
||||
struct xbps_handle *xhp = xbps_handle_get();
|
||||
char *plist, *metadir;
|
||||
char *plist;
|
||||
int rv = 0;
|
||||
|
||||
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
|
||||
XBPS_META_PATH, XBPS_PKGDB);
|
||||
plist = xbps_xasprintf("%s/%s", xhp->metadir, XBPS_PKGDB);
|
||||
if (plist == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
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 */
|
||||
if (access(metadir, X_OK) == -1) {
|
||||
if (access(xhp->metadir, X_OK) == -1) {
|
||||
if (errno == ENOENT) {
|
||||
if (xbps_mkpath(metadir, 0755) != 0) {
|
||||
if (xbps_mkpath(xhp->metadir, 0755) != 0) {
|
||||
xbps_dbg_printf("[pkgdb] failed to "
|
||||
"create metadir %s: %s\n", metadir,
|
||||
"create metadir %s: %s\n",
|
||||
xhp->metadir,
|
||||
strerror(errno));
|
||||
rv = errno;
|
||||
free(metadir);
|
||||
free(plist);
|
||||
return rv;
|
||||
}
|
||||
@ -112,7 +105,6 @@ xbps_pkgdb_update(bool flush)
|
||||
return errno;
|
||||
}
|
||||
}
|
||||
free(metadir);
|
||||
/* flush dictionary to storage */
|
||||
if (!prop_array_externalize_to_zfile(xhp->pkgdb, plist)) {
|
||||
free(plist);
|
||||
|
@ -272,8 +272,8 @@ xbps_dictionary_from_metadata_plist(const char *pkgname,
|
||||
xhp = xbps_handle_get();
|
||||
|
||||
savedpkgname = pkgname;
|
||||
plistf = xbps_xasprintf("%s/%s/metadata/%s/%s", xhp->rootdir,
|
||||
XBPS_META_PATH, savedpkgname, plist);
|
||||
plistf = xbps_xasprintf("%s/metadata/%s/%s", xhp->metadir,
|
||||
savedpkgname, plist);
|
||||
if (plistf == NULL)
|
||||
return NULL;
|
||||
|
||||
@ -283,9 +283,8 @@ xbps_dictionary_from_metadata_plist(const char *pkgname,
|
||||
free(plistf);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd,
|
||||
"pkgname", &savedpkgname);
|
||||
plistf = xbps_xasprintf("%s/%s/metadata/%s/%s",
|
||||
xhp->rootdir,
|
||||
XBPS_META_PATH, savedpkgname, plist);
|
||||
plistf = xbps_xasprintf("%s/metadata/%s/%s",
|
||||
xhp->metadir, savedpkgname, plist);
|
||||
prop_object_release(pkgd);
|
||||
if (plistf == NULL)
|
||||
return NULL;
|
||||
|
@ -94,7 +94,7 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
|
||||
struct stat st;
|
||||
const char *fetch_outputdir, *fetchstr = NULL;
|
||||
char *rpidx, *lrepodir, *uri_fixedp;
|
||||
char *metadir, *tmp_metafile, *lrepofile;
|
||||
char *tmp_metafile, *lrepofile;
|
||||
int rv = 0;
|
||||
bool only_sync = false;
|
||||
|
||||
@ -117,16 +117,11 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
|
||||
/*
|
||||
* Create metadir if necessary.
|
||||
*/
|
||||
metadir = xbps_xasprintf("%s/%s", xhp->rootdir, XBPS_META_PATH);
|
||||
if (metadir == NULL) {
|
||||
rv = -1;
|
||||
goto out;
|
||||
}
|
||||
if ((rv = xbps_mkpath(metadir, 0755)) == -1) {
|
||||
if ((rv = xbps_mkpath(xhp->metadir, 0755)) == -1) {
|
||||
xbps_set_cb_state(XBPS_STATE_REPOSYNC_FAIL,
|
||||
errno, NULL, NULL,
|
||||
"[reposync] failed to create metadir `%s': %s",
|
||||
metadir, strerror(errno));
|
||||
xhp->metadir, strerror(errno));
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
@ -138,10 +133,10 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
|
||||
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.
|
||||
*/
|
||||
tmp_metafile = xbps_xasprintf("%s/%s", metadir, plistf);
|
||||
tmp_metafile = xbps_xasprintf("%s/%s", xhp->metadir, plistf);
|
||||
if (tmp_metafile == NULL) {
|
||||
rv = -1;
|
||||
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
|
||||
* index file.
|
||||
*/
|
||||
lrepodir = xbps_xasprintf("%s/%s/%s",
|
||||
xhp->rootdir, XBPS_META_PATH, uri_fixedp);
|
||||
lrepodir = xbps_xasprintf("%s/%s", xhp->metadir, uri_fixedp);
|
||||
if (lrepodir == NULL) {
|
||||
rv = -1;
|
||||
goto out;
|
||||
@ -165,7 +159,7 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
|
||||
only_sync = true;
|
||||
fetch_outputdir = lrepodir;
|
||||
} else
|
||||
fetch_outputdir = metadir;
|
||||
fetch_outputdir = xhp->metadir;
|
||||
|
||||
/* reposync start cb */
|
||||
xbps_set_cb_state(XBPS_STATE_REPOSYNC, 0, NULL, NULL,
|
||||
@ -232,8 +226,6 @@ out:
|
||||
free(rpidx);
|
||||
if (lrepodir)
|
||||
free(lrepodir);
|
||||
if (metadir)
|
||||
free(metadir);
|
||||
if (tmp_metafile)
|
||||
free(tmp_metafile);
|
||||
if (lrepofile)
|
||||
|
@ -213,14 +213,7 @@ get_pkg_index_remote_plist(const char *uri, const char *plistf)
|
||||
if (uri_fixed == NULL)
|
||||
return NULL;
|
||||
|
||||
if (strcmp(xhp->rootdir, "/") == 0) {
|
||||
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);
|
||||
}
|
||||
repodir = xbps_xasprintf("%s/%s/%s", xhp->metadir, uri_fixed, plistf);
|
||||
free(uri_fixed);
|
||||
return repodir;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user