summaryrefslogtreecommitdiff
path: root/lib/libalpm/be_local.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/be_local.c')
-rw-r--r--lib/libalpm/be_local.c111
1 files changed, 58 insertions, 53 deletions
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 4b2a3017..0ff51deb 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -314,6 +314,56 @@ static int is_dir(const char *path, struct dirent *entry)
return 0;
}
+static int local_db_validate(pmdb_t *db)
+{
+ struct dirent *ent = NULL;
+ const char *dbpath;
+ DIR *dbdir;
+ int ret = -1;
+
+ dbpath = _alpm_db_path(db);
+ if(dbpath == NULL) {
+ RET_ERR(db->handle, PM_ERR_DB_OPEN, -1);
+ }
+ dbdir = opendir(dbpath);
+ if(dbdir == NULL) {
+ if(errno == ENOENT) {
+ /* database dir doesn't exist yet */
+ return 0;
+ } else {
+ RET_ERR(db->handle, PM_ERR_DB_OPEN, -1);
+ }
+ }
+
+ while((ent = readdir(dbdir)) != NULL) {
+ const char *name = ent->d_name;
+ char path[PATH_MAX];
+
+ if(strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
+ continue;
+ }
+ if(!is_dir(dbpath, ent)) {
+ continue;
+ }
+
+ snprintf(path, PATH_MAX, "%s%s/depends", dbpath, name);
+ if(access(path, F_OK) == 0) {
+ /* we found a depends file- bail */
+ db->handle->pm_errno = PM_ERR_DB_VERSION;
+ goto done;
+ }
+ }
+ /* we found no depends file after full scan */
+ ret = 0;
+
+done:
+ if(dbdir) {
+ closedir(dbdir);
+ }
+
+ return ret;
+}
+
static int local_db_populate(pmdb_t *db)
{
size_t est_count;
@@ -328,6 +378,7 @@ static int local_db_populate(pmdb_t *db)
/* pm_errno set in _alpm_db_path() */
return -1;
}
+
dbdir = opendir(dbpath);
if(dbdir == NULL) {
if(errno == ENOENT) {
@@ -867,62 +918,9 @@ int _alpm_local_db_remove(pmdb_t *db, pmpkg_t *info)
return ret;
}
-static int local_db_version(pmdb_t *db)
-{
- struct dirent *ent = NULL;
- const char *dbpath;
- DIR *dbdir;
- int version;
-
- dbpath = _alpm_db_path(db);
- if(dbpath == NULL) {
- RET_ERR(db->handle, PM_ERR_DB_OPEN, -1);
- }
- dbdir = opendir(dbpath);
- if(dbdir == NULL) {
- if(errno == ENOENT) {
- /* database dir doesn't exist yet */
- version = 2;
- goto done;
- } else {
- RET_ERR(db->handle, PM_ERR_DB_OPEN, -1);
- }
- }
-
- while((ent = readdir(dbdir)) != NULL) {
- const char *name = ent->d_name;
- char path[PATH_MAX];
-
- if(strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
- continue;
- }
- if(!is_dir(dbpath, ent)) {
- continue;
- }
-
- snprintf(path, PATH_MAX, "%s%s/depends", dbpath, name);
- if(access(path, F_OK) == 0) {
- /* we found a depends file- bail */
- version = 1;
- goto done;
- }
- }
- /* we found no depends file after full scan */
- version = 2;
-
-done:
- if(dbdir) {
- closedir(dbdir);
- }
-
- _alpm_log(db->handle, PM_LOG_DEBUG, "local database version %d\n", version);
- return version;
-}
-
struct db_operations local_db_ops = {
.populate = local_db_populate,
.unregister = _alpm_db_unregister,
- .version = local_db_version,
};
pmdb_t *_alpm_db_register_local(pmhandle_t *handle)
@@ -933,11 +931,18 @@ pmdb_t *_alpm_db_register_local(pmhandle_t *handle)
db = _alpm_db_new("local", 1);
if(db == NULL) {
+ handle->pm_errno = PM_ERR_DB_CREATE;
return NULL;
}
db->ops = &local_db_ops;
db->handle = handle;
+ if(local_db_validate(db)) {
+ /* pm_errno set in local_db_validate() */
+ _alpm_db_free(db);
+ return NULL;
+ }
+
handle->db_local = db;
return db;
}