1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-08-13 17:03:46 -04:00

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>
This commit is contained in:
Andrew Gregory 2015-12-05 05:46:08 -05:00 committed by Allan McRae
parent d069d9714a
commit 8ee084dbb3

View File

@ -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) {
if(updated) {
/* 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 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(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;
} else {
handle->pm_errno = 0;
}
/* 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;
}
cleanup:
_alpm_handle_unlock(handle);
free(syncpath);
umask(oldmask);