xbps-uhelper: optimize some targets where xbps_init() is not necessary.

This commit is contained in:
Juan RP 2011-11-05 08:41:29 +01:00
parent 7b251477e5
commit fe3353a2b2

View File

@ -110,11 +110,11 @@ usage(struct xbps_handle *xhp)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
struct xbps_handle *xhp; struct xbps_handle *xhp = NULL;
struct xferstat xfer; struct xferstat xfer;
prop_dictionary_t dict; prop_dictionary_t dict;
const char *version, *rootdir = NULL, *confdir = NULL; const char *version, *rootdir = NULL, *confdir = NULL;
char *plist, *pkgname, *pkgver, *in_chroot_env, *hash; char *plist = NULL, *pkgname, *pkgver, *in_chroot_env, *hash;
bool debug = false, in_chroot = false; bool debug = false, in_chroot = false;
int i, c, rv = 0; int i, c, rv = 0;
@ -145,33 +145,38 @@ main(int argc, char **argv)
if (argc < 1) if (argc < 1)
usage(NULL); usage(NULL);
/* if ((strcasecmp(argv[0], "register") == 0) ||
* Initialize the callbacks and debug in libxbps. (strcasecmp(argv[0], "unregister") == 0) ||
*/ (strcasecmp(argv[0], "version") == 0) ||
xhp = xbps_handle_alloc(); (strcasecmp(argv[0], "fetch") == 0)) {
if (xhp == NULL) { /*
xbps_error_printf("xbps-uhelper: failed to allocate resources\n"); * Initialize the callbacks and debug in libxbps.
exit(EXIT_FAILURE); */
} xhp = xbps_handle_alloc();
xhp->debug = debug; if (xhp == NULL) {
xhp->xbps_fetch_cb = fetch_file_progress_cb; xbps_error_printf("xbps-uhelper: failed to allocate resources\n");
xhp->xfcd->cookie = &xfer; exit(EXIT_FAILURE);
if (rootdir) }
xhp->rootdir = prop_string_create_cstring(rootdir); xhp->debug = debug;
if (confdir) xhp->xbps_fetch_cb = fetch_file_progress_cb;
xhp->confdir = prop_string_create_cstring(confdir); xhp->xfcd->cookie = &xfer;
if (rootdir)
xhp->rootdir = prop_string_create_cstring(rootdir);
if (confdir)
xhp->confdir = prop_string_create_cstring(confdir);
if ((rv = xbps_init(xhp)) != 0) { if ((rv = xbps_init(xhp)) != 0) {
xbps_error_printf("xbps-uhelper: failed to " xbps_error_printf("xbps-uhelper: failed to "
"initialize libxbps.\n"); "initialize libxbps.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
plist = xbps_xasprintf("%s/%s/%s", rootdir, plist = xbps_xasprintf("%s/%s/%s", rootdir,
XBPS_META_PATH, XBPS_REGPKGDB); XBPS_META_PATH, XBPS_REGPKGDB);
if (plist == NULL) { if (plist == NULL) {
xbps_end(xhp); xbps_end(xhp);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
}
} }
in_chroot_env = getenv("in_chroot"); in_chroot_env = getenv("in_chroot");