[pacman-dev] [PATCH 2/2] Change if-else chain to switch

David Phillips david at sighup.nz
Mon Sep 10 00:59:37 UTC 2018


---
 lib/libalpm/sync.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 85f70200..faef7b56 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -1176,21 +1176,28 @@ static int check_validity(alpm_handle_t *handle,
 	if(errors) {
 		for(i = errors; i; i = i->next) {
 			struct validity *v = i->data;
-			if(v->error == ALPM_ERR_PKG_MISSING_SIG) {
+			switch(v->error) {
+			case ALPM_ERR_PKG_MISSING_SIG:
 				_alpm_log(handle, ALPM_LOG_ERROR,
 						_("%s: missing required signature\n"), v->pkg->name);
-			} else if(v->error == ALPM_ERR_PKG_INVALID_SIG) {
+				break;
+			case ALPM_ERR_PKG_INVALID_SIG:
 				_alpm_process_siglist(handle, v->pkg->name, v->siglist,
 						v->siglevel & ALPM_SIG_PACKAGE_OPTIONAL,
 						v->siglevel & ALPM_SIG_PACKAGE_MARGINAL_OK,
 						v->siglevel & ALPM_SIG_PACKAGE_UNKNOWN_OK);
+				/* fallthrough */
+			case ALPM_ERR_PKG_INVALID_CHECKSUM:
 				prompt_to_delete(handle, v->path, v->error);
-			} else if(v->error == ALPM_ERR_PKG_INVALID_CHECKSUM) {
-				prompt_to_delete(handle, v->path, v->error);
-			} else if(v->error == ALPM_ERR_PKG_NOT_FOUND ||
-			          v->error == ALPM_ERR_BADPERMS ||
-			          v->error == ALPM_ERR_PKG_OPEN) {
+				break;
+			case ALPM_ERR_PKG_NOT_FOUND:
+			case ALPM_ERR_BADPERMS:
+			case ALPM_ERR_PKG_OPEN:
 				_alpm_log(handle, ALPM_LOG_ERROR, _("error while reading file %s: %s\n"), v->path, alpm_strerror(v->error));
+				break;
+			default:
+				/* ignore */
+				break;
 			}
 			alpm_siglist_cleanup(v->siglist);
 			free(v->siglist);
-- 
2.18.0


More information about the pacman-dev mailing list