mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-08 12:28:00 -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);
|
oldpkg = _alpm_pkg_dup(local);
|
||||||
/* make sure all infos are loaded because the database entry
|
/* make sure all infos are loaded because the database entry
|
||||||
* will be removed soon */
|
* 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);
|
EVENT(trans, PM_TRANS_EVT_UPGRADE_START, newpkg, oldpkg);
|
||||||
_alpm_log(PM_LOG_DEBUG, "upgrading package %s-%s\n",
|
_alpm_log(PM_LOG_DEBUG, "upgrading package %s-%s\n",
|
||||||
|
@ -57,7 +57,7 @@
|
|||||||
ASSERT(handle != NULL, return(errret)); \
|
ASSERT(handle != NULL, return(errret)); \
|
||||||
ASSERT(pkg != NULL, return(errret)); \
|
ASSERT(pkg != NULL, return(errret)); \
|
||||||
if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & info)) { \
|
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)
|
} while(0)
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ alpm_list_t *_cache_get_files(pmpkg_t *pkg)
|
|||||||
|
|
||||||
if(pkg->origin == PKG_FROM_LOCALDB
|
if(pkg->origin == PKG_FROM_LOCALDB
|
||||||
&& !(pkg->infolevel & INFRQ_FILES)) {
|
&& !(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;
|
return pkg->files;
|
||||||
}
|
}
|
||||||
@ -225,7 +225,7 @@ alpm_list_t *_cache_get_backup(pmpkg_t *pkg)
|
|||||||
|
|
||||||
if(pkg->origin == PKG_FROM_LOCALDB
|
if(pkg->origin == PKG_FROM_LOCALDB
|
||||||
&& !(pkg->infolevel & INFRQ_FILES)) {
|
&& !(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;
|
return pkg->backup;
|
||||||
}
|
}
|
||||||
@ -340,31 +340,7 @@ static int is_dir(const char *path, struct dirent *entry)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
pmdb_t *_alpm_db_register_local(void)
|
int _alpm_local_db_populate(pmdb_t *db)
|
||||||
{
|
|
||||||
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 count = 0;
|
int count = 0;
|
||||||
struct dirent *ent = NULL;
|
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 */
|
/* 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_log(PM_LOG_ERROR, _("corrupted database entry '%s'\n"), name);
|
||||||
_alpm_pkg_free(pkg);
|
_alpm_pkg_free(pkg);
|
||||||
continue;
|
continue;
|
||||||
@ -434,7 +410,7 @@ int _alpm_db_populate(pmdb_t *db)
|
|||||||
return(count);
|
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;
|
FILE *fp = NULL;
|
||||||
char path[PATH_MAX];
|
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) {
|
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);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -982,4 +958,33 @@ int _alpm_local_db_remove(pmdb_t *db, pmpkg_t *info)
|
|||||||
return(ret);
|
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: */
|
/* vim: set ts=2 sw=2 noet: */
|
||||||
|
@ -39,14 +39,13 @@
|
|||||||
#include "deps.h"
|
#include "deps.h"
|
||||||
#include "dload.h"
|
#include "dload.h"
|
||||||
|
|
||||||
|
|
||||||
#define LAZY_LOAD(info, errret) \
|
#define LAZY_LOAD(info, errret) \
|
||||||
do { \
|
do { \
|
||||||
ALPM_LOG_FUNC; \
|
ALPM_LOG_FUNC; \
|
||||||
ASSERT(handle != NULL, return(errret)); \
|
ASSERT(handle != NULL, return(errret)); \
|
||||||
ASSERT(pkg != NULL, return(errret)); \
|
ASSERT(pkg != NULL, return(errret)); \
|
||||||
if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & info)) { \
|
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)
|
} while(0)
|
||||||
|
|
||||||
@ -199,7 +198,7 @@ alpm_list_t *_sync_cache_get_files(pmpkg_t *pkg)
|
|||||||
|
|
||||||
if(pkg->origin == PKG_FROM_LOCALDB
|
if(pkg->origin == PKG_FROM_LOCALDB
|
||||||
&& !(pkg->infolevel & INFRQ_FILES)) {
|
&& !(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;
|
return pkg->files;
|
||||||
}
|
}
|
||||||
@ -214,7 +213,7 @@ alpm_list_t *_sync_cache_get_backup(pmpkg_t *pkg)
|
|||||||
|
|
||||||
if(pkg->origin == PKG_FROM_LOCALDB
|
if(pkg->origin == PKG_FROM_LOCALDB
|
||||||
&& !(pkg->infolevel & INFRQ_FILES)) {
|
&& !(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;
|
return pkg->backup;
|
||||||
}
|
}
|
||||||
@ -250,33 +249,6 @@ static struct pkg_operations sync_pkg_ops = {
|
|||||||
.get_backup = _sync_cache_get_backup,
|
.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 */
|
/* create list of directories in db */
|
||||||
static int dirlist_from_tar(const char *archive, alpm_list_t **dirlist)
|
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 */
|
/* 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_log(PM_LOG_ERROR, _("corrupted database entry '%s'\n"), name);
|
||||||
_alpm_pkg_free(pkg);
|
_alpm_pkg_free(pkg);
|
||||||
continue;
|
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) {
|
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);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -903,4 +875,37 @@ error:
|
|||||||
return(-1);
|
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: */
|
/* vim: set ts=2 sw=2 noet: */
|
||||||
|
@ -43,12 +43,6 @@
|
|||||||
#include "package.h"
|
#include "package.h"
|
||||||
#include "group.h"
|
#include "group.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
|
||||||
* @{
|
* @{
|
||||||
@ -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);
|
_alpm_log(PM_LOG_DEBUG, "setting install reason %u for %s/%s\n", reason, db->treename, name);
|
||||||
/* read DESC */
|
/* read DESC */
|
||||||
if(_alpm_db_read(db, pkg, INFRQ_DESC)) {
|
if(_alpm_local_db_read(db, pkg, INFRQ_DESC)) {
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
if(pkg->reason == reason) {
|
if(pkg->reason == reason) {
|
||||||
|
@ -60,7 +60,6 @@ struct __pmdb_t {
|
|||||||
struct db_operations *ops;
|
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);
|
||||||
@ -73,12 +72,13 @@ void _alpm_db_unregister(pmdb_t *db);
|
|||||||
pmdb_t *_alpm_db_new(const char *treename, int is_local);
|
pmdb_t *_alpm_db_new(const char *treename, int is_local);
|
||||||
|
|
||||||
/* be.c, backend specific calls */
|
/* be.c, backend specific calls */
|
||||||
int _alpm_db_populate(pmdb_t *db);
|
int _alpm_local_db_populate(pmdb_t *db);
|
||||||
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);
|
||||||
|
|
||||||
int _alpm_local_db_prepare(pmdb_t *db, pmpkg_t *info);
|
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_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq);
|
||||||
int _alpm_local_db_remove(pmdb_t *db, pmpkg_t *info);
|
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 */
|
/* cache bullshit */
|
||||||
/* packages */
|
/* packages */
|
||||||
|
@ -350,7 +350,7 @@ int SYMEXPORT alpm_pkg_has_scriptlet(pmpkg_t *pkg)
|
|||||||
|
|
||||||
if(pkg->origin == PKG_FROM_LOCALDB
|
if(pkg->origin == PKG_FROM_LOCALDB
|
||||||
&& !(pkg->infolevel & INFRQ_SCRIPTLET)) {
|
&& !(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;
|
return pkg->scriptlet;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user