+/** Check the validity of a database.
+ * This is most useful for sync databases and verifying signature status.
+ * If invalid, the handle error code will be set accordingly.
+ * @param db pointer to the package database
+ * @return 0 if valid, -1 if invalid (pm_errno is set accordingly)
+ */
+int alpm_db_validity(pmdb_t *db);
+
/** @name Accessors to the list of servers for a database.
* @{
*/
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 5006688..f273db7 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -926,6 +926,7 @@ int _alpm_local_db_remove(pmdb_t *db, pmpkg_t *info)
}
+/** Check the validity of a database. */
+int SYMEXPORT alpm_db_validity(pmdb_t *db)
+{
+ ASSERT(db != NULL, return -1);
+ db->handle->pm_errno = 0;
+ return db->ops->validate(db);
+}
+
/** Get a package entry from a package database. */
pmpkg_t SYMEXPORT *alpm_db_get_pkg(pmdb_t *db, const char *name)
{
diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index 0318734..5da28bf 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -51,6 +51,7 @@ enum _pmdbstatus_t {
};
struct db_operations {
+ int (*validate) (pmdb_t *);
int (*populate) (pmdb_t *);
void (*unregister) (pmdb_t *);
};
--
1.7.5.4
06-27-2011, 09:51 PM
Dave Reisner
Add an alpm_db_validity() public function
On Mon, Jun 27, 2011 at 04:39:36PM -0500, Dan McGee wrote:
> This allows one to check if a database is valid or invalid.
>
> Signed-off-by: Dan McGee <dan@archlinux.org>
> ---
> lib/libalpm/alpm.h | 8 ++++++++
> lib/libalpm/be_local.c | 1 +
> lib/libalpm/be_sync.c | 1 +
> lib/libalpm/db.c | 8 ++++++++
> lib/libalpm/db.h | 1 +
> 5 files changed, 19 insertions(+), 0 deletions(-)
>
> diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
> index ac35213..11ebfc1 100644
> --- a/lib/libalpm/alpm.h
> +++ b/lib/libalpm/alpm.h
> @@ -382,6 +382,14 @@ int alpm_db_unregister_all(pmhandle_t *handle);
> */
> const char *alpm_db_get_name(const pmdb_t *db);
>
> +/** Check the validity of a database.
> + * This is most useful for sync databases and verifying signature status.
> + * If invalid, the handle error code will be set accordingly.
> + * @param db pointer to the package database
> + * @return 0 if valid, -1 if invalid (pm_errno is set accordingly)
> + */
> +int alpm_db_validity(pmdb_t *db);
Voting for alpm_db_get_validity or alpm_db_is_valid instead of this
name. We seem to use verbs in our API pretty uniformly.