New configuration file via confuse: xbps.conf.
This commit is contained in:
@@ -46,10 +46,10 @@ OBJS += package_remove.o package_remove_obsoletes.o package_state.o
|
||||
OBJS += package_unpack.o package_requiredby.o package_register.o
|
||||
OBJS += package_purge.o transaction_commit.o transaction_package_replace.o
|
||||
OBJS += transaction_dictionary.o transaction_sortdeps.o transaction_ops.o
|
||||
OBJS += download.o
|
||||
OBJS += download.o initend.o
|
||||
OBJS += plist.o plist_archive_entry.o plist_find.o plist_match.o
|
||||
OBJS += plist_remove.o plist_fetch.o util.o util_hash.o
|
||||
OBJS += initend.o regpkgdb_dictionary.o init_virtualpkgs.o
|
||||
OBJS += regpkgdb_dictionary.o
|
||||
OBJS += repository_finddeps.o cb_util.o
|
||||
OBJS += repository_pool.o repository_pool_find.o repository_sync_index.o
|
||||
OBJS += $(EXTOBJS) $(COMPAT_SRCS)
|
||||
|
||||
@@ -111,12 +111,7 @@ xbps_fetch_file(const char *uri,
|
||||
fetchLastErrCode = 0;
|
||||
|
||||
xhp = xbps_handle_get();
|
||||
|
||||
if (xhp->fetch_timeout != 0)
|
||||
fetchTimeout = xhp->fetch_timeout;
|
||||
else
|
||||
fetchTimeout = 30; /* 30s if not set in configuration file. */
|
||||
|
||||
fetchTimeout = xhp->fetch_timeout;
|
||||
/*
|
||||
* Get the filename specified in URI argument.
|
||||
*/
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2011 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "xbps_api_impl.h"
|
||||
|
||||
/**
|
||||
* @file lib/init_virtualpkg.c
|
||||
* @brief Initialization of virtual package settings.
|
||||
*/
|
||||
void HIDDEN
|
||||
xbps_init_virtual_pkgs(struct xbps_handle *xh)
|
||||
{
|
||||
struct dirent *dp;
|
||||
DIR *dirp;
|
||||
prop_dictionary_t vpkgd;
|
||||
prop_string_t vpkgdir;
|
||||
char *vpkgfile;
|
||||
|
||||
assert(xh != NULL);
|
||||
|
||||
if (prop_object_type(xh->confdir) != PROP_TYPE_STRING) {
|
||||
vpkgdir = prop_string_create_cstring(XBPS_SYSCONF_PATH);
|
||||
prop_string_append_cstring(vpkgdir, "/");
|
||||
prop_string_append_cstring(vpkgdir, XBPS_VIRTUALPKGD_PATH);
|
||||
} else {
|
||||
vpkgdir = prop_string_copy(xh->confdir);
|
||||
prop_string_append_cstring(vpkgdir, "/");
|
||||
prop_string_append_cstring(vpkgdir, XBPS_VIRTUALPKGD_PATH);
|
||||
}
|
||||
|
||||
/*
|
||||
* Internalize all plist files from vpkgdir and add them
|
||||
* into xhp->virtualpkgs_array.
|
||||
*/
|
||||
dirp = opendir(prop_string_cstring_nocopy(vpkgdir));
|
||||
if (dirp == NULL) {
|
||||
xbps_dbg_printf("[init_virtualpkgs] cannot access "
|
||||
"to %s for virtual packages: %s\n",
|
||||
prop_string_cstring_nocopy(vpkgdir),
|
||||
strerror(errno));
|
||||
prop_object_release(vpkgdir);
|
||||
return;
|
||||
}
|
||||
while ((dp = readdir(dirp)) != NULL) {
|
||||
if ((strcmp(dp->d_name, ".") == 0) ||
|
||||
(strcmp(dp->d_name, "..") == 0))
|
||||
continue;
|
||||
|
||||
if (strstr(dp->d_name, ".plist") == NULL)
|
||||
continue;
|
||||
|
||||
vpkgfile = xbps_xasprintf("%s/%s",
|
||||
prop_string_cstring_nocopy(vpkgdir), dp->d_name);
|
||||
if (vpkgfile == NULL) {
|
||||
xbps_dbg_printf("[init_virtualpkgs] failed to "
|
||||
"alloc mem for %s\n", dp->d_name);
|
||||
continue;
|
||||
}
|
||||
vpkgd = prop_dictionary_internalize_from_file(vpkgfile);
|
||||
free(vpkgfile);
|
||||
|
||||
if (vpkgd == NULL) {
|
||||
xbps_dbg_printf("[init_virtualpkgs] failed to "
|
||||
"internalize %s: %s\n",
|
||||
dp->d_name, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
if (prop_object_type(xh->virtualpkgs_array) == PROP_TYPE_UNKNOWN)
|
||||
xh->virtualpkgs_array = prop_array_create();
|
||||
|
||||
if (!xbps_add_obj_to_array(xh->virtualpkgs_array, vpkgd)) {
|
||||
xbps_dbg_printf("[init_virtualpkgs] failed to add %s "
|
||||
"virtuapkg dictionary!\n", dp->d_name);
|
||||
prop_object_release(vpkgd);
|
||||
continue;
|
||||
}
|
||||
xbps_dbg_printf("[init_virtualpkgs] registered virtualpkg "
|
||||
"'%s'\n", dp->d_name);
|
||||
}
|
||||
(void)closedir(dirp);
|
||||
prop_object_release(vpkgdir);
|
||||
}
|
||||
221
lib/initend.c
221
lib/initend.c
@@ -42,129 +42,115 @@
|
||||
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
|
||||
static int
|
||||
cb_validate_virtual(cfg_t *cfg, cfg_opt_t *opt)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < cfg_size(cfg, "virtual-package"); i++) {
|
||||
cfg_t *sec = cfg_opt_getnsec(opt, i);
|
||||
if (cfg_getstr(sec, "targets") == 0) {
|
||||
cfg_error(cfg, "targets must be set for "
|
||||
"virtual-package %s", cfg_title(sec));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
xbps_init(struct xbps_handle *xh)
|
||||
{
|
||||
prop_dictionary_t confd;
|
||||
prop_string_t conffile = NULL, repofile = NULL;
|
||||
const char *conf_rootdir = NULL, *conf_cachedir = NULL;
|
||||
uint16_t fetch_cache_conn = 0, fetch_cache_conn_host = 0;
|
||||
int rv;
|
||||
cfg_opt_t vpkg_opts[] = {
|
||||
CFG_STR_LIST((char *)"targets", NULL, CFGF_NONE),
|
||||
CFG_END()
|
||||
};
|
||||
cfg_opt_t opts[] = {
|
||||
/* Defaults if not set in configuration file */
|
||||
CFG_STR((char *)"rootdir", (char *)"/", CFGF_NONE),
|
||||
CFG_STR((char *)"cachedir", (char *)XBPS_CACHE_PATH, CFGF_NONE),
|
||||
CFG_INT((char *)"fetch-cache-connections",
|
||||
XBPS_FETCH_CACHECONN, CFGF_NONE),
|
||||
CFG_INT((char *)"fetch-cache-connections-per-host",
|
||||
XBPS_FETCH_CACHECONN_HOST, CFGF_NONE),
|
||||
CFG_INT((char *)"fetch-timeout-connection",
|
||||
XBPS_FETCH_TIMEOUT, CFGF_NONE),
|
||||
CFG_BOOL((char *)"syslog", true, CFGF_NONE),
|
||||
CFG_STR_LIST((char *)"repositories", NULL, CFGF_MULTI),
|
||||
CFG_SEC((char *)"virtual-package",
|
||||
vpkg_opts, CFGF_MULTI|CFGF_TITLE),
|
||||
CFG_FUNC((char *)"include", &cfg_include),
|
||||
CFG_END()
|
||||
};
|
||||
int rv, cc, cch;
|
||||
|
||||
assert(xh != NULL);
|
||||
|
||||
xhp = xh;
|
||||
debug = xhp->debug;
|
||||
|
||||
/* If confdir not set, defaults to XBPS_SYSCONF_PATH */
|
||||
if (prop_object_type(xhp->confdir) != PROP_TYPE_STRING) {
|
||||
conffile = prop_string_create_cstring(_CONFFILE);
|
||||
repofile = prop_string_create_cstring(_REPOFILE);
|
||||
} else {
|
||||
conffile = prop_string_copy(xhp->confdir);
|
||||
prop_string_append_cstring(conffile, "/");
|
||||
prop_string_append_cstring(conffile, XBPS_CONF_PLIST);
|
||||
if (xhp->conffile == NULL)
|
||||
xhp->conffile = XBPS_CONF_DEF;
|
||||
|
||||
repofile = prop_string_copy(xhp->confdir);
|
||||
prop_string_append_cstring(repofile, "/");
|
||||
prop_string_append_cstring(repofile, XBPS_CONF_REPOS_PLIST);
|
||||
}
|
||||
/*
|
||||
* Internalize the XBPS_CONF_REPOS_PLIST array.
|
||||
*/
|
||||
xhp->repos_array =
|
||||
prop_array_internalize_from_file(prop_string_cstring_nocopy(repofile));
|
||||
/*
|
||||
* Internalize the XBPS_CONF_PLIST dictionary.
|
||||
*/
|
||||
confd = prop_dictionary_internalize_from_file(
|
||||
prop_string_cstring_nocopy(conffile));
|
||||
if (confd == NULL) {
|
||||
if (errno != ENOENT) {
|
||||
xbps_dbg_printf("%s: cannot internalize conf "
|
||||
"dictionary: %s\n", strerror(errno));
|
||||
xbps_end(xh);
|
||||
return errno;
|
||||
}
|
||||
xbps_dbg_printf("%s: conf_dictionary not internalized.\n",
|
||||
__func__);
|
||||
} else {
|
||||
/*
|
||||
* Get defaults from configuration file.
|
||||
*/
|
||||
prop_dictionary_get_cstring_nocopy(confd,
|
||||
"root-directory", &conf_rootdir);
|
||||
prop_dictionary_get_cstring_nocopy(confd,
|
||||
"cache-directory", &conf_cachedir);
|
||||
prop_dictionary_get_uint16(confd,
|
||||
"fetch-cache-connections", &fetch_cache_conn);
|
||||
prop_dictionary_get_uint16(confd,
|
||||
"fetch-cache-connections-per-host", &fetch_cache_conn_host);
|
||||
prop_dictionary_get_uint16(confd,
|
||||
"fetch-timeout-connection", &xhp->fetch_timeout);
|
||||
}
|
||||
/* parse configuration file */
|
||||
xhp->cfg = cfg_init(opts, CFGF_NOCASE);
|
||||
cfg_set_validate_func(xhp->cfg, "virtual-package", &cb_validate_virtual);
|
||||
|
||||
/*
|
||||
* Client supplied values in xbps_handle will be choosen over the
|
||||
* same values in configuration file. If not specified, use defaults.
|
||||
*/
|
||||
if (prop_object_type(xhp->rootdir) != PROP_TYPE_STRING) {
|
||||
if (conf_rootdir != NULL)
|
||||
xhp->rootdir = prop_string_create_cstring(conf_rootdir);
|
||||
else {
|
||||
/* If rootdir not set, defaults to '/' */
|
||||
xhp->rootdir = prop_string_create_cstring("/");
|
||||
}
|
||||
}
|
||||
if (prop_object_type(xhp->cachedir) != PROP_TYPE_STRING) {
|
||||
if (conf_cachedir != NULL) {
|
||||
if (conf_cachedir[0] == '/') {
|
||||
/* full path */
|
||||
xhp->cachedir =
|
||||
prop_string_create_cstring(conf_cachedir);
|
||||
} else {
|
||||
/* relative to rootdir */
|
||||
xhp->cachedir = prop_string_copy(xhp->rootdir);
|
||||
prop_string_append_cstring(
|
||||
xhp->cachedir, "/");
|
||||
prop_string_append_cstring(
|
||||
xhp->cachedir, conf_cachedir);
|
||||
if ((rv = cfg_parse(xhp->cfg, xhp->conffile)) != CFG_SUCCESS) {
|
||||
if (rv == CFG_PARSE_ERROR) {
|
||||
if (errno != ENOENT) {
|
||||
/*
|
||||
* Don't error out if config file not found.
|
||||
* We'll use defaults without any repo or
|
||||
* virtual packages.
|
||||
*/
|
||||
xbps_end(xh);
|
||||
return rv;
|
||||
}
|
||||
} else {
|
||||
/* If cachedir not set, defaults to XBPS_CACHE_PATH */
|
||||
xhp->cachedir =
|
||||
prop_string_create_cstring(XBPS_CACHE_PATH);
|
||||
errno = 0;
|
||||
} else if (rv == CFG_PARSE_ERROR) {
|
||||
/*
|
||||
* Parser error from configuration file.
|
||||
*/
|
||||
xbps_end(xh);
|
||||
return ENOTSUP;
|
||||
}
|
||||
}
|
||||
if (fetch_cache_conn == 0)
|
||||
fetch_cache_conn = XBPS_FETCH_CACHECONN;
|
||||
if (fetch_cache_conn_host == 0)
|
||||
fetch_cache_conn_host = XBPS_FETCH_CACHECONN_HOST;
|
||||
|
||||
xbps_fetch_set_cache_connection(fetch_cache_conn,
|
||||
fetch_cache_conn_host);
|
||||
|
||||
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(conffile));
|
||||
xbps_dbg_printf("repofile: %s\n",
|
||||
prop_string_cstring_nocopy(repofile));
|
||||
xbps_dbg_printf("fetch_cache_conn: %zu\n",
|
||||
fetch_cache_conn);
|
||||
xbps_dbg_printf("fetch_cache_conn_host: %zu\n",
|
||||
fetch_cache_conn_host);
|
||||
xbps_dbg_printf("fetch_timeout: %zu\n",
|
||||
xhp->fetch_timeout);
|
||||
|
||||
prop_dictionary_get_bool(confd, "syslog-enabled", &xhp->syslog_enabled);
|
||||
xbps_dbg_printf("syslog logging: %d\n", xhp->syslog_enabled);
|
||||
/*
|
||||
* Respect client setting in struct xbps_handle for {root,cache}dir;
|
||||
* otherwise use values from configuration file or defaults if unset.
|
||||
*/
|
||||
if (xhp->rootdir == NULL) {
|
||||
if (xhp->cfg == NULL)
|
||||
xhp->rootdir = "/";
|
||||
else
|
||||
xhp->rootdir = cfg_getstr(xhp->cfg, "rootdir");
|
||||
}
|
||||
if (xhp->cachedir == NULL) {
|
||||
if (xhp->cfg == NULL)
|
||||
xhp->cachedir = XBPS_CACHE_PATH;
|
||||
else
|
||||
xhp->cachedir = cfg_getstr(xhp->cfg, "cachedir");
|
||||
}
|
||||
if (xhp->cfg == NULL) {
|
||||
xhp->syslog_enabled = true;
|
||||
xhp->fetch_timeout = XBPS_FETCH_TIMEOUT;
|
||||
cc = XBPS_FETCH_CACHECONN;
|
||||
cch = XBPS_FETCH_CACHECONN_HOST;
|
||||
} else {
|
||||
xhp->syslog_enabled = cfg_getbool(xhp->cfg, "syslog");
|
||||
xhp->fetch_timeout = cfg_getint(xhp->cfg, "fetch-timeout-connection");
|
||||
cc = cfg_getint(xhp->cfg, "fetch-cache-connections");
|
||||
cch = cfg_getint(xhp->cfg, "fetch-cache-connections-per-host");
|
||||
}
|
||||
xbps_fetch_set_cache_connection(cc, cch);
|
||||
|
||||
xbps_dbg_printf("rootdir=%s\n", xhp->rootdir);
|
||||
xbps_dbg_printf("cachedir=%s\n", xhp->cachedir);
|
||||
xbps_dbg_printf("fetch-timeout=%u\n", xhp->fetch_timeout);
|
||||
xbps_dbg_printf("fetch-cacheconn=%u\n", cc);
|
||||
xbps_dbg_printf("fetch-cacheconn-host=%u\n", cch);
|
||||
xbps_dbg_printf("syslog=%u\n", xhp->syslog_enabled);
|
||||
/*
|
||||
* Initialize regpkgdb dictionary.
|
||||
*/
|
||||
@@ -173,18 +159,9 @@ xbps_init(struct xbps_handle *xh)
|
||||
xbps_dbg_printf("%s: couldn't initialize "
|
||||
"regpkgdb: %s\n", strerror(rv));
|
||||
xbps_end(xh);
|
||||
return rv;
|
||||
return EINVAL;
|
||||
}
|
||||
}
|
||||
if (prop_object_type(confd) == PROP_TYPE_DICTIONARY)
|
||||
prop_object_release(confd);
|
||||
if (prop_object_type(conffile) == PROP_TYPE_STRING)
|
||||
prop_object_release(conffile);
|
||||
if (prop_object_type(repofile) == PROP_TYPE_STRING)
|
||||
prop_object_release(repofile);
|
||||
|
||||
/* Initialize virtual package settings */
|
||||
xbps_init_virtual_pkgs(xhp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -198,14 +175,8 @@ xbps_end(struct xbps_handle *xh)
|
||||
|
||||
if (xh == NULL)
|
||||
return;
|
||||
if (prop_object_type(xh->confdir) == PROP_TYPE_STRING)
|
||||
prop_object_release(xh->confdir);
|
||||
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 (prop_object_type(xh->virtualpkgs_array) == PROP_TYPE_ARRAY)
|
||||
prop_object_release(xh->virtualpkgs_array);
|
||||
if (xh->cfg != NULL)
|
||||
cfg_free(xh->cfg);
|
||||
|
||||
free(xh);
|
||||
xh = NULL;
|
||||
|
||||
@@ -128,12 +128,11 @@ xbps_configure_pkg(const char *pkgname,
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
if (chdir(prop_string_cstring_nocopy(xhp->rootdir)) == -1) {
|
||||
if (chdir(xhp->rootdir) == -1) {
|
||||
xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, errno,
|
||||
pkgname, lver,
|
||||
"%s: [configure] failed to chdir to rootdir `%s': %s",
|
||||
pkgver, prop_string_cstring_nocopy(xhp->rootdir),
|
||||
strerror(errno));
|
||||
pkgver, xhp->rootdir, strerror(errno));
|
||||
free(buf);
|
||||
free(pkgver);
|
||||
return EINVAL;
|
||||
|
||||
@@ -188,16 +188,15 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
|
||||
/*
|
||||
* Execute the purge action in REMOVE script (if found).
|
||||
*/
|
||||
if (chdir(prop_string_cstring_nocopy(xhp->rootdir)) == -1) {
|
||||
if (chdir(xhp->rootdir) == -1) {
|
||||
rv = errno;
|
||||
xbps_set_cb_state(XBPS_STATE_PURGE_FAIL,
|
||||
rv, pkgname, version,
|
||||
"%s: [purge] failed to chdir to rootdir `%s': %s",
|
||||
pkgver, prop_string_cstring_nocopy(xhp->rootdir),
|
||||
strerror(rv));
|
||||
pkgver, xhp->rootdir, strerror(rv));
|
||||
return rv;
|
||||
}
|
||||
buf = xbps_xasprintf(".%s/metadata/%s/REMOVE", XBPS_META_PATH, pkgname);
|
||||
buf = xbps_xasprintf("%s/metadata/%s/REMOVE", XBPS_META_PATH, pkgname);
|
||||
if (buf == NULL) {
|
||||
rv = ENOMEM;
|
||||
return rv;
|
||||
@@ -221,7 +220,7 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
|
||||
* Remove metadata dir and unregister package.
|
||||
*/
|
||||
if ((rv = remove_pkg_metadata(pkgname, version, pkgver,
|
||||
prop_string_cstring_nocopy(xhp->rootdir))) != 0) {
|
||||
xhp->rootdir)) != 0) {
|
||||
xbps_set_cb_state(XBPS_STATE_PURGE_FAIL,
|
||||
rv, pkgname, version,
|
||||
"%s: [purge] failed to remove metadata files: %s",
|
||||
|
||||
@@ -53,8 +53,7 @@ xbps_register_pkg(prop_dictionary_t pkgrd)
|
||||
assert(prop_object_type(pkgrd) == PROP_TYPE_DICTIONARY);
|
||||
|
||||
xhp = xbps_handle_get();
|
||||
plist = xbps_xasprintf("%s/%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->rootdir),
|
||||
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
|
||||
XBPS_META_PATH, XBPS_REGPKGDB);
|
||||
if (plist == NULL)
|
||||
return ENOMEM;
|
||||
@@ -172,8 +171,7 @@ xbps_unregister_pkg(const char *pkgname, const char *version)
|
||||
xbps_set_cb_state(XBPS_STATE_UNREGISTER, 0, pkgname, version, NULL);
|
||||
|
||||
xhp = xbps_handle_get();
|
||||
plist = xbps_xasprintf("%s/%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->rootdir),
|
||||
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
|
||||
XBPS_META_PATH, XBPS_REGPKGDB);
|
||||
if (plist == NULL) {
|
||||
rv = ENOMEM;
|
||||
|
||||
@@ -110,8 +110,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
||||
path = xbps_xasprintf("%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->rootdir), file);
|
||||
path = xbps_xasprintf("%s/%s", xhp->rootdir, file);
|
||||
if (path == NULL) {
|
||||
rv = ENOMEM;
|
||||
break;
|
||||
@@ -224,13 +223,12 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update)
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (chdir(prop_string_cstring_nocopy(xhp->rootdir)) == -1) {
|
||||
if (chdir(xhp->rootdir) == -1) {
|
||||
rv = errno;
|
||||
xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL,
|
||||
rv, pkgname, version,
|
||||
"%s: [remove] failed to chdir to rootdir `%s': %s",
|
||||
pkgver, prop_string_cstring_nocopy(xhp->rootdir),
|
||||
strerror(rv));
|
||||
pkgver, xhp->rootdir, strerror(rv));
|
||||
free(buf);
|
||||
free(pkgver);
|
||||
return rv;
|
||||
|
||||
@@ -109,8 +109,7 @@ xbps_requiredby_pkg_remove(const char *pkgname)
|
||||
assert(pkgname != NULL);
|
||||
|
||||
xhp = xbps_handle_get();
|
||||
plist = xbps_xasprintf("%s/%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->rootdir),
|
||||
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
|
||||
XBPS_META_PATH, XBPS_REGPKGDB);
|
||||
if (plist == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
@@ -179,8 +179,7 @@ xbps_set_pkg_state_installed(const char *pkgname,
|
||||
assert(pkgname != NULL);
|
||||
xhp = xbps_handle_get();
|
||||
|
||||
metadir = xbps_xasprintf("%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->rootdir), XBPS_META_PATH);
|
||||
metadir = xbps_xasprintf("%s/%s", xhp->rootdir, XBPS_META_PATH);
|
||||
if (metadir == NULL)
|
||||
return ENOMEM;
|
||||
plist = xbps_xasprintf("%s/%s", metadir, XBPS_REGPKGDB);
|
||||
|
||||
@@ -96,7 +96,7 @@ extract_metafile(struct archive *ar,
|
||||
return ENOMEM;
|
||||
version = xbps_pkg_version(pkgver);
|
||||
|
||||
buf = xbps_xasprintf(".%s/metadata/%s/%s",
|
||||
buf = xbps_xasprintf("%s/metadata/%s/%s",
|
||||
XBPS_META_PATH, pkgname, file);
|
||||
if (buf == NULL) {
|
||||
free(pkgname);
|
||||
@@ -133,7 +133,7 @@ remove_metafile(const char *file, const char *pkgver)
|
||||
return ENOMEM;
|
||||
version = xbps_pkg_version(pkgver);
|
||||
|
||||
buf = xbps_xasprintf(".%s/metadata/%s/%s",
|
||||
buf = xbps_xasprintf("%s/metadata/%s/%s",
|
||||
XBPS_META_PATH, pkgname, file);
|
||||
if (buf == NULL) {
|
||||
free(pkgname);
|
||||
@@ -193,12 +193,11 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
|
||||
xucd->entry_total_count = 0;
|
||||
}
|
||||
|
||||
if (chdir(prop_string_cstring_nocopy(xhp->rootdir)) == -1) {
|
||||
if (chdir(xhp->rootdir) == -1) {
|
||||
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
|
||||
errno, pkgname, version,
|
||||
"%s: [unpack] failed to chdir to rootdir `%s': %s",
|
||||
pkgver, prop_string_cstring_nocopy(xhp->rootdir),
|
||||
strerror(errno));
|
||||
pkgver, xhp->rootdir, strerror(errno));
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
@@ -245,7 +244,7 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
|
||||
* Extract the INSTALL script first to execute
|
||||
* the pre install target.
|
||||
*/
|
||||
buf = xbps_xasprintf(".%s/metadata/%s/INSTALL",
|
||||
buf = xbps_xasprintf("%s/metadata/%s/INSTALL",
|
||||
XBPS_META_PATH, pkgname);
|
||||
if (buf == NULL) {
|
||||
rv = ENOMEM;
|
||||
@@ -469,7 +468,7 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
|
||||
* On pkgs that set the preserve keyword or while installing
|
||||
* new packages, do not check for obsolete files.
|
||||
*/
|
||||
pkgfilesd = xbps_xasprintf(".%s/metadata/%s/%s",
|
||||
pkgfilesd = xbps_xasprintf("%s/metadata/%s/%s",
|
||||
XBPS_META_PATH, pkgname, XBPS_PKGFILES);
|
||||
if (pkgfilesd == NULL) {
|
||||
rv = ENOMEM;
|
||||
@@ -484,12 +483,11 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
|
||||
if (prop_object_type(old_filesd) == PROP_TYPE_DICTIONARY) {
|
||||
rv = xbps_remove_obsoletes(pkgname, version,
|
||||
pkgver, old_filesd, filesd);
|
||||
prop_object_release(old_filesd);
|
||||
if (rv != 0) {
|
||||
prop_object_release(old_filesd);
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
prop_object_release(old_filesd);
|
||||
} else if (errno && errno != ENOENT) {
|
||||
rv = errno;
|
||||
goto out;
|
||||
@@ -498,7 +496,7 @@ out1:
|
||||
/*
|
||||
* Create pkg metadata directory.
|
||||
*/
|
||||
buf = xbps_xasprintf(".%s/metadata/%s", XBPS_META_PATH, pkgname);
|
||||
buf = xbps_xasprintf("%s/metadata/%s", XBPS_META_PATH, pkgname);
|
||||
if (buf == NULL) {
|
||||
rv = ENOMEM;
|
||||
goto out;
|
||||
|
||||
@@ -224,8 +224,7 @@ xbps_dictionary_from_metadata_plist(const char *pkgname,
|
||||
xhp = xbps_handle_get();
|
||||
|
||||
savedpkgname = pkgname;
|
||||
plistf = xbps_xasprintf("%s/%s/metadata/%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->rootdir),
|
||||
plistf = xbps_xasprintf("%s/%s/metadata/%s/%s", xhp->rootdir,
|
||||
XBPS_META_PATH, savedpkgname, plist);
|
||||
if (plistf == NULL)
|
||||
return NULL;
|
||||
@@ -237,7 +236,7 @@ xbps_dictionary_from_metadata_plist(const char *pkgname,
|
||||
prop_dictionary_get_cstring_nocopy(pkgd,
|
||||
"pkgname", &savedpkgname);
|
||||
plistf = xbps_xasprintf("%s/%s/metadata/%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->rootdir),
|
||||
xhp->rootdir,
|
||||
XBPS_META_PATH, savedpkgname, plist);
|
||||
prop_object_release(pkgd);
|
||||
if (plistf == NULL)
|
||||
|
||||
@@ -121,48 +121,45 @@ static const char *
|
||||
find_virtualpkg_user_in_conf(const char *vpkg, bool bypattern)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
prop_object_iterator_t iter;
|
||||
prop_object_t obj;
|
||||
const char *vpkgver, *pkg = NULL;
|
||||
char *vpkgname = NULL;
|
||||
size_t i, j, cnt;
|
||||
|
||||
xhp = xbps_handle_get();
|
||||
if (prop_object_type(xhp->virtualpkgs_array) != PROP_TYPE_ARRAY) {
|
||||
xbps_dbg_printf("%s: invalid virtualpkgs_array "
|
||||
"type\n", __func__);
|
||||
if (xhp->cfg == NULL)
|
||||
return NULL;
|
||||
|
||||
if ((cnt = cfg_size(xhp->cfg, "virtual-package")) == 0) {
|
||||
/* no virtual packages configured */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((iter = prop_array_iterator(xhp->virtualpkgs_array)) == NULL)
|
||||
return NULL;
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"virtual-pkgver", &vpkgver))
|
||||
continue;
|
||||
|
||||
if (bypattern) {
|
||||
if (xbps_pkgpattern_match(vpkgver, vpkg)) {
|
||||
prop_dictionary_get_cstring_nocopy(obj,
|
||||
"target-pkgpattern", &pkg);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < cnt; i++) {
|
||||
cfg_t *sec = cfg_getnsec(xhp->cfg, "virtual-package", i);
|
||||
for (j = 0; j < cfg_size(sec, "targets"); j++) {
|
||||
vpkgver = cfg_getnstr(sec, "targets", j);
|
||||
vpkgname = xbps_pkg_name(vpkgver);
|
||||
if (vpkgname == NULL)
|
||||
break;
|
||||
|
||||
if (strcmp(vpkg, vpkgname) == 0) {
|
||||
free(vpkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj,
|
||||
"target-pkgpattern", &pkg);
|
||||
break;
|
||||
if (bypattern) {
|
||||
if (!xbps_pkgpattern_match(vpkgver, vpkg)) {
|
||||
free(vpkgname);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (strcmp(vpkg, vpkgname)) {
|
||||
free(vpkgname);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/* virtual package matched in conffile */
|
||||
pkg = cfg_title(sec);
|
||||
xbps_dbg_printf("matched vpkg in conf `%s' for %s\n",
|
||||
pkg, vpkg);
|
||||
free(vpkgname);
|
||||
break;
|
||||
}
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
|
||||
return pkg;
|
||||
}
|
||||
|
||||
@@ -171,31 +168,16 @@ find_virtualpkg_user_in_array(prop_array_t array,
|
||||
const char *str,
|
||||
bool bypattern)
|
||||
{
|
||||
prop_object_t obj = NULL;
|
||||
prop_object_iterator_t iter;
|
||||
const char *virtualpkg;
|
||||
const char *vpkgname;
|
||||
|
||||
assert(prop_object_type(array) == PROP_TYPE_ARRAY);
|
||||
assert(str != NULL);
|
||||
|
||||
virtualpkg = find_virtualpkg_user_in_conf(str, bypattern);
|
||||
if (virtualpkg == NULL)
|
||||
vpkgname = find_virtualpkg_user_in_conf(str, bypattern);
|
||||
if (vpkgname == NULL)
|
||||
return NULL;
|
||||
|
||||
iter = prop_array_iterator(array);
|
||||
if (iter == NULL)
|
||||
return NULL;
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
/*
|
||||
* force pattern match because virtualpkg is
|
||||
* always a pkgpattern.
|
||||
*/
|
||||
if (xbps_match_virtual_pkg_in_dict(obj, virtualpkg, true))
|
||||
break;
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
return obj;
|
||||
return find_pkg_in_array(array, vpkgname, false, false);
|
||||
}
|
||||
|
||||
static prop_dictionary_t
|
||||
|
||||
@@ -66,8 +66,7 @@ xbps_regpkgdb_dictionary_init(struct xbps_handle *xhp)
|
||||
if (regpkgdb_initialized)
|
||||
return 0;
|
||||
|
||||
plist = xbps_xasprintf("%s/%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->rootdir),
|
||||
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
|
||||
XBPS_META_PATH, XBPS_REGPKGDB);
|
||||
if (plist == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
@@ -74,10 +74,8 @@ check_repo_arch(const char *uri)
|
||||
}
|
||||
|
||||
int HIDDEN
|
||||
xbps_repository_pool_init(void)
|
||||
xbps_repository_pool_init(const struct xbps_handle *xhp)
|
||||
{
|
||||
prop_string_t obj;
|
||||
struct xbps_handle *xhp;
|
||||
struct repository_pool *rpool;
|
||||
size_t i, ntotal = 0, nmissing = 0, repocnt = 0;
|
||||
const char *repouri;
|
||||
@@ -87,17 +85,11 @@ xbps_repository_pool_init(void)
|
||||
|
||||
if (repolist_initialized)
|
||||
return 0;
|
||||
|
||||
xhp = xbps_handle_get();
|
||||
if (prop_object_type(xhp->repos_array) != PROP_TYPE_ARRAY)
|
||||
else if (xhp->cfg == NULL)
|
||||
return ENOTSUP;
|
||||
|
||||
if (prop_array_count(xhp->repos_array) == 0)
|
||||
return ENOTSUP;
|
||||
|
||||
for (i = 0; i < prop_array_count(xhp->repos_array); i++) {
|
||||
obj = prop_array_get(xhp->repos_array, i);
|
||||
repouri = prop_string_cstring_nocopy(obj);
|
||||
for (i = 0; i < cfg_size(xhp->cfg, "repositories"); i++) {
|
||||
repouri = cfg_getnstr(xhp->cfg, "repositories", i);
|
||||
/*
|
||||
* Check that we do not register duplicate repositories.
|
||||
*/
|
||||
@@ -156,19 +148,11 @@ xbps_repository_pool_init(void)
|
||||
goto out;
|
||||
}
|
||||
|
||||
rpool->rpi->rpi_uri = prop_string_cstring(obj);
|
||||
if (rpool->rpi->rpi_uri == NULL) {
|
||||
rv = errno;
|
||||
free(rpool->rpi);
|
||||
free(rpool);
|
||||
free(plist);
|
||||
goto out;
|
||||
}
|
||||
rpool->rpi->rpi_uri = repouri;
|
||||
rpool->rpi->rpi_repod =
|
||||
prop_dictionary_internalize_from_zfile(plist);
|
||||
if (rpool->rpi->rpi_repod == NULL) {
|
||||
rv = errno;
|
||||
free(rpool->rpi->rpi_uri);
|
||||
free(rpool->rpi);
|
||||
free(rpool);
|
||||
free(plist);
|
||||
@@ -190,7 +174,6 @@ xbps_repository_pool_init(void)
|
||||
}
|
||||
|
||||
repolist_initialized = true;
|
||||
prop_object_release(xhp->repos_array);
|
||||
xbps_dbg_printf("[rpool] initialized ok.\n");
|
||||
out:
|
||||
if (rv != 0)
|
||||
@@ -213,7 +196,6 @@ xbps_repository_pool_release(void)
|
||||
xbps_dbg_printf("[rpool] unregistered repository '%s'\n",
|
||||
rpool->rpi->rpi_uri);
|
||||
prop_object_release(rpool->rpi->rpi_repod);
|
||||
free(rpool->rpi->rpi_uri);
|
||||
free(rpool->rpi);
|
||||
free(rpool);
|
||||
rpool = NULL;
|
||||
@@ -223,22 +205,17 @@ xbps_repository_pool_release(void)
|
||||
}
|
||||
|
||||
int
|
||||
xbps_repository_pool_sync(void)
|
||||
xbps_repository_pool_sync(const struct xbps_handle *xhp)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
const char *repouri;
|
||||
size_t i;
|
||||
int rv;
|
||||
|
||||
xhp = xbps_handle_get();
|
||||
if (xhp->repos_array == NULL)
|
||||
if (xhp->cfg == NULL)
|
||||
return ENOTSUP;
|
||||
|
||||
if (prop_array_count(xhp->repos_array) == 0)
|
||||
return ENOTSUP;
|
||||
|
||||
for (i = 0; i < prop_array_count(xhp->repos_array); i++) {
|
||||
prop_array_get_cstring_nocopy(xhp->repos_array, i, &repouri);
|
||||
for (i = 0; i < cfg_size(xhp->cfg, "repositories"); i++) {
|
||||
repouri = cfg_getnstr(xhp->cfg, "repositories", i);
|
||||
/*
|
||||
* Check if repository doesn't match our architecture.
|
||||
*/
|
||||
@@ -266,6 +243,7 @@ xbps_repository_pool_foreach(
|
||||
int (*fn)(struct repository_pool_index *, void *, bool *),
|
||||
void *arg)
|
||||
{
|
||||
const struct xbps_handle *xhp = xbps_handle_get();
|
||||
struct repository_pool *rpool, *rpool_new;
|
||||
int rv = 0;
|
||||
bool done = false;
|
||||
@@ -274,7 +252,7 @@ xbps_repository_pool_foreach(
|
||||
/*
|
||||
* Initialize repository pool.
|
||||
*/
|
||||
if ((rv = xbps_repository_pool_init()) != 0) {
|
||||
if ((rv = xbps_repository_pool_init(xhp)) != 0) {
|
||||
if (rv == ENOTSUP) {
|
||||
xbps_dbg_printf("[rpool] empty repository list.\n");
|
||||
} else if (rv != ENOENT && rv != ENOTSUP) {
|
||||
|
||||
@@ -117,8 +117,7 @@ xbps_repository_sync_pkg_index(const char *uri)
|
||||
/*
|
||||
* Create metadir if necessary.
|
||||
*/
|
||||
metadir = xbps_xasprintf("%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->rootdir), XBPS_META_PATH);
|
||||
metadir = xbps_xasprintf("%s/%s", xhp->rootdir, XBPS_META_PATH);
|
||||
if (metadir == NULL) {
|
||||
rv = -1;
|
||||
goto out;
|
||||
@@ -151,7 +150,7 @@ xbps_repository_sync_pkg_index(const char *uri)
|
||||
* Full path to repository directory to store the index.plist file.
|
||||
*/
|
||||
lrepodir = xbps_xasprintf("%s/%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->rootdir), XBPS_META_PATH, uri_fixedp);
|
||||
xhp->rootdir, XBPS_META_PATH, uri_fixedp);
|
||||
if (lrepodir == NULL) {
|
||||
rv = -1;
|
||||
goto out;
|
||||
|
||||
@@ -124,13 +124,11 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
/*
|
||||
* Create cachedir.
|
||||
*/
|
||||
if (xbps_mkpath(prop_string_cstring_nocopy(xhp->cachedir),
|
||||
0755) == -1) {
|
||||
if (xbps_mkpath(xhp->cachedir, 0755) == -1) {
|
||||
xbps_set_cb_state(XBPS_STATE_DOWNLOAD_FAIL,
|
||||
errno, pkgname, version,
|
||||
"%s: [trans] cannot create cachedir `%s': %s",
|
||||
pkgver, prop_string_cstring_nocopy(xhp->cachedir),
|
||||
strerror(errno));
|
||||
pkgver, xhp->cachedir, strerror(errno));
|
||||
free(binfile);
|
||||
rv = errno;
|
||||
break;
|
||||
@@ -142,8 +140,7 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
/*
|
||||
* Fetch binary package.
|
||||
*/
|
||||
rv = xbps_fetch_file(binfile,
|
||||
prop_string_cstring_nocopy(xhp->cachedir), false, NULL);
|
||||
rv = xbps_fetch_file(binfile, xhp->cachedir, false, NULL);
|
||||
if (rv == -1) {
|
||||
xbps_set_cb_state(XBPS_STATE_DOWNLOAD_FAIL,
|
||||
errno, pkgname, version,
|
||||
|
||||
@@ -213,12 +213,12 @@ get_pkg_index_remote_plist(const char *uri)
|
||||
if (uri_fixed == NULL)
|
||||
return NULL;
|
||||
|
||||
if (prop_string_equals_cstring(xhp->rootdir, "/")) {
|
||||
if (strcmp(xhp->rootdir, "/") == 0) {
|
||||
repodir = xbps_xasprintf("%s/%s/%s",
|
||||
XBPS_META_PATH, uri_fixed, XBPS_PKGINDEX);
|
||||
} else {
|
||||
repodir = xbps_xasprintf("%s/%s/%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->rootdir),
|
||||
xhp->rootdir,
|
||||
XBPS_META_PATH, uri_fixed, XBPS_PKGINDEX);
|
||||
}
|
||||
free(uri_fixed);
|
||||
@@ -254,8 +254,7 @@ 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",
|
||||
prop_string_cstring_nocopy(xhp->cachedir), filen);
|
||||
lbinpkg = xbps_xasprintf("%s/%s", xhp->cachedir, filen);
|
||||
if (lbinpkg == NULL)
|
||||
return NULL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user