summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/be_local.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-08-18 04:06:04 +0200
committerDan McGee <dan@archlinux.org>2011-08-18 17:47:41 +0200
commitc885a953eb888004f0302ed3eceafef93e2f072f (patch)
tree676e9d86361ba8af989d8f8277db58e261471518 /lib/libalpm/be_local.c
parent4a7f3bbc469d1f6a8da1c7f310ab518ad841c2b9 (diff)
downloadpacman-c885a953eb888004f0302ed3eceafef93e2f072f.tar.gz
pacman-c885a953eb888004f0302ed3eceafef93e2f072f.tar.xz
Enhance and utilize database status flags
* Move is_local standalone field to status enum * Create VALID/INVALID flag pair * Create EXISTS/MISSING flag pair With these additional fields, we can be more intelligent with database loading and messages to the user. We now only warn once if a sync database does not exist and do not continue to try to load it once we have marked it as missing. The reason for the flags existing in pairs is so the unknown case can be represented. There should never be a time when both flags in the same group are true, but if they are both false, it represents the unknown case. Care is taken to always manipulate both flags at the same time. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/be_local.c')
-rw-r--r--lib/libalpm/be_local.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index a874504e..5b69f628 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -318,6 +318,9 @@ static int local_db_validate(alpm_db_t *db)
if(db->status & DB_STATUS_VALID) {
return 0;
}
+ if(db->status & DB_STATUS_INVALID) {
+ return -1;
+ }
dbpath = _alpm_db_path(db);
if(dbpath == NULL) {
@@ -328,11 +331,16 @@ static int local_db_validate(alpm_db_t *db)
if(errno == ENOENT) {
/* database dir doesn't exist yet */
db->status |= DB_STATUS_VALID;
+ db->status &= ~DB_STATUS_INVALID;
+ db->status &= ~DB_STATUS_EXISTS;
+ db->status |= DB_STATUS_MISSING;
return 0;
} else {
RET_ERR(db->handle, ALPM_ERR_DB_OPEN, -1);
}
}
+ db->status |= DB_STATUS_EXISTS;
+ db->status &= ~DB_STATUS_MISSING;
while((ent = readdir(dbdir)) != NULL) {
const char *name = ent->d_name;
@@ -348,12 +356,15 @@ static int local_db_validate(alpm_db_t *db)
snprintf(path, PATH_MAX, "%s%s/depends", dbpath, name);
if(access(path, F_OK) == 0) {
/* we found a depends file- bail */
+ db->status &= ~DB_STATUS_VALID;
+ db->status |= DB_STATUS_INVALID;
db->handle->pm_errno = ALPM_ERR_DB_VERSION;
goto done;
}
}
/* we found no depends file after full scan */
db->status |= DB_STATUS_VALID;
+ db->status &= ~DB_STATUS_INVALID;
ret = 0;
done:
@@ -373,6 +384,11 @@ static int local_db_populate(alpm_db_t *db)
const char *dbpath;
DIR *dbdir;
+ if(db->status & DB_STATUS_INVALID) {
+ RET_ERR(db->handle, ALPM_ERR_DB_INVALID, -1);
+ }
+ /* note: DB_STATUS_MISSING is not fatal for local database */
+
dbpath = _alpm_db_path(db);
if(dbpath == NULL) {
/* pm_errno set in _alpm_db_path() */
@@ -383,6 +399,8 @@ static int local_db_populate(alpm_db_t *db)
if(dbdir == NULL) {
if(errno == ENOENT) {
/* no database existing yet is not an error */
+ db->status &= ~DB_STATUS_EXISTS;
+ db->status |= DB_STATUS_MISSING;
return 0;
}
RET_ERR(db->handle, ALPM_ERR_DB_OPEN, -1);
@@ -390,6 +408,8 @@ static int local_db_populate(alpm_db_t *db)
if(fstat(dirfd(dbdir), &buf) != 0) {
RET_ERR(db->handle, ALPM_ERR_DB_OPEN, -1);
}
+ db->status |= DB_STATUS_EXISTS;
+ db->status &= ~DB_STATUS_MISSING;
if(buf.st_nlink >= 2) {
est_count = buf.st_nlink;
} else {