libxbps: use a new bool in struct xbps_handle to track successful initialization.

(cherry picked from commit 03374950680f6a839b1ee2df8e3a4e1dfb110fa8)
This commit is contained in:
Juan RP 2012-09-24 10:50:23 +02:00
parent 7714f0f6c5
commit e370ff0625
2 changed files with 13 additions and 6 deletions

View File

@ -81,7 +81,7 @@
/** /**
* @def XBPS_PKGDB * @def XBPS_PKGDB
* Filename for the master package database. * Filename for the package database.
*/ */
#define XBPS_PKGDB "pkgdb.plist" #define XBPS_PKGDB "pkgdb.plist"
@ -562,6 +562,10 @@ struct xbps_handle {
* - XBPS_FLAG_INSTALL_MANUAL * - XBPS_FLAG_INSTALL_MANUAL
*/ */
int flags; int flags;
/**
* @private
*/
bool initialized;
}; };
void xbps_dbg_printf(struct xbps_handle *, const char *, ...); void xbps_dbg_printf(struct xbps_handle *, const char *, ...);

View File

@ -40,8 +40,6 @@
* Use these functions to initialize some parameters before start * Use these functions to initialize some parameters before start
* using libxbps and finalize usage to release resources at the end. * using libxbps and finalize usage to release resources at the end.
*/ */
static bool xbps_initialized;
static char * static char *
set_cachedir(struct xbps_handle *xh) set_cachedir(struct xbps_handle *xh)
{ {
@ -121,6 +119,9 @@ xbps_init(struct xbps_handle *xhp)
assert(xhp != NULL); assert(xhp != NULL);
if (xhp->initialized)
return 0;
if (xhp->conffile == NULL) if (xhp->conffile == NULL)
xhp->conffile = XBPS_CONF_DEF; xhp->conffile = XBPS_CONF_DEF;
@ -207,7 +208,7 @@ xbps_init(struct xbps_handle *xhp)
xhp->transaction_frequency_flush); xhp->transaction_frequency_flush);
xbps_dbg_printf(xhp, "Architecture: %s\n", xhp->un_machine); xbps_dbg_printf(xhp, "Architecture: %s\n", xhp->un_machine);
xbps_initialized = true; xhp->initialized = true;
return 0; return 0;
} }
@ -215,7 +216,9 @@ xbps_init(struct xbps_handle *xhp)
void void
xbps_end(struct xbps_handle *xhp) xbps_end(struct xbps_handle *xhp)
{ {
if (!xbps_initialized) assert(xhp);
if (!xhp->initialized)
return; return;
xbps_pkgdb_release(xhp); xbps_pkgdb_release(xhp);
@ -227,8 +230,8 @@ xbps_end(struct xbps_handle *xhp)
free(xhp->metadir_priv); free(xhp->metadir_priv);
free(xhp->un_machine); free(xhp->un_machine);
xhp->initialized = false;
xhp = NULL; xhp = NULL;
xbps_initialized = false;
} }
static void static void