From 8ee084dbb33a9a9fee77376f5fac07f331a24ef8 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Sat, 5 Dec 2015 05:46:08 -0500 Subject: db_update: always clear db flags after update Signature downloading and DB validation was being based on the most recent download status for the DB. If a DB successfully downloaded but a signature did not, db_update would move to the next server. If the next server tried does not have a more recent copy of the DB, db_update would not download the DB again and would forget that the DB had previously been updated. In this case it would skip validation entirely, leaving an updated DB with the original validation status. Signed-off-by: Andrew Gregory Signed-off-by: Allan McRae --- lib/libalpm/be_sync.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'lib/libalpm') diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index b09b0608..200e3817 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -177,6 +177,7 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db) char *syncpath; const char *dbext; alpm_list_t *i; + int updated = 0; int ret = -1; mode_t oldmask; alpm_handle_t *handle; @@ -239,8 +240,9 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db) ret = _alpm_download(&payload, syncpath, NULL, &final_db_url); _alpm_dload_payload_reset(&payload); + updated = (updated || ret == 0); - if(ret == 0 && (level & ALPM_SIG_DATABASE)) { + if(ret != -1 && updated && (level & ALPM_SIG_DATABASE)) { /* an existing sig file is no good at this point */ char *sigpath = _alpm_sigpath(handle, _alpm_db_path(db)); if(!sigpath) { @@ -296,32 +298,31 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db) } } - if(ret == 1) { - /* files match, do nothing */ - handle->pm_errno = 0; - goto cleanup; - } else if(ret == -1) { - /* pm_errno was set by the download code */ - _alpm_log(handle, ALPM_LOG_DEBUG, "failed to sync db: %s\n", - alpm_strerror(handle->pm_errno)); - goto cleanup; - } + if(updated) { + /* Cache needs to be rebuilt */ + _alpm_db_free_pkgcache(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; - /* 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 the download failed skip validation to preserve the download error */ + if(ret != -1 && sync_db_validate(db) != 0) { + /* pm_errno should be set */ + ret = -1; + } + } - if(sync_db_validate(db)) { - /* pm_errno should be set */ - ret = -1; + if(ret == -1) { + /* pm_errno was set by the download code */ + _alpm_log(handle, ALPM_LOG_DEBUG, "failed to sync db: %s\n", + alpm_strerror(handle->pm_errno)); + } else { + handle->pm_errno = 0; } -cleanup: _alpm_handle_unlock(handle); free(syncpath); umask(oldmask); -- cgit v1.2.3-70-g09d2