diff options
author | Dan McGee <dan@archlinux.org> | 2011-08-17 21:06:04 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-08-18 10:47:41 -0500 |
commit | c885a953eb888004f0302ed3eceafef93e2f072f (patch) | |
tree | 676e9d86361ba8af989d8f8277db58e261471518 /lib/libalpm/be_sync.c | |
parent | 4a7f3bbc469d1f6a8da1c7f310ab518ad841c2b9 (diff) | |
download | 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_sync.c')
-rw-r--r-- | lib/libalpm/be_sync.c | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index 7f016749..2db7ce58 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -70,28 +70,37 @@ static char *get_sync_dir(alpm_handle_t *handle) static int sync_db_validate(alpm_db_t *db) { alpm_siglevel_t level; + const char *dbpath; - if(db->status & DB_STATUS_VALID) { + if(db->status & DB_STATUS_VALID || db->status & DB_STATUS_MISSING) { return 0; } + if(db->status & DB_STATUS_INVALID) { + return -1; + } + + dbpath = _alpm_db_path(db); + if(!dbpath) { + /* pm_errno set in _alpm_db_path() */ + return -1; + } + + /* we can skip any validation if the database doesn't exist */ + if(access(dbpath, R_OK) != 0 && errno == ENOENT) { + db->status &= ~DB_STATUS_EXISTS; + db->status |= DB_STATUS_MISSING; + _alpm_log(db->handle, ALPM_LOG_WARNING, + "database file for '%s' does not exist\n", db->treename); + goto valid; + } + db->status |= DB_STATUS_EXISTS; + db->status &= ~DB_STATUS_MISSING; /* this takes into account the default verification level if UNKNOWN * was assigned to this db */ level = alpm_db_get_siglevel(db); if(level & ALPM_SIG_DATABASE) { - const char *dbpath = _alpm_db_path(db); - if(!dbpath) { - /* pm_errno set in _alpm_db_path() */ - return -1; - } - - /* we can skip any validation if the database doesn't exist */ - if(access(dbpath, R_OK) != 0 && errno == ENOENT) { - goto valid; - return 0; - } - if(_alpm_check_pgp_helper(db->handle, dbpath, NULL, level & ALPM_SIG_DATABASE_OPTIONAL, level & ALPM_SIG_DATABASE_MARGINAL_OK, level & ALPM_SIG_DATABASE_UNKNOWN_OK, ALPM_ERR_DB_INVALID_SIG)) { @@ -101,6 +110,7 @@ static int sync_db_validate(alpm_db_t *db) valid: db->status |= DB_STATUS_VALID; + db->status &= ~DB_STATUS_INVALID; return 0; } @@ -234,7 +244,12 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db) /* Cache needs to be rebuilt */ _alpm_db_free_pkgcache(db); + /* clear all status flags regarding validity/existence */ db->status &= ~DB_STATUS_VALID; + db->status &= ~DB_STATUS_INVALID; + db->status &= ~DB_STATUS_EXISTS; + db->status &= ~DB_STATUS_MISSING; + if(sync_db_validate(db)) { /* pm_errno should be set */ ret = -1; @@ -378,6 +393,13 @@ static int sync_db_populate(alpm_db_t *db) struct archive_entry *entry; alpm_pkg_t *pkg = NULL; + if(db->status & DB_STATUS_INVALID) { + RET_ERR(db->handle, ALPM_ERR_DB_INVALID, -1); + } + if(db->status & DB_STATUS_MISSING) { + RET_ERR(db->handle, ALPM_ERR_DB_NOT_FOUND, -1); + } + if((archive = archive_read_new()) == NULL) { RET_ERR(db->handle, ALPM_ERR_LIBARCHIVE, -1); } |