xbps_pkgdb_update: added 3rd bool arg "update", not update in memory pkgdb.

If true, the in memory pkgdb dict will be updated with data from the on-disk pkgdb.
This commit is contained in:
Juan RP 2015-01-10 19:42:09 +01:00
parent 7c153a2b15
commit 7dea05f507
3 changed files with 14 additions and 9 deletions

View File

@ -48,7 +48,7 @@
* *
* This header documents the full API for the XBPS Library. * This header documents the full API for the XBPS Library.
*/ */
#define XBPS_API_VERSION "20150110" #define XBPS_API_VERSION "20150110-1"
#ifndef XBPS_VERSION #ifndef XBPS_VERSION
#define XBPS_VERSION "UNSET" #define XBPS_VERSION "UNSET"
@ -856,10 +856,12 @@ xbps_array_t xbps_pkgdb_get_pkg_fulldeptree(struct xbps_handle *xhp,
* @param[in] xhp The pointer to the xbps_handle struct. * @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] flush If true the pkgdb plist contents in memory will * @param[in] flush If true the pkgdb plist contents in memory will
* be flushed atomically to storage. * be flushed atomically to storage.
* @param[in] update If true, the pkgdb plist stored on disk will be re-read
* and the in memory copy will be refreshed.
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_pkgdb_update(struct xbps_handle *xhp, bool flush); int xbps_pkgdb_update(struct xbps_handle *xhp, bool flush, bool update);
/** /**
* Creates a temporary file and executes it in rootdir. * Creates a temporary file and executes it in rootdir.

View File

@ -107,7 +107,7 @@ xbps_pkgdb_lock(struct xbps_handle *xhp)
void void
xbps_pkgdb_unlock(struct xbps_handle *xhp) xbps_pkgdb_unlock(struct xbps_handle *xhp)
{ {
(void)xbps_pkgdb_update(xhp, true); (void)xbps_pkgdb_update(xhp, true, false);
if (pkgdb_fd != -1) { if (pkgdb_fd != -1) {
if (lockf(pkgdb_fd, F_ULOCK, 0) == -1) if (lockf(pkgdb_fd, F_ULOCK, 0) == -1)
@ -189,7 +189,7 @@ xbps_pkgdb_init(struct xbps_handle *xhp)
if (xhp->pkgdb != NULL) if (xhp->pkgdb != NULL)
return 0; return 0;
if ((rv = xbps_pkgdb_update(xhp, false)) != 0) { if ((rv = xbps_pkgdb_update(xhp, false, true)) != 0) {
if (rv != ENOENT) if (rv != ENOENT)
xbps_dbg_printf(xhp, "[pkgdb] cannot internalize " xbps_dbg_printf(xhp, "[pkgdb] cannot internalize "
"pkgdb array: %s\n", strerror(rv)); "pkgdb array: %s\n", strerror(rv));
@ -206,7 +206,7 @@ xbps_pkgdb_init(struct xbps_handle *xhp)
} }
int int
xbps_pkgdb_update(struct xbps_handle *xhp, bool flush) xbps_pkgdb_update(struct xbps_handle *xhp, bool flush, bool update)
{ {
xbps_dictionary_t pkgdb_storage; xbps_dictionary_t pkgdb_storage;
static int cached_rv; static int cached_rv;
@ -215,7 +215,7 @@ xbps_pkgdb_update(struct xbps_handle *xhp, bool flush)
if (cached_rv && !flush) if (cached_rv && !flush)
return cached_rv; return cached_rv;
if (xhp->pkgdb && flush) { if (xhp->pkgdb && update) {
pkgdb_storage = xbps_dictionary_internalize_from_file(xhp->pkgdb_plist); pkgdb_storage = xbps_dictionary_internalize_from_file(xhp->pkgdb_plist);
if (pkgdb_storage == NULL || if (pkgdb_storage == NULL ||
!xbps_dictionary_equals(xhp->pkgdb, pkgdb_storage)) { !xbps_dictionary_equals(xhp->pkgdb, pkgdb_storage)) {
@ -230,6 +230,9 @@ xbps_pkgdb_update(struct xbps_handle *xhp, bool flush)
xhp->pkgdb = NULL; xhp->pkgdb = NULL;
cached_rv = 0; cached_rv = 0;
} }
if (!update)
return rv;
/* update copy in memory */ /* update copy in memory */
if ((xhp->pkgdb = xbps_dictionary_internalize_from_file(xhp->pkgdb_plist)) == NULL) { if ((xhp->pkgdb = xbps_dictionary_internalize_from_file(xhp->pkgdb_plist)) == NULL) {
if (errno == ENOENT) if (errno == ENOENT)

View File

@ -1,5 +1,5 @@
/*- /*-
* Copyright (c) 2009-2014 Juan Romero Pardines. * Copyright (c) 2009-2015 Juan Romero Pardines.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -348,7 +348,7 @@ xbps_transaction_commit(struct xbps_handle *xhp)
xbps_object_iterator_reset(iter); xbps_object_iterator_reset(iter);
/* Force a pkgdb write for all unpacked pkgs in transaction */ /* Force a pkgdb write for all unpacked pkgs in transaction */
(void)xbps_pkgdb_update(xhp, true); (void)xbps_pkgdb_update(xhp, true, true);
/* /*
* Configure all unpacked packages. * Configure all unpacked packages.
@ -390,7 +390,7 @@ xbps_transaction_commit(struct xbps_handle *xhp)
out: out:
xbps_object_iterator_release(iter); xbps_object_iterator_release(iter);
/* Force a pkgdb write for all unpacked pkgs in transaction */ /* Force a pkgdb write for all unpacked pkgs in transaction */
(void)xbps_pkgdb_update(xhp, true); (void)xbps_pkgdb_update(xhp, true, true);
return rv; return rv;
} }