Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/be_sync.c
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2010-10-09 20:16:15 +1000
committerAllan McRae <allan@archlinux.org>2010-10-14 13:17:39 +1000
commitfc32faaa6ab4081e2046b2a81e4f9949af2f7282 (patch)
treeb800c442e7ec22e2a3f96dd8f56212ee1d5300c1 /lib/libalpm/be_sync.c
parent5b2de3d8ecceea0eed3124e50792400adce4e95a (diff)
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>
Diffstat (limited to 'lib/libalpm/be_sync.c')
-rw-r--r--lib/libalpm/be_sync.c71
1 files changed, 38 insertions, 33 deletions
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index a38e91a7..5c929bdb 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -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: */