summaryrefslogtreecommitdiffstats
path: root/lib/libalpm
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2010-10-09 12:16:15 +0200
committerAllan McRae <allan@archlinux.org>2010-10-14 05:17:39 +0200
commitfc32faaa6ab4081e2046b2a81e4f9949af2f7282 (patch)
treeb800c442e7ec22e2a3f96dd8f56212ee1d5300c1 /lib/libalpm
parent5b2de3d8ecceea0eed3124e50792400adce4e95a (diff)
downloadpacman-fc32faaa6ab4081e2046b2a81e4f9949af2f7282.tar.gz
pacman-fc32faaa6ab4081e2046b2a81e4f9949af2f7282.tar.xz
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')
-rw-r--r--lib/libalpm/add.c2
-rw-r--r--lib/libalpm/be_local.c67
-rw-r--r--lib/libalpm/be_sync.c71
-rw-r--r--lib/libalpm/db.c8
-rw-r--r--lib/libalpm/db.h8
-rw-r--r--lib/libalpm/package.c2
6 files changed, 81 insertions, 77 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 3e5e8c59..2b6b019b 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -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",
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 2cd8ae14..d5378cfb 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -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: */
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: */
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index 68e9ba7b..2e6bf31b 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -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) {
diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index 8adbc5d1..72801115 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -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 */
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 682ff90c..09bf78eb 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -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;
}