Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2015-12-05 05:46:08 -0500
committerAllan McRae <allan@archlinux.org>2015-12-06 00:15:35 +1000
commit8ee084dbb33a9a9fee77376f5fac07f331a24ef8 (patch)
tree4e888a17fa665e964d8f60efa0d5358602f7ddb1
parentd069d9714af61749666ca4caa31ef66cfa35ee86 (diff)
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 <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
-rw-r--r--lib/libalpm/be_sync.c45
1 files changed, 23 insertions, 22 deletions
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);