xbps_handle: remove debug, install_*, syslog_enabled members.

Replaced by definitions that can be set to xbps_handle::flags.
This commit is contained in:
Juan RP 2012-01-22 10:52:35 +01:00
parent c884634a62
commit 791f1d40b2
9 changed files with 70 additions and 69 deletions

View File

@ -64,20 +64,18 @@ main(int argc, char **argv)
struct sigaction sa;
const char *rootdir, *cachedir, *conffile, *option;
int i, c, flags, rv;
bool yes, debug, reqby_force, force_rm_with_deps, recursive_rm;
bool install_auto, install_manual, show_download_pkglist_url;
bool reinstall;
bool yes, reqby_force, force_rm_with_deps, recursive_rm;
bool reinstall, show_download_pkglist_url;
rootdir = cachedir = conffile = option = NULL;
flags = rv = 0;
reqby_force = yes = force_rm_with_deps = false;
recursive_rm = debug = reinstall = false;
install_auto = install_manual = show_download_pkglist_url = false;
recursive_rm = reinstall = show_download_pkglist_url = false;
while ((c = getopt(argc, argv, "AC:c:dDFfMo:Rr:Vvy")) != -1) {
switch (c) {
case 'A':
install_auto = true;
flags |= XBPS_FLAG_INSTALL_AUTO;
break;
case 'C':
conffile = optarg;
@ -86,7 +84,7 @@ main(int argc, char **argv)
cachedir = optarg;
break;
case 'd':
debug = true;
flags |= XBPS_FLAG_DEBUG;
break;
case 'D':
show_download_pkglist_url = true;
@ -100,7 +98,7 @@ main(int argc, char **argv)
flags |= XBPS_FLAG_FORCE_REMOVE_FILES;
break;
case 'M':
install_manual = true;
flags |= XBPS_FLAG_INSTALL_MANUAL;
break;
case 'o':
option = optarg;
@ -134,7 +132,8 @@ main(int argc, char **argv)
usage();
/* Specifying -A and -M is illegal */
if (install_manual && install_auto) {
if ((flags & XBPS_FLAG_INSTALL_AUTO) &&
(flags & XBPS_FLAG_INSTALL_MANUAL)) {
xbps_error_printf("xbps-bin: -A and -M options cannot be "
"used together!\n");
exit(EXIT_FAILURE);
@ -144,7 +143,6 @@ main(int argc, char **argv)
* Initialize libxbps.
*/
memset(&xh, 0, sizeof(xh));
xh.debug = debug;
xh.state_cb = state_cb;
xh.fetch_cb = fetch_file_progress_cb;
xh.fetch_cb_data = &xfer;
@ -152,8 +150,6 @@ main(int argc, char **argv)
xh.cachedir = cachedir;
xh.conffile = conffile;
xh.flags = flags;
xh.install_reason_manual = install_manual;
xh.install_reason_auto = install_auto;
if (flags & XBPS_FLAG_VERBOSE)
xh.unpack_cb = unpack_progress_cb_verbose;
else

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2011 Juan Romero Pardines.
* Copyright (c) 2011-2012 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -36,11 +36,14 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata)
const struct xbps_handle *xhp = xbps_handle_get();
prop_dictionary_t pkgd;
const char *version;
bool syslog_enabled;
(void)cbdata;
if (xhp->syslog_enabled)
if (xhp->flags & XBPS_FLAG_SYSLOG) {
syslog_enabled = true;
openlog("xbps-bin", LOG_CONS, LOG_USER);
}
switch (xscd->state) {
/* notifications */
@ -101,7 +104,7 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata)
case XBPS_STATE_INSTALL_DONE:
printf("Installed `%s-%s' successfully.\n",
xscd->pkgname, xscd->version);
if (xhp->syslog_enabled)
if (syslog_enabled)
syslog(LOG_NOTICE, "Installed `%s-%s' successfully "
"(rootdir: %s).", xscd->pkgname, xscd->version,
xhp->rootdir);
@ -109,7 +112,7 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata)
case XBPS_STATE_UPDATE_DONE:
printf("Updated `%s' to `%s' successfully.\n",
xscd->pkgname, xscd->version);
if (xhp->syslog_enabled)
if (syslog_enabled)
syslog(LOG_NOTICE, "Updated `%s' to `%s' successfully "
"(rootdir: %s).", xscd->pkgname, xscd->version,
xhp->rootdir);
@ -117,7 +120,7 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata)
case XBPS_STATE_REMOVE_DONE:
printf("Removed `%s-%s' successfully.\n",
xscd->pkgname, xscd->version);
if (xhp->syslog_enabled)
if (syslog_enabled)
syslog(LOG_NOTICE, "Removed `%s-%s' successfully "
"(rootdir: %s).", xscd->pkgname, xscd->version,
xhp->rootdir);
@ -134,7 +137,7 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata)
case XBPS_STATE_REPOSYNC_FAIL:
case XBPS_STATE_CONFIG_FILE_FAIL:
xbps_error_printf("%s\n", xscd->desc);
if (xhp->syslog_enabled)
if (syslog_enabled)
syslog(LOG_ERR, "%s", xscd->desc);
break;
case XBPS_STATE_REMOVE_FILE_FAIL:
@ -145,7 +148,7 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata)
return;
xbps_error_printf("%s\n", xscd->desc);
if (xhp->syslog_enabled)
if (syslog_enabled)
syslog(LOG_ERR, "%s", xscd->desc);
break;
default:

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2009-2011 Juan Romero Pardines.
* Copyright (c) 2009-2012 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -56,8 +56,7 @@ main(int argc, char **argv)
struct repo_search_data *rsd = NULL;
prop_dictionary_t pkgd;
const char *rootdir, *cachedir, *conffile, *option;
int c, rv = 0;
bool debug = false;
int flags = 0, c, rv = 0;
rootdir = cachedir = conffile = option = NULL;
@ -70,7 +69,7 @@ main(int argc, char **argv)
cachedir = optarg;
break;
case 'd':
debug = true;
flags |= XBPS_FLAG_DEBUG;
break;
case 'o':
option = optarg;
@ -98,7 +97,7 @@ main(int argc, char **argv)
* Initialize XBPS subsystems.
*/
memset(&xh, 0, sizeof(xh));
xh.debug = debug;
xh.flags = flags;
xh.state_cb = state_cb;
xh.fetch_cb = fetch_file_progress_cb;
xh.fetch_cb_data = &xfer;

