Use GOTO_ERR throughout

The GOTO_ERR define was added in commit 80ae8014 for use in future commits.
There are plenty of places in the code base it can be used, so convert them.

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Allan McRae 2020-04-13 22:24:23 +10:00
parent 0eda92c5d4
commit 6ba250e400
6 changed files with 22 additions and 41 deletions

View file

@ -256,8 +256,7 @@ static struct archive *_cache_mtree_open(alpm_pkg_t *pkg)
} }
if((mtree = archive_read_new()) == NULL) { if((mtree = archive_read_new()) == NULL) {
pkg->handle->pm_errno = ALPM_ERR_LIBARCHIVE; GOTO_ERR(pkg->handle, ALPM_ERR_LIBARCHIVE, error);
goto error;
} }
_alpm_archive_read_support_filter_all(mtree); _alpm_archive_read_support_filter_all(mtree);
@ -266,9 +265,8 @@ static struct archive *_cache_mtree_open(alpm_pkg_t *pkg)
if((r = _alpm_archive_read_open_file(mtree, mtfile, ALPM_BUFFER_SIZE))) { if((r = _alpm_archive_read_open_file(mtree, mtfile, ALPM_BUFFER_SIZE))) {
_alpm_log(pkg->handle, ALPM_LOG_ERROR, _("error while reading file %s: %s\n"), _alpm_log(pkg->handle, ALPM_LOG_ERROR, _("error while reading file %s: %s\n"),
mtfile, archive_error_string(mtree)); mtfile, archive_error_string(mtree));
pkg->handle->pm_errno = ALPM_ERR_LIBARCHIVE;
_alpm_archive_read_free(mtree); _alpm_archive_read_free(mtree);
goto error; GOTO_ERR(pkg->handle, ALPM_ERR_LIBARCHIVE, error);
} }
free(mtfile); free(mtfile);

View file

