mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-22 15:58:50 -05:00
Completely separate local and sync db handling
Put the db_operations struct to use and completely split the handling of the sync and local databases. Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
5b2de3d8ec
commit
fc32faaa6a
@ -497,7 +497,7 @@ static int commit_single_pkg(pmpkg_t *newpkg, int pkg_current, int pkg_count,
|
||||
oldpkg = _alpm_pkg_dup(local);
|
||||
/* make sure all infos are loaded because the database entry
|
||||
* will be removed soon */
|
||||
_alpm_db_read(oldpkg->origin_data.db, oldpkg, INFRQ_ALL);
|
||||
_alpm_local_db_read(oldpkg->origin_data.db, oldpkg, INFRQ_ALL);
|
||||
|
||||
EVENT(trans, PM_TRANS_EVT_UPGRADE_START, newpkg, oldpkg);
|
||||
_alpm_log(PM_LOG_DEBUG, "upgrading package %s-%s\n",
|
||||
|
@ -57,7 +57,7 @@
|
||||
ASSERT(handle != NULL, return(errret)); \
|
||||
ASSERT(pkg != NULL, return(errret)); \
|
||||
if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & info)) { \
|
||||
_alpm_db_read(pkg->origin_data.db, pkg, info); \
|
||||
_alpm_local_db_read(pkg->origin_data.db, pkg, info); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
@ -210,7 +210,7 @@ alpm_list_t *_cache_get_files(pmpkg_t *pkg)
|
||||
|
||||
if(pkg->origin == PKG_FROM_LOCALDB
|
||||
&& !(pkg->infolevel & INFRQ_FILES)) {
|
||||
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_FILES);
|
||||
_alpm_local_db_read(pkg->origin_data.db, pkg, INFRQ_FILES);
|
||||
}
|
||||
return pkg->files;
|
||||
}
|
||||
@ -225,7 +225,7 @@ alpm_list_t *_cache_get_backup(pmpkg_t *pkg)
|
||||
|
||||
if(pkg->origin == PKG_FROM_LOCALDB
|
||||
&& !(pkg->infolevel & INFRQ_FILES)) {
|
||||
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_FILES);
|
||||
_alpm_local_db_read(pkg->origin_data.db, pkg, INFRQ_FILES);
|
||||
}
|
||||
return pkg->backup;
|
||||
}
|
||||
@ -340,31 +340,7 @@ static int is_dir(const char *path, struct dirent *entry)
|
||||
#endif
|
||||
}
|
||||
|
||||
pmdb_t *_alpm_db_register_local(void)
|
||||
{
|
||||
pmdb_t *db;
|
||||
|
||||
ALPM_LOG_FUNC;
|
||||
|
||||
if(handle->db_local != NULL) {
|
||||
_alpm_log(PM_LOG_WARNING, _("attempt to re-register the 'local' DB\n"));
|
||||
RET_ERR(PM_ERR_DB_NOT_NULL, NULL);
|
||||
}
|
||||
|
||||
_alpm_log(PM_LOG_DEBUG, "registering local database\n");
|
||||
|
||||
db = _alpm_db_new("local", 1);
|
||||
db->ops = &default_db_ops;
|
||||
if(db == NULL) {
|
||||
RET_ERR(PM_ERR_DB_CREATE, NULL);
|
||||
}
|
||||
|
||||
handle->db_local = db;
|
||||
return(db);
|
||||
}
|
||||
|
||||
|
||||
int _alpm_db_populate(pmdb_t *db)
|
||||
int _alpm_local_db_populate(pmdb_t *db)
|
||||
{
|
||||
int count = 0;
|
||||
struct dirent *ent = NULL;
|
||||
@ -412,7 +388,7 @@ int _alpm_db_populate(pmdb_t *db)
|
||||
}
|
||||
|
||||
/* explicitly read with only 'BASE' data, accessors will handle the rest */
|
||||
if(_alpm_db_read(db, pkg, INFRQ_BASE) == -1) {
|
||||
if(_alpm_local_db_read(db, pkg, INFRQ_BASE) == -1) {
|
||||
_alpm_log(PM_LOG_ERROR, _("corrupted database entry '%s'\n"), name);
|
||||
_alpm_pkg_free(pkg);
|
||||
continue;
|
||||
@ -434,7 +410,7 @@ int _alpm_db_populate(pmdb_t *db)
|
||||
return(count);
|
||||
}
|
||||
|
||||
int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
|
||||
int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
char path[PATH_MAX];
|
||||
@ -448,7 +424,7 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
|
||||
}
|
||||
|
||||
if(info == NULL || info->name == NULL || info->version == NULL) {
|
||||
_alpm_log(PM_LOG_DEBUG, "invalid package entry provided to _alpm_db_read, skipping\n");
|
||||
_alpm_log(PM_LOG_DEBUG, "invalid package entry provided to _alpm_local_db_read, skipping\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
@ -982,4 +958,33 @@ int _alpm_local_db_remove(pmdb_t *db, pmpkg_t *info)
|
||||
return(ret);
|
||||
}
|
||||
|
||||
struct db_operations local_db_ops = {
|
||||
.populate = _alpm_local_db_populate,
|
||||
.unregister = _alpm_db_unregister,
|
||||
};
|
||||
|
||||
pmdb_t *_alpm_db_register_local(void)
|
||||
{
|
||||
pmdb_t *db;
|
||||
|
||||
ALPM_LOG_FUNC;
|
||||
|
||||
if(handle->db_local != NULL) {
|
||||
_alpm_log(PM_LOG_WARNING, _("attempt to re-register the 'local' DB\n"));
|
||||
RET_ERR(PM_ERR_DB_NOT_NULL, NULL);
|
||||
}
|
||||
|
||||
_alpm_log(PM_LOG_DEBUG, "registering local database\n");
|
||||
|
||||
db = _alpm_db_new("local", 1);
|
||||
db->ops = &local_db_ops;
|
||||
if(db == NULL) {
|
||||
RET_ERR(PM_ERR_DB_CREATE, NULL);
|
||||
}
|
||||
|
||||
handle->db_local = db;
|
||||
return(db);
|
||||
}
|
||||
|
||||
|
||||
/* vim: set ts=2 sw=2 noet: */
|
||||
|
@ -39,14 +39,13 @@
|
||||
#include "deps.h"
|
||||
#include "dload.h"
|
||||
|
||||
|
||||
#define LAZY_LOAD(info, errret) \
|
||||
do { \
|
||||
ALPM_LOG_FUNC; \
|
||||
ASSERT(handle != NULL, return(errret)); \
|
||||
ASSERT(pkg != NULL, return(errret)); \
|
||||
if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & info)) { \
|
||||
_alpm_db_read(pkg->origin_data.db, pkg, info); \
|
||||
_alpm_sync_db_read(pkg->origin_data.db, pkg, info); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
@ -199,7 +198,7 @@ alpm_list_t *_sync_cache_get_files(pmpkg_t *pkg)
|
||||
|
||||
if(pkg->origin == PKG_FROM_LOCALDB
|
||||
&& !(pkg->infolevel & INFRQ_FILES)) {
|
||||
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_FILES);
|
||||
_alpm_sync_db_read(pkg->origin_data.db, pkg, INFRQ_FILES);
|
||||
}
|
||||
return pkg->files;
|
||||
}
|
||||
@ -214,7 +213,7 @@ alpm_list_t *_sync_cache_get_backup(pmpkg_t *pkg)
|
||||
|
||||
if(pkg->origin == PKG_FROM_LOCALDB
|
||||
&& !(pkg->infolevel & INFRQ_FILES)) {
|
||||
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_FILES);
|
||||
_alpm_sync_db_read(pkg->origin_data.db, pkg, INFRQ_FILES);
|
||||
}
|
||||
return pkg->backup;
|
||||
}
|
||||
@ -250,33 +249,6 @@ static struct pkg_operations sync_pkg_ops = {
|
||||
.get_backup = _sync_cache_get_backup,
|
||||
};
|
||||
|
||||
pmdb_t *_alpm_db_register_sync(const char *treename)
|
||||
{
|
||||
pmdb_t *db;
|
||||
alpm_list_t *i;
|
||||
|
||||
ALPM_LOG_FUNC;
|
||||
|
||||
for(i = handle->dbs_sync; i; i = i->next) {
|
||||
pmdb_t *sdb = i->data;
|
||||
if(strcmp(treename, sdb->treename) == 0) {
|
||||
_alpm_log(PM_LOG_DEBUG, "attempt to re-register the '%s' database, using existing\n", sdb->treename);
|
||||
return sdb;
|
||||
}
|
||||
}
|
||||
|
||||
_alpm_log(PM_LOG_DEBUG, "registering sync database '%s'\n", treename);
|
||||
|
||||
db = _alpm_db_new(treename, 0);
|
||||
db->ops = &default_db_ops;
|
||||
if(db == NULL) {
|
||||
RET_ERR(PM_ERR_DB_CREATE, NULL);
|
||||
}
|
||||
|
||||
handle->dbs_sync = alpm_list_add(handle->dbs_sync, db);
|
||||
return(db);
|
||||
}
|
||||
|
||||
/* create list of directories in db */
|
||||
static int dirlist_from_tar(const char *archive, alpm_list_t **dirlist)
|
||||
{
|
||||
@ -577,7 +549,7 @@ int _alpm_sync_db_populate(pmdb_t *db)
|
||||
}
|
||||
|
||||
/* explicitly read with only 'BASE' data, accessors will handle the rest */
|
||||
if(_alpm_db_read(db, pkg, INFRQ_BASE) == -1) {
|
||||
if(_alpm_sync_db_read(db, pkg, INFRQ_BASE) == -1) {
|
||||
_alpm_log(PM_LOG_ERROR, _("corrupted database entry '%s'\n"), name);
|
||||
_alpm_pkg_free(pkg);
|
||||
continue;
|
||||
@ -613,7 +585,7 @@ int _alpm_sync_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
|
||||
}
|
||||
|
||||
if(info == NULL || info->name == NULL || info->version == NULL) {
|
||||
_alpm_log(PM_LOG_DEBUG, "invalid package entry provided to _alpm_db_read, skipping\n");
|
||||
_alpm_log(PM_LOG_DEBUG, "invalid package entry provided to _alpm_sync_db_read, skipping\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
@ -903,4 +875,37 @@ error:
|
||||
return(-1);
|
||||
}
|
||||
|
||||
struct db_operations sync_db_ops = {
|
||||
.populate = _alpm_sync_db_populate,
|
||||
.unregister = _alpm_db_unregister,
|
||||
};
|
||||
|
||||
pmdb_t *_alpm_db_register_sync(const char *treename)
|
||||
{
|
||||
pmdb_t *db;
|
||||
alpm_list_t *i;
|
||||
|
||||
ALPM_LOG_FUNC;
|
||||
|
||||
for(i = handle->dbs_sync; i; i = i->next) {
|
||||
pmdb_t *sdb = i->data;
|
||||
if(strcmp(treename, sdb->treename) == 0) {
|
||||
_alpm_log(PM_LOG_DEBUG, "attempt to re-register the '%s' database, using existing\n", sdb->treename);
|
||||
return sdb;
|
||||
}
|
||||
}
|
||||
|
||||
_alpm_log(PM_LOG_DEBUG, "registering sync database '%s'\n", treename);
|
||||
|
||||
db = _alpm_db_new(treename, 0);
|
||||
db->ops = &sync_db_ops;
|
||||
if(db == NULL) {
|
||||
RET_ERR(PM_ERR_DB_CREATE, NULL);
|
||||
}
|
||||
|
||||
handle->dbs_sync = alpm_list_add(handle->dbs_sync, db);
|
||||
return(db);
|
||||
}
|
||||
|
||||
|
||||
/* vim: set ts=2 sw=2 noet: */
|
||||
|
@ -43,12 +43,6 @@
|
||||
#include "package.h"
|
||||
#include "group.h"
|
||||
|
||||
|
||||
struct db_operations default_db_ops = {
|
||||
.populate = _alpm_db_populate,
|
||||
.unregister = _alpm_db_unregister,
|
||||
};
|
||||
|
||||
/** \addtogroup alpm_databases Database Functions
|
||||
* @brief Functions to query and manipulate the database of libalpm
|
||||
* @{
|
||||
@ -353,7 +347,7 @@ int SYMEXPORT alpm_db_set_pkgreason(pmdb_t *db, const char *name, pmpkgreason_t
|
||||
|
||||
_alpm_log(PM_LOG_DEBUG, "setting install reason %u for %s/%s\n", reason, db->treename, name);
|
||||
/* read DESC */
|
||||
if(_alpm_db_read(db, pkg, INFRQ_DESC)) {
|
||||
if(_alpm_local_db_read(db, pkg, INFRQ_DESC)) {
|
||||
return(-1);
|
||||
}
|
||||
if(pkg->reason == reason) {
|
||||
|
@ -60,7 +60,6 @@ struct __pmdb_t {
|
||||
struct db_operations *ops;
|
||||
};
|
||||
|
||||
extern struct db_operations default_db_ops;
|
||||
|
||||
/* db.c, database general calls */
|
||||
void _alpm_db_free(pmdb_t *db);
|
||||
@ -73,12 +72,13 @@ void _alpm_db_unregister(pmdb_t *db);
|
||||
pmdb_t *_alpm_db_new(const char *treename, int is_local);
|
||||
|
||||
/* be.c, backend specific calls */
|
||||
int _alpm_db_populate(pmdb_t *db);
|
||||
int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq);
|
||||
|
||||
int _alpm_local_db_populate(pmdb_t *db);
|
||||
int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq);
|
||||
int _alpm_local_db_prepare(pmdb_t *db, pmpkg_t *info);
|
||||
int _alpm_local_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq);
|
||||
int _alpm_local_db_remove(pmdb_t *db, pmpkg_t *info);
|
||||
int _alpm_sync_db_populate(pmdb_t *db);
|
||||
int _alpm_sync_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq);
|
||||
|
||||
/* cache bullshit */
|
||||
/* packages */
|
||||
|
@ -350,7 +350,7 @@ int SYMEXPORT alpm_pkg_has_scriptlet(pmpkg_t *pkg)
|
||||
|
||||
if(pkg->origin == PKG_FROM_LOCALDB
|
||||
&& !(pkg->infolevel & INFRQ_SCRIPTLET)) {
|
||||
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_SCRIPTLET);
|
||||
_alpm_local_db_read(pkg->origin_data.db, pkg, INFRQ_SCRIPTLET);
|
||||
}
|
||||
return pkg->scriptlet;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user