View File

@ -118,8 +118,8 @@ main(int argc, char **argv)
struct xferstat xfer;
const char *pkgn, *version, *rootdir = NULL, *confdir = NULL;
char *plist, *pkgname, *pkgver, *in_chroot_env, *hash;
bool debug = false, in_chroot = false;
int i, c, rv = 0;
bool in_chroot = false;
int flags = 0, i, c, rv = 0;
while ((c = getopt(argc, argv, "C:dr:V")) != -1) {
switch (c) {
@ -131,7 +131,7 @@ main(int argc, char **argv)
rootdir = optarg;
break;
case 'd':
debug = true;
flags |= XBPS_FLAG_DEBUG;
break;
case 'V':
printf("%s\n", XBPS_RELVER);
@ -157,7 +157,7 @@ main(int argc, char **argv)
* Initialize libxbps.
*/
memset(&xh, 0, sizeof(xh));
xh.debug = debug;
xh.flags = flags;
xh.fetch_cb = fetch_file_progress_cb;
xh.fetch_cb_data = &xfer;
xh.rootdir = rootdir;

View File

@ -56,7 +56,7 @@
*/
#define XBPS_PKGINDEX_VERSION "1.4"
#define XBPS_API_VERSION "20120122"
#define XBPS_API_VERSION "20120122-1"
#define XBPS_VERSION "0.12"
/**
@ -147,6 +147,33 @@
*/
#define XBPS_FLAG_FORCE_REMOVE_FILES 0x00000004
/**
* @def XBPS_FLAG_SYSLOG
* Enable syslog logging flag. To make clients aware that syslog
* will be used.
*/
#define XBPS_FLAG_SYSLOG 0x00000008
/**
* @def XBPS_FLAG_INSTALL_AUTO
* Enabled automatic install mode for a package and all dependencies
* installed direct and indirectly.
*/
#define XBPS_FLAG_INSTALL_AUTO 0x00000010
/**
* @def XBPS_FLAG_INSTALL_MANUAL
* Enabled manual install mode for a package and all dependencies
* installed direct and indirectly.
*/
#define XBPS_FLAG_INSTALL_MANUAL 0x00000020
/**
* @def XBPS_FLAG_DEBUG
* Enable debug mode to output debugging printfs to stdout/stderr.
*/
#define XBPS_FLAG_DEBUG 0x00000040
/**
* @def XBPS_FETCH_CACHECONN
* Default (global) limit of cached connections used in libfetch.
@ -527,37 +554,6 @@ struct xbps_handle {
* - XBPS_FLAG_FORCE
*/
int flags;
/**
* @var debug
*
* Set to true to enable debugging messages to stderr.
*/
bool debug;
/**
* @var install_reason_auto
*
* Set to true to make installed or updated target package
* (and its dependencies) marked with automatic installation,
* thus it will be found as orphan if no packages are depending
* on it.
*/
bool install_reason_auto;
/**
* @var install_reason_manual
*
* Set to true to make installed or updated target package
* (and its dependencies) marked with manual installation, thus
* it will never will be found as orphan.
*/
bool install_reason_manual;
/**
* @var syslog_enabled
*
* Set to true to make the client aware that some operations
* shall be sent to the syslog daemon if the option has been
* enabled in configuration file.
*/
bool syslog_enabled;
};
/**

View File

@ -40,6 +40,7 @@
* using libxbps and finalize usage to release resources at the end.
*/
static bool debug;
static bool syslog_enabled;
static bool xbps_initialized;
static struct xbps_handle *xhp;
@ -109,7 +110,8 @@ xbps_init(struct xbps_handle *xh)
assert(xh != NULL);
xhp = xh;
debug = xhp->debug;
if (xhp->flags & XBPS_FLAG_DEBUG)
debug = true;
if (xhp->conffile == NULL)
xhp->conffile = XBPS_CONF_DEF;
@ -161,19 +163,24 @@ xbps_init(struct xbps_handle *xh)
xhp->cachedir = xhp->cachedir_priv;
if (xhp->cfg == NULL) {
xhp->syslog_enabled = true;
xhp->flags |= XBPS_FLAG_SYSLOG;
xhp->fetch_timeout = XBPS_FETCH_TIMEOUT;
xhp->transaction_frequency_flush = XBPS_TRANS_FLUSH;
cc = XBPS_FETCH_CACHECONN;
cch = XBPS_FETCH_CACHECONN_HOST;
} else {
xhp->syslog_enabled = cfg_getbool(xhp->cfg, "syslog");
syslog_enabled = cfg_getbool(xhp->cfg, "syslog");
if (syslog_enabled)
xhp->flags |= XBPS_FLAG_SYSLOG;
xhp->fetch_timeout = cfg_getint(xhp->cfg, "FetchTimeoutConnection");
cc = cfg_getint(xhp->cfg, "FetchCacheConnections");
cch = cfg_getint(xhp->cfg, "FetchCacheConnectionsPerHost");
xhp->transaction_frequency_flush =
cfg_getint(xhp->cfg, "TransactionFrequencyFlush");
}
if (!syslog_enabled && (xhp->flags & XBPS_FLAG_SYSLOG))
syslog_enabled = true;
xbps_fetch_set_cache_connection(cc, cch);
xbps_dbg_printf("Rootdir=%s\n", xhp->rootdir);
@ -181,7 +188,7 @@ xbps_init(struct xbps_handle *xh)
xbps_dbg_printf("FetchTimeout=%u\n", xhp->fetch_timeout);
xbps_dbg_printf("FetchCacheconn=%u\n", cc);
xbps_dbg_printf("FetchCacheconnHost=%u\n", cch);
xbps_dbg_printf("Syslog=%u\n", xhp->syslog_enabled);
xbps_dbg_printf("Syslog=%u\n", syslog_enabled);
xbps_dbg_printf("TransactionFrequencyFlush=%u\n",
xhp->transaction_frequency_flush);

View File

@ -97,9 +97,9 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
goto out;
}
prop_dictionary_get_bool(pkgd, "automatic-install", &autoinst);
if (xhp->install_reason_auto)
if (xhp->flags & XBPS_FLAG_INSTALL_AUTO)
autoinst = true;
else if (xhp->install_reason_manual)
else if (xhp->flags & XBPS_FLAG_INSTALL_MANUAL)
autoinst = false;
if (!prop_dictionary_set_bool(pkgd,

View File

@ -71,7 +71,7 @@ store_dependency(prop_dictionary_t transd,
if (!prop_array_add(array, repo_pkgd))
return EINVAL;
if (xhp->debug) {
if (xhp->flags & XBPS_FLAG_DEBUG) {
xbps_dbg_printf_append("\n");
xbps_dbg_printf(" ");
for (x = 0; x < *depth; x++)
@ -211,7 +211,7 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
rv = EINVAL;
break;
}
if (xhp->debug) {
if (xhp->flags & XBPS_FLAG_DEBUG) {
xbps_dbg_printf("");
for (x = 0; x < *depth; x++)
xbps_dbg_printf_append(" ");
@ -419,7 +419,7 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
continue;
}
prop_object_release(curpkgd);
if (xhp->debug) {
if (xhp->flags & XBPS_FLAG_DEBUG) {
xbps_dbg_printf("");
for (x = 0; x < *depth; x++)
xbps_dbg_printf_append(" ");