@ -459,8 +459,7 @@ static int build_filelist_from_mtree(alpm_handle_t *handle, alpm_pkg_t *pkg, str
/* create a new archive to parse the mtree and load it from archive into memory */ /* create a new archive to parse the mtree and load it from archive into memory */
/* TODO: split this into a function */ /* TODO: split this into a function */
if((mtree = archive_read_new()) == NULL) { if((mtree = archive_read_new()) == NULL) {
handle->pm_errno = ALPM_ERR_LIBARCHIVE; GOTO_ERR(handle, ALPM_ERR_LIBARCHIVE, error);
goto error;
} }
_alpm_archive_read_support_filter_all(mtree); _alpm_archive_read_support_filter_all(mtree);
@ -479,8 +478,7 @@ static int build_filelist_from_mtree(alpm_handle_t *handle, alpm_pkg_t *pkg, str
if(size < 0) { if(size < 0) {
_alpm_log(handle, ALPM_LOG_DEBUG, _("error while reading package %s: %s\n"), _alpm_log(handle, ALPM_LOG_DEBUG, _("error while reading package %s: %s\n"),
pkg->filename, archive_error_string(archive)); pkg->filename, archive_error_string(archive));
handle->pm_errno = ALPM_ERR_LIBARCHIVE; GOTO_ERR(handle, ALPM_ERR_LIBARCHIVE, error);
goto error;
} }
if(size == 0) { if(size == 0) {
break; break;
@ -493,8 +491,7 @@ static int build_filelist_from_mtree(alpm_handle_t *handle, alpm_pkg_t *pkg, str
_alpm_log(handle, ALPM_LOG_DEBUG, _alpm_log(handle, ALPM_LOG_DEBUG,
_("error while reading mtree of package %s: %s\n"), _("error while reading mtree of package %s: %s\n"),
pkg->filename, archive_error_string(mtree)); pkg->filename, archive_error_string(mtree));
handle->pm_errno = ALPM_ERR_LIBARCHIVE; GOTO_ERR(handle, ALPM_ERR_LIBARCHIVE, error);
goto error;
} }
while((ret = archive_read_next_header(mtree, &mtree_entry)) == ARCHIVE_OK) { while((ret = archive_read_next_header(mtree, &mtree_entry)) == ARCHIVE_OK) {
@ -517,8 +514,7 @@ static int build_filelist_from_mtree(alpm_handle_t *handle, alpm_pkg_t *pkg, str
if(ret != ARCHIVE_EOF && ret != ARCHIVE_OK) { /* An error occurred */ if(ret != ARCHIVE_EOF && ret != ARCHIVE_OK) { /* An error occurred */
_alpm_log(handle, ALPM_LOG_DEBUG, _("error while reading mtree of package %s: %s\n"), _alpm_log(handle, ALPM_LOG_DEBUG, _("error while reading mtree of package %s: %s\n"),
pkg->filename, archive_error_string(mtree)); pkg->filename, archive_error_string(mtree));
handle->pm_errno = ALPM_ERR_LIBARCHIVE; GOTO_ERR(handle, ALPM_ERR_LIBARCHIVE, error);
goto error;
} }
/* throw away any files we loaded directly from the archive */ /* throw away any files we loaded directly from the archive */
@ -583,11 +579,9 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
newpkg = _alpm_pkg_new(); newpkg = _alpm_pkg_new();
if(newpkg == NULL) { if(newpkg == NULL) {
handle->pm_errno = ALPM_ERR_MEMORY; GOTO_ERR(handle, ALPM_ERR_MEMORY, error);
goto error;
} }
STRDUP(newpkg->filename, pkgfile, STRDUP(newpkg->filename, pkgfile, GOTO_ERR(handle, ALPM_ERR_MEMORY, error));
handle->pm_errno = ALPM_ERR_MEMORY; goto error);
newpkg->size = st.st_size; newpkg->size = st.st_size;
_alpm_log(handle, ALPM_LOG_DEBUG, "starting package load for %s\n", pkgfile); _alpm_log(handle, ALPM_LOG_DEBUG, "starting package load for %s\n", pkgfile);
@ -637,8 +631,7 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
if(archive_read_data_skip(archive)) { if(archive_read_data_skip(archive)) {
_alpm_log(handle, ALPM_LOG_ERROR, _("error while reading package %s: %s\n"), _alpm_log(handle, ALPM_LOG_ERROR, _("error while reading package %s: %s\n"),
pkgfile, archive_error_string(archive)); pkgfile, archive_error_string(archive));
handle->pm_errno = ALPM_ERR_LIBARCHIVE; GOTO_ERR(handle, ALPM_ERR_LIBARCHIVE, error);
goto error;
} }
/* if we are not doing a full read, see if we have all we need */ /* if we are not doing a full read, see if we have all we need */
@ -650,8 +643,7 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
if(ret != ARCHIVE_EOF && ret != ARCHIVE_OK) { /* An error occurred */ if(ret != ARCHIVE_EOF && ret != ARCHIVE_OK) { /* An error occurred */
_alpm_log(handle, ALPM_LOG_ERROR, _("error while reading package %s: %s\n"), _alpm_log(handle, ALPM_LOG_ERROR, _("error while reading package %s: %s\n"),
pkgfile, archive_error_string(archive)); pkgfile, archive_error_string(archive));
handle->pm_errno = ALPM_ERR_LIBARCHIVE; GOTO_ERR(handle, ALPM_ERR_LIBARCHIVE, error);
goto error;
} }
if(!config) { if(!config) {

View file

@ -464,9 +464,8 @@ static int sync_db_populate(alpm_db_t *db)
db->pkgcache = _alpm_pkghash_create(est_count); db->pkgcache = _alpm_pkghash_create(est_count);
if(db->pkgcache == NULL) { if(db->pkgcache == NULL) {
db->handle->pm_errno = ALPM_ERR_MEMORY;
ret = -1; ret = -1;
goto cleanup; GOTO_ERR(db->handle, ALPM_ERR_MEMORY, cleanup);
} }
while((archive_ret = archive_read_next_header(archive, &entry)) == ARCHIVE_OK) { while((archive_ret = archive_read_next_header(archive, &entry)) == ARCHIVE_OK) {
@ -485,9 +484,8 @@ static int sync_db_populate(alpm_db_t *db)
_alpm_log(db->handle, ALPM_LOG_ERROR, _("could not read db '%s' (%s)\n"), _alpm_log(db->handle, ALPM_LOG_ERROR, _("could not read db '%s' (%s)\n"),
db->treename, archive_error_string(archive)); db->treename, archive_error_string(archive));
_alpm_db_free_pkgcache(db); _alpm_db_free_pkgcache(db);
db->handle->pm_errno = ALPM_ERR_LIBARCHIVE;
ret = -1; ret = -1;
goto cleanup; GOTO_ERR(db->handle, ALPM_ERR_LIBARCHIVE, cleanup);
} }
count = alpm_list_count(db->pkgcache->list); count = alpm_list_count(db->pkgcache->list);

View file

@ -424,11 +424,10 @@ static int curl_download_internal(struct dload_payload *payload,
if(localf == NULL) { if(localf == NULL) {
localf = fopen(payload->tempfile_name, payload->tempfile_openmode); localf = fopen(payload->tempfile_name, payload->tempfile_openmode);
if(localf == NULL) { if(localf == NULL) {
handle->pm_errno = ALPM_ERR_RETRIEVE;
_alpm_log(handle, ALPM_LOG_ERROR, _alpm_log(handle, ALPM_LOG_ERROR,
_("could not open file %s: %s\n"), _("could not open file %s: %s\n"),
payload->tempfile_name, strerror(errno)); payload->tempfile_name, strerror(errno));
goto cleanup; GOTO_ERR(handle, ALPM_ERR_RETRIEVE, cleanup);
} }
} }
@ -535,10 +534,9 @@ static int curl_download_internal(struct dload_payload *payload,
* as actually being transferred during curl_easy_perform() */ * as actually being transferred during curl_easy_perform() */
if(!DOUBLE_EQ(remote_size, -1) && !DOUBLE_EQ(bytes_dl, -1) && if(!DOUBLE_EQ(remote_size, -1) && !DOUBLE_EQ(bytes_dl, -1) &&
!DOUBLE_EQ(bytes_dl, remote_size)) { !DOUBLE_EQ(bytes_dl, remote_size)) {
handle->pm_errno = ALPM_ERR_RETRIEVE;
_alpm_log(handle, ALPM_LOG_ERROR, _("%s appears to be truncated: %jd/%jd bytes\n"), _alpm_log(handle, ALPM_LOG_ERROR, _("%s appears to be truncated: %jd/%jd bytes\n"),
payload->remote_name, (intmax_t)bytes_dl, (intmax_t)remote_size); payload->remote_name, (intmax_t)bytes_dl, (intmax_t)remote_size);
goto cleanup; GOTO_ERR(handle, ALPM_ERR_RETRIEVE, cleanup);
} }
if(payload->trust_remote_name) { if(payload->trust_remote_name) {

View file

@ -586,16 +586,14 @@ int _alpm_gpgme_checksig(alpm_handle_t *handle, const char *path,
|| (sigfile = fopen(sigpath, "rb")) == NULL) { || (sigfile = fopen(sigpath, "rb")) == NULL) {
_alpm_log(handle, ALPM_LOG_DEBUG, "sig path %s could not be opened\n", _alpm_log(handle, ALPM_LOG_DEBUG, "sig path %s could not be opened\n",
sigpath); sigpath);
handle->pm_errno = ALPM_ERR_SIG_MISSING; GOTO_ERR(handle, ALPM_ERR_SIG_MISSING, error);
goto error;
} }
} }
/* does the file we are verifying exist? */ /* does the file we are verifying exist? */
file = fopen(path, "rb"); file = fopen(path, "rb");
if(file == NULL) { if(file == NULL) {
handle->pm_errno = ALPM_ERR_NOT_A_FILE; GOTO_ERR(handle, ALPM_ERR_NOT_A_FILE, error);
goto error;
} }
if(init_gpgme(handle)) { if(init_gpgme(handle)) {
@ -619,8 +617,7 @@ int _alpm_gpgme_checksig(alpm_handle_t *handle, const char *path,
int decode_ret = alpm_decode_signature(base64_sig, int decode_ret = alpm_decode_signature(base64_sig,
&decoded_sigdata, &data_len); &decoded_sigdata, &data_len);
if(decode_ret) { if(decode_ret) {
handle->pm_errno = ALPM_ERR_SIG_INVALID; GOTO_ERR(handle, ALPM_ERR_SIG_INVALID, error);
goto gpg_error;
} }
gpg_err = gpgme_data_new_from_mem(&sigdata, gpg_err = gpgme_data_new_from_mem(&sigdata,
(char *)decoded_sigdata, data_len, 0); (char *)decoded_sigdata, data_len, 0);
@ -637,15 +634,14 @@ int _alpm_gpgme_checksig(alpm_handle_t *handle, const char *path,
CHECK_ERR(); CHECK_ERR();
if(!verify_result || !verify_result->signatures) { if(!verify_result || !verify_result->signatures) {
_alpm_log(handle, ALPM_LOG_DEBUG, "no signatures returned\n"); _alpm_log(handle, ALPM_LOG_DEBUG, "no signatures returned\n");
handle->pm_errno = ALPM_ERR_SIG_MISSING; GOTO_ERR(handle, ALPM_ERR_SIG_MISSING, gpg_error);
goto gpg_error;
} }
for(gpgsig = verify_result->signatures, sigcount = 0; for(gpgsig = verify_result->signatures, sigcount = 0;
gpgsig; gpgsig = gpgsig->next, sigcount++); gpgsig; gpgsig = gpgsig->next, sigcount++);
_alpm_log(handle, ALPM_LOG_DEBUG, "%d signatures returned\n", sigcount); _alpm_log(handle, ALPM_LOG_DEBUG, "%d signatures returned\n", sigcount);
CALLOC(siglist->results, sigcount, sizeof(alpm_sigresult_t), CALLOC(siglist->results, sigcount, sizeof(alpm_sigresult_t),
handle->pm_errno = ALPM_ERR_MEMORY; goto gpg_error); GOTO_ERR(handle, ALPM_ERR_MEMORY, gpg_error));
siglist->count = sigcount; siglist->count = sigcount;
for(gpgsig = verify_result->signatures, sigcount = 0; gpgsig; for(gpgsig = verify_result->signatures, sigcount = 0; gpgsig;
@ -682,7 +678,7 @@ int _alpm_gpgme_checksig(alpm_handle_t *handle, const char *path,
gpg_err = GPG_ERR_NO_ERROR; gpg_err = GPG_ERR_NO_ERROR;
/* we dupe the fpr in this case since we have no key to point at */ /* we dupe the fpr in this case since we have no key to point at */
STRDUP(result->key.fingerprint, gpgsig->fpr, STRDUP(result->key.fingerprint, gpgsig->fpr,
handle->pm_errno = ALPM_ERR_MEMORY; goto gpg_error); GOTO_ERR(handle, ALPM_ERR_MEMORY, gpg_error));
} else { } else {
CHECK_ERR(); CHECK_ERR();
if(key->uids) { if(key->uids) {

View file

@ -456,11 +456,10 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
} }
} else { } else {
/* pm_errno was set by resolvedeps, callback may have overwrote it */ /* pm_errno was set by resolvedeps, callback may have overwrote it */
handle->pm_errno = ALPM_ERR_UNSATISFIED_DEPS;
alpm_list_free(resolved); alpm_list_free(resolved);
alpm_list_free(unresolvable); alpm_list_free(unresolvable);
ret = -1; ret = -1;
goto cleanup; GOTO_ERR(handle, ALPM_ERR_UNSATISFIED_DEPS, cleanup);
} }
} }
@ -820,7 +819,7 @@ static int download_files(alpm_handle_t *handle)
const alpm_pkg_t *pkg = i->data; const alpm_pkg_t *pkg = i->data;
struct dload_payload payload = {0}; struct dload_payload payload = {0};
STRDUP(payload.remote_name, pkg->filename, handle->pm_errno = ALPM_ERR_MEMORY; goto finish); STRDUP(payload.remote_name, pkg->filename, GOTO_ERR(handle, ALPM_ERR_MEMORY, finish));
payload.servers = pkg->origin_data.db->servers; payload.servers = pkg->origin_data.db->servers;
payload.max_size = pkg->size; payload.max_size = pkg->size;