Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/alpm.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/alpm.c')
-rw-r--r--lib/libalpm/alpm.c60
1 files changed, 35 insertions, 25 deletions
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index 8dacc61e..19e26363 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -102,12 +102,12 @@ int alpm_release()
/* close local database */
if(handle->db_local) {
- _alpm_db_close(handle->db_local);
+ alpm_db_unregister(handle->db_local);
handle->db_local = NULL;
}
/* and also sync ones */
for(i = handle->dbs_sync; i; i = i->next) {
- _alpm_db_close(i->data);
+ alpm_db_unregister(i->data);
i->data = NULL;
}
@@ -161,7 +161,6 @@ int alpm_get_option(unsigned char parm, long *data)
*/
pmdb_t *alpm_db_register(char *treename)
{
- char path[PATH_MAX];
struct stat buf;
pmdb_t *db;
int found = 0;
@@ -189,16 +188,23 @@ pmdb_t *alpm_db_register(char *treename)
RET_ERR(PM_ERR_DB_NOT_NULL, NULL);
}
+ _alpm_log(PM_LOG_FLOW1, "registering database '%s'", treename);
+
+ db = _alpm_db_new(handle->root, handle->dbpath, treename);
+ if(db == NULL) {
+ return(NULL);
+ }
+
/* make sure the database directory exists */
- snprintf(path, PATH_MAX, "%s%s", handle->root, handle->dbpath);
- if(stat(path, &buf) != 0 || !S_ISDIR(buf.st_mode)) {
- if(_alpm_makepath(path) != 0) {
+ if(stat(db->path, &buf) != 0 || !S_ISDIR(buf.st_mode)) {
+ if(_alpm_makepath(db->path) != 0) {
RET_ERR(PM_ERR_SYSTEM, NULL);
}
}
- db = _alpm_db_open(path, treename, DB_O_CREATE);
- if(db == NULL) {
+ _alpm_log(PM_LOG_DEBUG, "opening database '%s'", db->treename);
+ if(_alpm_db_open(db, DB_O_CREATE) == -1) {
+ _alpm_db_free(db);
RET_ERR(PM_ERR_DB_OPEN, NULL);
}
@@ -238,14 +244,12 @@ int alpm_db_unregister(pmdb_t *db)
ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, -1));
if(db == handle->db_local) {
- _alpm_db_close(handle->db_local);
handle->db_local = NULL;
found = 1;
} else {
pmdb_t *data;
handle->dbs_sync = _alpm_list_remove(handle->dbs_sync, db, db_cmp, (void **)&data);
if(data) {
- _alpm_db_close(data);
found = 1;
}
}
@@ -254,6 +258,16 @@ int alpm_db_unregister(pmdb_t *db)
RET_ERR(PM_ERR_DB_NOT_FOUND, -1);
}
+ _alpm_log(PM_LOG_FLOW1, "unregistering database '%s'", db->treename);
+
+ /* Cleanup */
+ _alpm_db_free_pkgcache(db);
+
+ _alpm_log(PM_LOG_DEBUG, "closing database '%s'", db->treename);
+ _alpm_db_close(db);
+
+ _alpm_db_free(db);
+
return(0);
}
@@ -419,9 +433,8 @@ void *alpm_pkg_getinfo(pmpkg_t *pkg, unsigned char parm)
case PM_PKG_REASON:
case PM_PKG_MD5SUM:
if(!(pkg->infolevel & INFRQ_DESC)) {
- char target[PKG_FULLNAME_LEN];
- snprintf(target, PKG_FULLNAME_LEN, "%s-%s", pkg->name, pkg->version);
- _alpm_db_read(pkg->data, target, INFRQ_DESC, pkg);
+ _alpm_log(PM_LOG_DEBUG, "loading DESC info for '%s'", pkg->name);
+ _alpm_db_read(pkg->data, INFRQ_DESC, pkg);
}
break;*/
/* Depends entry */
@@ -432,26 +445,23 @@ void *alpm_pkg_getinfo(pmpkg_t *pkg, unsigned char parm)
case PM_PKG_PROVIDES:
case PM_PKG_REPLACES:
if(!(pkg->infolevel & INFRQ_DEPENDS)) {
- char target[PKG_FULLNAME_LEN];
- snprintf(target, PKG_FULLNAME_LEN, "%s-%s", pkg->name, pkg->version);
- _alpm_db_read(pkg->data, target, INFRQ_DEPENDS, pkg);
+ _alpm_log(PM_LOG_DEBUG, "loading DEPENDS info for '%s'", pkg->name);
+ _alpm_db_read(pkg->data, INFRQ_DEPENDS, pkg);
}
break;*/
/* Files entry */
case PM_PKG_FILES:
case PM_PKG_BACKUP:
if(pkg->data == handle->db_local && !(pkg->infolevel & INFRQ_FILES)) {
- char target[PKG_FULLNAME_LEN];
- snprintf(target, PKG_FULLNAME_LEN, "%s-%s", pkg->name, pkg->version);
- _alpm_db_read(pkg->data, target, INFRQ_FILES, pkg);
+ _alpm_log(PM_LOG_DEBUG, "loading FILES info for '%s'", pkg->name);
+ _alpm_db_read(pkg->data, INFRQ_FILES, pkg);
}
break;
/* Scriptlet */
case PM_PKG_SCRIPLET:
if(pkg->data == handle->db_local && !(pkg->infolevel & INFRQ_SCRIPLET)) {
- char target[PKG_FULLNAME_LEN];
- snprintf(target, PKG_FULLNAME_LEN, "%s-%s", pkg->name, pkg->version);
- _alpm_db_read(pkg->data, target, INFRQ_SCRIPLET, pkg);
+ _alpm_log(PM_LOG_DEBUG, "loading SCRIPLET info for '%s'", pkg->name);
+ _alpm_db_read(pkg->data, INFRQ_SCRIPLET, pkg);
}
break;
}
@@ -535,6 +545,7 @@ int alpm_pkg_checkmd5sum(pmpkg_t *pkg)
int retval = 0;
ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ /* We only inspect packages from sync repositories */
ASSERT(pkg->origin == PKG_FROM_CACHE, RET_ERR(PM_ERR_PKG_INVALID, -1));
ASSERT(pkg->data != handle->db_local, RET_ERR(PM_ERR_PKG_INVALID, -1));
@@ -550,9 +561,8 @@ int alpm_pkg_checkmd5sum(pmpkg_t *pkg)
retval = -1;
} else {
if(!(pkg->infolevel & INFRQ_DESC)) {
- char target[PKG_FULLNAME_LEN];
- snprintf(target, PKG_FULLNAME_LEN, "%s-%s", pkg->name, pkg->version);
- _alpm_db_read(pkg->data, target, INFRQ_DESC, pkg);
+ _alpm_log(PM_LOG_DEBUG, "loading DESC info for '%s'", pkg->name);
+ _alpm_db_read(pkg->data, INFRQ_DESC, pkg);
}
if(strcmp(md5sum, pkg->md5sum) == 0) {