Reorder some operations in sig check for efficiency

We don't need to open the data to be checked if we don't have a
signature to check against, so postpone that open until we know we have
either the base64_data or a valid signature file.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2012-01-11 12:04:34 -06:00
parent 4f02b98338
commit 6e8ca48cbb
1 changed files with 7 additions and 13 deletions

View File

@ -430,8 +430,13 @@ int _alpm_gpgme_checksig(alpm_handle_t *handle, const char *path,
if(!base64_sig) {
sigpath = _alpm_sigpath(handle, path);
/* this will just help debugging */
_alpm_access(handle, NULL, sigpath, R_OK);
if(_alpm_access(handle, NULL, sigpath, R_OK) != 0
|| (sigfile = fopen(sigpath, "rb")) == NULL) {
_alpm_log(handle, ALPM_LOG_DEBUG, "sig path %s could not be opened\n",
sigpath);
handle->pm_errno = ALPM_ERR_SIG_MISSING;
goto error;
}
}
/* does the file we are verifying exist? */
@ -441,17 +446,6 @@ int _alpm_gpgme_checksig(alpm_handle_t *handle, const char *path,
goto error;
}
/* does the sig file exist (if we didn't get the data directly)? */
if(!base64_sig) {
sigfile = fopen(sigpath, "rb");
if(sigfile == NULL) {
_alpm_log(handle, ALPM_LOG_DEBUG, "sig path %s could not be opened\n",
sigpath);
handle->pm_errno = ALPM_ERR_SIG_MISSING;
goto error;
}
}
if(init_gpgme(handle)) {
/* pm_errno was set in gpgme_init() */
goto error;