Initial hack at a DB operations struct
It doesn't do a whole lot yet, but these type of operations will potentially be different for the DBs we load. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
522ef5e981
commit
efbae3cfcb
3 changed files with 29 additions and 7 deletions
|
@ -367,7 +367,7 @@ int _alpm_db_load_pkgcache(pmdb_t *db)
|
||||||
|
|
||||||
_alpm_log(PM_LOG_DEBUG, "loading package cache for repository '%s'\n",
|
_alpm_log(PM_LOG_DEBUG, "loading package cache for repository '%s'\n",
|
||||||
db->treename);
|
db->treename);
|
||||||
if(_alpm_db_populate(db) == -1) {
|
if(db->ops->populate(db) == -1) {
|
||||||
_alpm_log(PM_LOG_DEBUG,
|
_alpm_log(PM_LOG_DEBUG,
|
||||||
"failed to load package cache for repository '%s'\n", db->treename);
|
"failed to load package cache for repository '%s'\n", db->treename);
|
||||||
return(-1);
|
return(-1);
|
||||||
|
|
|
@ -42,6 +42,11 @@
|
||||||
#include "alpm.h"
|
#include "alpm.h"
|
||||||
#include "package.h"
|
#include "package.h"
|
||||||
|
|
||||||
|
struct db_operations default_db_ops = {
|
||||||
|
.populate = _alpm_db_populate,
|
||||||
|
.unregister = _alpm_db_unregister,
|
||||||
|
};
|
||||||
|
|
||||||
/** \addtogroup alpm_databases Database Functions
|
/** \addtogroup alpm_databases Database Functions
|
||||||
* @brief Functions to query and manipulate the database of libalpm
|
* @brief Functions to query and manipulate the database of libalpm
|
||||||
* @{
|
* @{
|
||||||
|
@ -80,7 +85,7 @@ pmdb_t SYMEXPORT *alpm_db_register_local(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper function for alpm_db_unregister{_all} */
|
/* Helper function for alpm_db_unregister{_all} */
|
||||||
static void _alpm_db_unregister(pmdb_t *db)
|
void _alpm_db_unregister(pmdb_t *db)
|
||||||
{
|
{
|
||||||
if(db == NULL) {
|
if(db == NULL) {
|
||||||
return;
|
return;
|
||||||
|
@ -96,6 +101,7 @@ static void _alpm_db_unregister(pmdb_t *db)
|
||||||
int SYMEXPORT alpm_db_unregister_all(void)
|
int SYMEXPORT alpm_db_unregister_all(void)
|
||||||
{
|
{
|
||||||
alpm_list_t *i;
|
alpm_list_t *i;
|
||||||
|
pmdb_t *db;
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
|
@ -105,13 +111,16 @@ int SYMEXPORT alpm_db_unregister_all(void)
|
||||||
ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, -1));
|
ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, -1));
|
||||||
|
|
||||||
/* close local database */
|
/* close local database */
|
||||||
_alpm_db_unregister(handle->db_local);
|
db = handle->db_local;
|
||||||
handle->db_local = NULL;
|
if(db) {
|
||||||
|
db->ops->unregister(db);
|
||||||
|
handle->db_local = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* and also sync ones */
|
/* and also sync ones */
|
||||||
for(i = handle->dbs_sync; i; i = i->next) {
|
for(i = handle->dbs_sync; i; i = i->next) {
|
||||||
pmdb_t *db = i->data;
|
db = i->data;
|
||||||
_alpm_db_unregister(db);
|
db->ops->unregister(db);
|
||||||
i->data = NULL;
|
i->data = NULL;
|
||||||
}
|
}
|
||||||
FREELIST(handle->dbs_sync);
|
FREELIST(handle->dbs_sync);
|
||||||
|
@ -154,7 +163,7 @@ int SYMEXPORT alpm_db_unregister(pmdb_t *db)
|
||||||
RET_ERR(PM_ERR_DB_NOT_FOUND, -1);
|
RET_ERR(PM_ERR_DB_NOT_FOUND, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
_alpm_db_unregister(db);
|
db->ops->unregister(db);
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,6 +526,7 @@ pmdb_t *_alpm_db_register_local(void)
|
||||||
_alpm_log(PM_LOG_DEBUG, "registering local database\n");
|
_alpm_log(PM_LOG_DEBUG, "registering local database\n");
|
||||||
|
|
||||||
db = _alpm_db_new("local", 1);
|
db = _alpm_db_new("local", 1);
|
||||||
|
db->ops = &default_db_ops;
|
||||||
if(db == NULL) {
|
if(db == NULL) {
|
||||||
RET_ERR(PM_ERR_DB_CREATE, NULL);
|
RET_ERR(PM_ERR_DB_CREATE, NULL);
|
||||||
}
|
}
|
||||||
|
@ -543,6 +553,7 @@ pmdb_t *_alpm_db_register_sync(const char *treename)
|
||||||
_alpm_log(PM_LOG_DEBUG, "registering sync database '%s'\n", treename);
|
_alpm_log(PM_LOG_DEBUG, "registering sync database '%s'\n", treename);
|
||||||
|
|
||||||
db = _alpm_db_new(treename, 0);
|
db = _alpm_db_new(treename, 0);
|
||||||
|
db->ops = &default_db_ops;
|
||||||
if(db == NULL) {
|
if(db == NULL) {
|
||||||
RET_ERR(PM_ERR_DB_CREATE, NULL);
|
RET_ERR(PM_ERR_DB_CREATE, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,11 @@ typedef enum _pmdbinfrq_t {
|
||||||
INFRQ_ALL = 0x3F
|
INFRQ_ALL = 0x3F
|
||||||
} pmdbinfrq_t;
|
} pmdbinfrq_t;
|
||||||
|
|
||||||
|
struct db_operations {
|
||||||
|
int (*populate) (pmdb_t *);
|
||||||
|
void (*unregister) (pmdb_t *);
|
||||||
|
};
|
||||||
|
|
||||||
/* Database */
|
/* Database */
|
||||||
struct __pmdb_t {
|
struct __pmdb_t {
|
||||||
char *treename;
|
char *treename;
|
||||||
|
@ -46,12 +51,17 @@ struct __pmdb_t {
|
||||||
char *_path;
|
char *_path;
|
||||||
int pkgcache_loaded;
|
int pkgcache_loaded;
|
||||||
int grpcache_loaded;
|
int grpcache_loaded;
|
||||||
|
/* also indicates whether we are RO or RW */
|
||||||
int is_local;
|
int is_local;
|
||||||
alpm_list_t *pkgcache;
|
alpm_list_t *pkgcache;
|
||||||
alpm_list_t *grpcache;
|
alpm_list_t *grpcache;
|
||||||
alpm_list_t *servers;
|
alpm_list_t *servers;
|
||||||
|
|
||||||
|
struct db_operations *ops;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern struct db_operations default_db_ops;
|
||||||
|
|
||||||
/* db.c, database general calls */
|
/* db.c, database general calls */
|
||||||
void _alpm_db_free(pmdb_t *db);
|
void _alpm_db_free(pmdb_t *db);
|
||||||
const char *_alpm_db_path(pmdb_t *db);
|
const char *_alpm_db_path(pmdb_t *db);
|
||||||
|
@ -59,6 +69,7 @@ int _alpm_db_cmp(const void *d1, const void *d2);
|
||||||
alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles);
|
alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles);
|
||||||
pmdb_t *_alpm_db_register_local(void);
|
pmdb_t *_alpm_db_register_local(void);
|
||||||
pmdb_t *_alpm_db_register_sync(const char *treename);
|
pmdb_t *_alpm_db_register_sync(const char *treename);
|
||||||
|
void _alpm_db_unregister(pmdb_t *db);
|
||||||
|
|
||||||
/* be.c, backend specific calls */
|
/* be.c, backend specific calls */
|
||||||
int _alpm_db_populate(pmdb_t *db);
|
int _alpm_db_populate(pmdb_t *db);
|
||||||
|
|
Loading…
Add table
Reference in a new issue