summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorXavier Chantry <shiningxc@gmail.com>2009-01-19 20:45:12 +0100
committerXavier Chantry <shiningxc@gmail.com>2009-01-20 14:04:54 +0100
commit14230869e6a37526f8a1bdb1fb88f23309b10aef (patch)
tree2edc0a14e297426af668acc54ae70f785911b98a /lib
parenteab96848376db6f54f05773a7e924faf0355137f (diff)
downloadpacman-14230869e6a37526f8a1bdb1fb88f23309b10aef.tar.xz
Remove some db abstraction crap.
These db_open and db_close looked quite useless. And they caused the db directory to be opened on a simple registering of a database. This is totally unneeded, this opening can be delayed to when we actually need it. Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/be_files.c40
-rw-r--r--lib/libalpm/db.c15
-rw-r--r--lib/libalpm/db.h3
3 files changed, 8 insertions, 50 deletions
diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c
index de906eb7..06b25a94 100644
--- a/lib/libalpm/be_files.c
+++ b/lib/libalpm/be_files.c
@@ -214,36 +214,6 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
return(0);
}
-int _alpm_db_open(pmdb_t *db)
-{
- ALPM_LOG_FUNC;
-
- if(db == NULL) {
- RET_ERR(PM_ERR_DB_NULL, -1);
- }
-
- _alpm_log(PM_LOG_DEBUG, "opening database from path '%s'\n", db->path);
- db->handle = opendir(db->path);
- if(db->handle == NULL) {
- RET_ERR(PM_ERR_DB_OPEN, -1);
- }
-
- return(0);
-}
-
-void _alpm_db_close(pmdb_t *db)
-{
- ALPM_LOG_FUNC;
-
- if(db == NULL) {
- return;
- }
-
- if(db->handle) {
- closedir(db->handle);
- db->handle = NULL;
- }
-}
static int splitname(const char *target, pmpkg_t *pkg)
{
@@ -290,13 +260,17 @@ int _alpm_db_populate(pmdb_t *db)
struct dirent *ent = NULL;
struct stat sbuf;
char path[PATH_MAX];
+ DIR *dbdir;
ALPM_LOG_FUNC;
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
- rewinddir(db->handle);
- while((ent = readdir(db->handle)) != NULL) {
+ dbdir = opendir(db->path);
+ if(dbdir == NULL) {
+ RET_ERR(PM_ERR_DB_OPEN, -1);
+ }
+ while((ent = readdir(dbdir)) != NULL) {
const char *name = ent->d_name;
pmpkg_t *pkg;
@@ -311,6 +285,7 @@ int _alpm_db_populate(pmdb_t *db)
pkg = _alpm_pkg_new();
if(pkg == NULL) {
+ closedir(dbdir);
return(-1);
}
/* split the db entry name */
@@ -336,6 +311,7 @@ int _alpm_db_populate(pmdb_t *db)
count++;
}
+ closedir(dbdir);
db->pkgcache = alpm_list_msort(db->pkgcache, count, _alpm_pkg_cmp);
return(count);
}
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index 9b91ce47..a639b1fb 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -85,9 +85,6 @@ static void _alpm_db_unregister(pmdb_t *db)
return;
}
- _alpm_log(PM_LOG_DEBUG, "closing database '%s'\n", db->treename);
- _alpm_db_close(db);
-
_alpm_log(PM_LOG_DEBUG, "unregistering database '%s'\n", db->treename);
_alpm_db_free(db);
}
@@ -466,12 +463,6 @@ pmdb_t *_alpm_db_register_local(void)
RET_ERR(PM_ERR_DB_CREATE, NULL);
}
- _alpm_log(PM_LOG_DEBUG, "opening database '%s'\n", db->treename);
- if(_alpm_db_open(db) == -1) {
- _alpm_db_free(db);
- RET_ERR(PM_ERR_DB_OPEN, NULL);
- }
-
handle->db_local = db;
return(db);
}
@@ -522,12 +513,6 @@ pmdb_t *_alpm_db_register_sync(const char *treename)
RET_ERR(PM_ERR_DB_CREATE, NULL);
}
- _alpm_log(PM_LOG_DEBUG, "opening database '%s'\n", db->treename);
- if(_alpm_db_open(db) == -1) {
- _alpm_db_free(db);
- RET_ERR(PM_ERR_DB_OPEN, NULL);
- }
-
handle->dbs_sync = alpm_list_add(handle->dbs_sync, db);
return(db);
}
diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index edc4c93e..1af16355 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -41,7 +41,6 @@ typedef enum _pmdbinfrq_t {
struct __pmdb_t {
char *path;
char *treename;
- void *handle;
unsigned short pkgcache_loaded;
alpm_list_t *pkgcache;
unsigned short grpcache_loaded;
@@ -58,8 +57,6 @@ pmdb_t *_alpm_db_register_local(void);
pmdb_t *_alpm_db_register_sync(const char *treename);
/* be.c, backend specific calls */
-int _alpm_db_open(pmdb_t *db);
-void _alpm_db_close(pmdb_t *db);
int _alpm_db_populate(pmdb_t *db);
int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq);
int _alpm_db_prepare(pmdb_t *db, pmpkg_t *info);