From 7dea05f507a9620962f7d4b2be30ec0b8d12c50d Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sat, 10 Jan 2015 19:42:09 +0100 Subject: [PATCH] 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. --- include/xbps.h.in | 6 ++++-- lib/pkgdb.c | 11 +++++++---- lib/transaction_commit.c | 6 +++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/include/xbps.h.in b/include/xbps.h.in index cd4ce4b8..3329632e 100644 --- a/include/xbps.h.in +++ b/include/xbps.h.in @@ -48,7 +48,7 @@ * * This header documents the full API for the XBPS Library. */ -#define XBPS_API_VERSION "20150110" +#define XBPS_API_VERSION "20150110-1" #ifndef XBPS_VERSION #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] flush If true the pkgdb plist contents in memory will * 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. */ -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. diff --git a/lib/pkgdb.c b/lib/pkgdb.c index 57be51ca..7be285dd 100644 --- a/lib/pkgdb.c +++ b/lib/pkgdb.c @@ -107,7 +107,7 @@ xbps_pkgdb_lock(struct xbps_handle *xhp) void 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 (lockf(pkgdb_fd, F_ULOCK, 0) == -1) @@ -189,7 +189,7 @@ xbps_pkgdb_init(struct xbps_handle *xhp) if (xhp->pkgdb != NULL) return 0; - if ((rv = xbps_pkgdb_update(xhp, false)) != 0) { + if ((rv = xbps_pkgdb_update(xhp, false, true)) != 0) { if (rv != ENOENT) xbps_dbg_printf(xhp, "[pkgdb] cannot internalize " "pkgdb array: %s\n", strerror(rv)); @@ -206,7 +206,7 @@ xbps_pkgdb_init(struct xbps_handle *xhp) } 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; static int cached_rv; @@ -215,7 +215,7 @@ xbps_pkgdb_update(struct xbps_handle *xhp, bool flush) if (cached_rv && !flush) return cached_rv; - if (xhp->pkgdb && flush) { + if (xhp->pkgdb && update) { pkgdb_storage = xbps_dictionary_internalize_from_file(xhp->pkgdb_plist); if (pkgdb_storage == NULL || !xbps_dictionary_equals(xhp->pkgdb, pkgdb_storage)) { @@ -230,6 +230,9 @@ xbps_pkgdb_update(struct xbps_handle *xhp, bool flush) xhp->pkgdb = NULL; cached_rv = 0; } + if (!update) + return rv; + /* update copy in memory */ if ((xhp->pkgdb = xbps_dictionary_internalize_from_file(xhp->pkgdb_plist)) == NULL) { if (errno == ENOENT) diff --git a/lib/transaction_commit.c b/lib/transaction_commit.c index 27ae66cf..5a2cf783 100644 --- a/lib/transaction_commit.c +++ b/lib/transaction_commit.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2014 Juan Romero Pardines. + * Copyright (c) 2009-2015 Juan Romero Pardines. * All rights reserved. * * 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); /* 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. @@ -390,7 +390,7 @@ xbps_transaction_commit(struct xbps_handle *xhp) out: xbps_object_iterator_release(iter); /* 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; }