New configuration scheme changes, round 1.
- Configuration file 'xbps-conf.plist' has been splitted off into two files: conf.plist and repositories.plist. By default they are stored in etc/xbps. - Changed some members in xbps_handle struct, mostly to make it easy to change its value in {cache,root}dir and conffile. - Made xbps_init() release proplib objects as soon as we don't need them, that way it uses 35% less of memory or in some cases even more. There will be another commit that will implement to read new virtualpkg settings by the user, as specified in: http://code.google.com/p/xbps/issues/detail?id=12
This commit is contained in:
@@ -42,9 +42,13 @@
|
||||
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
|
||||
|
||||
int
|
||||
xbps_init(struct xbps_handle *xh)
|
||||
{
|
||||
prop_dictionary_t confd;
|
||||
const char *conf_rootdir = NULL, *conf_cachedir = NULL;
|
||||
uint16_t fetch_cache_conn = 0, fetch_cache_conn_host = 0;
|
||||
int rv;
|
||||
@@ -54,16 +58,19 @@ xbps_init(struct xbps_handle *xh)
|
||||
xhp = xh;
|
||||
debug = xhp->debug;
|
||||
|
||||
/* If conffile not set, defaults to XBPS_CONF_PATH */
|
||||
if (xhp->conffile == NULL)
|
||||
xhp->conffile = XBPS_CONF_PATH "/" XBPS_CONF_PLIST;
|
||||
|
||||
/* If conffile not set, defaults to XBPS_SYSCONF_PATH */
|
||||
if (prop_object_type(xhp->conffile) != PROP_TYPE_STRING)
|
||||
xhp->conffile = prop_string_create_cstring(_CONFFILE);
|
||||
/*
|
||||
* Internalize the XBPS_CONF_REPOS_PLIST array.
|
||||
*/
|
||||
xhp->repos_array = prop_array_internalize_from_file(_REPOFILE);
|
||||
/*
|
||||
* Internalize the XBPS_CONF_PLIST dictionary.
|
||||
*/
|
||||
xhp->conf_dictionary =
|
||||
prop_dictionary_internalize_from_file(xhp->conffile);
|
||||
if (xhp->conf_dictionary == NULL) {
|
||||
confd = prop_dictionary_internalize_from_file(
|
||||
prop_string_cstring_nocopy(xhp->conffile));
|
||||
if (confd == NULL) {
|
||||
if (errno != ENOENT) {
|
||||
xbps_dbg_printf("%s: cannot internalize conf "
|
||||
"dictionary: %s\n", strerror(errno));
|
||||
@@ -76,15 +83,15 @@ xbps_init(struct xbps_handle *xh)
|
||||
/*
|
||||
* Get defaults from configuration file.
|
||||
*/
|
||||
prop_dictionary_get_cstring_nocopy(xhp->conf_dictionary,
|
||||
prop_dictionary_get_cstring_nocopy(confd,
|
||||
"root-directory", &conf_rootdir);
|
||||
prop_dictionary_get_cstring_nocopy(xhp->conf_dictionary,
|
||||
prop_dictionary_get_cstring_nocopy(confd,
|
||||
"cache-directory", &conf_cachedir);
|
||||
prop_dictionary_get_uint16(xhp->conf_dictionary,
|
||||
prop_dictionary_get_uint16(confd,
|
||||
"fetch-cache-connections", &fetch_cache_conn);
|
||||
prop_dictionary_get_uint16(xhp->conf_dictionary,
|
||||
prop_dictionary_get_uint16(confd,
|
||||
"fetch-cache-connections-per-host", &fetch_cache_conn_host);
|
||||
prop_dictionary_get_uint16(xhp->conf_dictionary,
|
||||
prop_dictionary_get_uint16(confd,
|
||||
"fetch-timeout-connection", &xhp->fetch_timeout);
|
||||
}
|
||||
|
||||
@@ -92,33 +99,32 @@ xbps_init(struct xbps_handle *xh)
|
||||
* Client supplied values in xbps_handle will be choosen over the
|
||||
* same values in configuration file. If not specified, use defaults.
|
||||
*/
|
||||
if (xhp->rootdir == NULL) {
|
||||
if (prop_object_type(xhp->rootdir) != PROP_TYPE_STRING) {
|
||||
if (conf_rootdir != NULL)
|
||||
xhp->rootdir = conf_rootdir;
|
||||
xhp->rootdir = prop_string_create_cstring(conf_rootdir);
|
||||
else {
|
||||
/* If rootdir not set, defaults to '/' */
|
||||
xhp->rootdir = "/";
|
||||
xhp->rootdir = prop_string_create_cstring("/");
|
||||
}
|
||||
}
|
||||
if (xhp->cachedir == NULL) {
|
||||
if (prop_object_type(xhp->cachedir) != PROP_TYPE_STRING) {
|
||||
if (conf_cachedir != NULL) {
|
||||
if (conf_cachedir[0] == '/') {
|
||||
/* full path */
|
||||
xhp->cachedir = conf_cachedir;
|
||||
xhp->cachedir =
|
||||
prop_string_create_cstring(conf_cachedir);
|
||||
} else {
|
||||
/* relative to rootdir */
|
||||
xhp->pstring_cachedir =
|
||||
prop_string_create_cstring(xhp->rootdir);
|
||||
xhp->cachedir = prop_string_copy(xhp->rootdir);
|
||||
prop_string_append_cstring(
|
||||
xhp->pstring_cachedir, "/");
|
||||
xhp->cachedir, "/");
|
||||
prop_string_append_cstring(
|
||||
xhp->pstring_cachedir, conf_cachedir);
|
||||
xhp->cachedir = prop_string_cstring_nocopy(
|
||||
xhp->pstring_cachedir);
|
||||
xhp->cachedir, conf_cachedir);
|
||||
}
|
||||
} else {
|
||||
/* If cachedir not set, defaults to XBPS_CACHE_PATH */
|
||||
xhp->cachedir = XBPS_CACHE_PATH;
|
||||
xhp->cachedir =
|
||||
prop_string_create_cstring(XBPS_CACHE_PATH);
|
||||
}
|
||||
}
|
||||
if (fetch_cache_conn == 0)
|
||||
@@ -129,12 +135,16 @@ xbps_init(struct xbps_handle *xh)
|
||||
xbps_fetch_set_cache_connection(fetch_cache_conn,
|
||||
fetch_cache_conn_host);
|
||||
|
||||
xbps_dbg_printf("%s: rootdir: `%s' cachedir: `%s' conf: `%s'\n",
|
||||
__func__, xhp->rootdir, xhp->cachedir, xhp->conffile);
|
||||
xbps_dbg_printf("%s: fetch_cache_conn: %zu fetch_cache_host: %zu\n",
|
||||
__func__, fetch_cache_conn, fetch_cache_conn_host);
|
||||
xbps_dbg_printf("%s: fetch_timeout: %zu\n", __func__,
|
||||
xhp->fetch_timeout);
|
||||
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(xhp->conffile));
|
||||
xbps_dbg_printf("repofile: %s\n", _REPOFILE);
|
||||
xbps_dbg_printf("fetch_cache_conn: %zu\n", fetch_cache_conn);
|
||||
xbps_dbg_printf("fetch_cacche_conn_host: %zu\n", fetch_cache_conn_host);
|
||||
xbps_dbg_printf("fetch_timeout: %zu\n", xhp->fetch_timeout);
|
||||
|
||||
/*
|
||||
* Initialize regpkgdb dictionary.
|
||||
@@ -147,6 +157,12 @@ xbps_init(struct xbps_handle *xh)
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
/* We don't need the confd dictionary internalized anymore */
|
||||
if (prop_object_type(confd) == PROP_TYPE_DICTIONARY)
|
||||
prop_object_release(confd);
|
||||
/* We don't need the conffile string anymore */
|
||||
if (prop_object_type(xh->conffile) == PROP_TYPE_STRING)
|
||||
prop_object_release(xh->conffile);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -157,14 +173,13 @@ xbps_end(struct xbps_handle *xh)
|
||||
xbps_regpkgdb_dictionary_release();
|
||||
xbps_repository_pool_release();
|
||||
xbps_fetch_unset_cache_connection();
|
||||
|
||||
if (xh == NULL)
|
||||
return;
|
||||
|
||||
if (prop_object_type(xh->conf_dictionary) == PROP_TYPE_DICTIONARY)
|
||||
prop_object_release(xh->conf_dictionary);
|
||||
if (prop_object_type(xh->pstring_cachedir) == PROP_TYPE_STRING)
|
||||
prop_object_release(xh->pstring_cachedir);
|
||||
|
||||
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 (xh->xfcd != NULL)
|
||||
free(xh->xfcd);
|
||||
if (xh->xucd != NULL)
|
||||
|
@@ -127,9 +127,10 @@ xbps_configure_pkg(const char *pkgname,
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
if (chdir(xhp->rootdir) == -1) {
|
||||
if (chdir(prop_string_cstring_nocopy(xhp->rootdir)) == -1) {
|
||||
xbps_dbg_printf("%s: [configure] chdir to '%s' returned %s\n",
|
||||
pkgname, xhp->rootdir, strerror(errno));
|
||||
pkgname, prop_string_cstring_nocopy(xhp->rootdir),
|
||||
strerror(errno));
|
||||
free(buf);
|
||||
free(pkgver);
|
||||
return EINVAL;
|
||||
|
@@ -160,7 +160,7 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
|
||||
/*
|
||||
* Execute the purge action in REMOVE script (if found).
|
||||
*/
|
||||
if (chdir(xhp->rootdir) == -1) {
|
||||
if (chdir(prop_string_cstring_nocopy(xhp->rootdir)) == -1) {
|
||||
rv = errno;
|
||||
prop_object_release(dict);
|
||||
xbps_error_printf("[purge] %s: cannot change to rootdir: %s.\n",
|
||||
@@ -194,7 +194,8 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
|
||||
/*
|
||||
* Remove metadata dir and unregister package.
|
||||
*/
|
||||
if ((rv = remove_pkg_metadata(pkgname, xhp->rootdir)) != 0) {
|
||||
if ((rv = remove_pkg_metadata(pkgname,
|
||||
prop_string_cstring_nocopy(xhp->rootdir))) != 0) {
|
||||
xbps_error_printf("%s: couldn't remove metadata files: %s\n",
|
||||
pkgname, strerror(rv));
|
||||
return rv;
|
||||
|
@@ -51,7 +51,8 @@ xbps_register_pkg(prop_dictionary_t pkgrd)
|
||||
bool autoinst = false;
|
||||
|
||||
xhp = xbps_handle_get();
|
||||
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
|
||||
plist = xbps_xasprintf("%s/%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->rootdir),
|
||||
XBPS_META_PATH, XBPS_REGPKGDB);
|
||||
if (plist == NULL)
|
||||
return ENOMEM;
|
||||
@@ -162,7 +163,8 @@ xbps_unregister_pkg(const char *pkgname)
|
||||
assert(pkgname != NULL);
|
||||
|
||||
xhp = xbps_handle_get();
|
||||
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
|
||||
plist = xbps_xasprintf("%s/%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->rootdir),
|
||||
XBPS_META_PATH, XBPS_REGPKGDB);
|
||||
if (plist == NULL)
|
||||
return ENOMEM;
|
||||
|
@@ -106,7 +106,8 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
||||
path = xbps_xasprintf("%s/%s", xhp->rootdir, file);
|
||||
path = xbps_xasprintf("%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->rootdir), file);
|
||||
if (path == NULL) {
|
||||
rv = ENOMEM;
|
||||
break;
|
||||
@@ -194,7 +195,7 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update)
|
||||
if (buf == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
if (chdir(xhp->rootdir) == -1) {
|
||||
if (chdir(prop_string_cstring_nocopy(xhp->rootdir)) == -1) {
|
||||
free(buf);
|
||||
return EINVAL;
|
||||
}
|
||||
|
@@ -110,7 +110,8 @@ xbps_requiredby_pkg_remove(const char *pkgname)
|
||||
assert(pkgname != NULL);
|
||||
|
||||
xhp = xbps_handle_get();
|
||||
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
|
||||
plist = xbps_xasprintf("%s/%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->rootdir),
|
||||
XBPS_META_PATH, XBPS_REGPKGDB);
|
||||
if (plist == NULL)
|
||||
return ENOMEM;
|
||||
|
@@ -175,7 +175,8 @@ xbps_set_pkg_state_installed(const char *pkgname,
|
||||
assert(pkgname != NULL);
|
||||
xhp = xbps_handle_get();
|
||||
|
||||
metadir = xbps_xasprintf("%s/%s", xhp->rootdir, XBPS_META_PATH);
|
||||
metadir = xbps_xasprintf("%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->rootdir), XBPS_META_PATH);
|
||||
if (metadir == NULL)
|
||||
return ENOMEM;
|
||||
plist = xbps_xasprintf("%s/%s", metadir, XBPS_REGPKGDB);
|
||||
|
@@ -172,7 +172,7 @@ unpack_archive(prop_dictionary_t pkg_repod,
|
||||
|
||||
preserve = update = false;
|
||||
|
||||
if (chdir(xhp->rootdir) == -1) {
|
||||
if (chdir(prop_string_cstring_nocopy(xhp->rootdir)) == -1) {
|
||||
xbps_error_printf("cannot chdir to rootdir for "
|
||||
"`%s-%s': %s\n", pkgname, version, strerror(errno));
|
||||
return errno;
|
||||
|
@@ -196,7 +196,8 @@ xbps_dictionary_from_metadata_plist(const char *pkgname,
|
||||
xhp = xbps_handle_get();
|
||||
|
||||
plistf = xbps_xasprintf("%s/%s/metadata/%s/%s",
|
||||
xhp->rootdir, XBPS_META_PATH, pkgname, plist);
|
||||
prop_string_cstring_nocopy(xhp->rootdir),
|
||||
XBPS_META_PATH, pkgname, plist);
|
||||
if (plistf == NULL)
|
||||
return NULL;
|
||||
|
||||
@@ -209,7 +210,8 @@ xbps_dictionary_from_metadata_plist(const char *pkgname,
|
||||
}
|
||||
free(plistf);
|
||||
plistf = xbps_xasprintf("%s/%s/metadata/%s/%s",
|
||||
xhp->rootdir, XBPS_META_PATH, pkgname, plist);
|
||||
prop_string_cstring_nocopy(xhp->rootdir),
|
||||
XBPS_META_PATH, pkgname, plist);
|
||||
if (plistf == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
@@ -127,10 +127,10 @@ find_virtualpkg_user_in_conf(const char *vpkg, bool bypattern)
|
||||
char *vpkgname = NULL;
|
||||
|
||||
xhp = xbps_handle_get();
|
||||
if (xhp->conf_dictionary == NULL)
|
||||
if (xhp->virtualpkg_dictionary == NULL)
|
||||
return NULL;
|
||||
|
||||
if ((iter = xbps_array_iter_from_dict(xhp->conf_dictionary,
|
||||
if ((iter = xbps_array_iter_from_dict(xhp->virtualpkg_dictionary,
|
||||
"virtual-packages")) == NULL)
|
||||
return NULL;
|
||||
|
||||
|
@@ -66,7 +66,8 @@ xbps_regpkgdb_dictionary_init(struct xbps_handle *xhp)
|
||||
if (regpkgdb_initialized)
|
||||
return 0;
|
||||
|
||||
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
|
||||
plist = xbps_xasprintf("%s/%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->rootdir),
|
||||
XBPS_META_PATH, XBPS_REGPKGDB);
|
||||
if (plist == NULL)
|
||||
return ENOMEM;
|
||||
|
@@ -73,7 +73,6 @@ int HIDDEN
|
||||
xbps_repository_pool_init(void)
|
||||
{
|
||||
struct xbps_handle *xhp;
|
||||
prop_array_t array;
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter = NULL;
|
||||
struct repository_pool *rpool;
|
||||
@@ -84,20 +83,16 @@ xbps_repository_pool_init(void)
|
||||
bool duprepo;
|
||||
|
||||
xhp = xbps_handle_get();
|
||||
if (xhp->conf_dictionary == NULL)
|
||||
if (xhp->repos_array == NULL)
|
||||
return ENOTSUP;
|
||||
|
||||
if (repolist_initialized)
|
||||
return 0;
|
||||
|
||||
array = prop_dictionary_get(xhp->conf_dictionary, "repositories");
|
||||
if (array == NULL)
|
||||
return errno;
|
||||
|
||||
if (prop_array_count(array) == 0)
|
||||
if (prop_array_count(xhp->repos_array) == 0)
|
||||
return ENOTSUP;
|
||||
|
||||
iter = prop_array_iterator(array);
|
||||
iter = prop_array_iterator(xhp->repos_array);
|
||||
if (iter == NULL) {
|
||||
rv = errno;
|
||||
goto out;
|
||||
@@ -189,6 +184,7 @@ xbps_repository_pool_init(void)
|
||||
}
|
||||
|
||||
repolist_initialized = true;
|
||||
prop_object_release(xhp->repos_array);
|
||||
xbps_dbg_printf("[rpool] initialized ok.\n");
|
||||
out:
|
||||
if (iter)
|
||||
|
@@ -122,7 +122,8 @@ xbps_repository_sync_pkg_index(const char *uri)
|
||||
/*
|
||||
* Create metadir if necessary.
|
||||
*/
|
||||
metadir = xbps_xasprintf("%s/%s", xhp->rootdir, XBPS_META_PATH);
|
||||
metadir = xbps_xasprintf("%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->rootdir), XBPS_META_PATH);
|
||||
if (metadir == NULL) {
|
||||
rv = -1;
|
||||
goto out;
|
||||
@@ -154,7 +155,7 @@ xbps_repository_sync_pkg_index(const char *uri)
|
||||
* file.
|
||||
*/
|
||||
lrepodir = xbps_xasprintf("%s/%s/%s",
|
||||
xhp->rootdir, XBPS_META_PATH, uri_fixedp);
|
||||
prop_string_cstring_nocopy(xhp->rootdir), XBPS_META_PATH, uri_fixedp);
|
||||
if (lrepodir == NULL) {
|
||||
rv = -1;
|
||||
goto out;
|
||||
|
@@ -137,9 +137,12 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
/*
|
||||
* Create cachedir.
|
||||
*/
|
||||
if (xbps_mkpath(xhp->cachedir, 0755) == -1) {
|
||||
if (xbps_mkpath(prop_string_cstring_nocopy(xhp->cachedir),
|
||||
0755) == -1) {
|
||||
xbps_error_printf("xbps-bin: cannot mkdir cachedir "
|
||||
"`%s': %s.\n", xhp->cachedir, strerror(errno));
|
||||
"`%s': %s.\n",
|
||||
prop_string_cstring_nocopy(xhp->cachedir),
|
||||
strerror(errno));
|
||||
free(binfile);
|
||||
rv = errno;
|
||||
break;
|
||||
@@ -149,7 +152,8 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
/*
|
||||
* Fetch binary package.
|
||||
*/
|
||||
rv = xbps_fetch_file(binfile, xhp->cachedir, false, NULL);
|
||||
rv = xbps_fetch_file(binfile,
|
||||
prop_string_cstring_nocopy(xhp->cachedir), false, NULL);
|
||||
if (rv == -1) {
|
||||
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_DOWNLOAD, pkgver, errno);
|
||||
free(binfile);
|
||||
|
@@ -214,7 +214,8 @@ get_pkg_index_remote_plist(const char *uri)
|
||||
return NULL;
|
||||
|
||||
repodir = xbps_xasprintf("%s/%s/%s/%s",
|
||||
xhp->rootdir, XBPS_META_PATH, uri_fixed, XBPS_PKGINDEX);
|
||||
prop_string_cstring_nocopy(xhp->rootdir),
|
||||
XBPS_META_PATH, uri_fixed, XBPS_PKGINDEX);
|
||||
if (repodir == NULL) {
|
||||
free(uri_fixed);
|
||||
return NULL;
|
||||
@@ -261,7 +262,8 @@ 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", xhp->cachedir, filen);
|
||||
lbinpkg = xbps_xasprintf("%s/%s",
|
||||
prop_string_cstring_nocopy(xhp->cachedir), filen);
|
||||
if (lbinpkg == NULL)
|
||||
return NULL;
|
||||
|
||||
|
Reference in New Issue
Block a user