From 79f29ed53e495f8d0f99495c680b0db818e8c878 Mon Sep 17 00:00:00 2001 From: classabbyamp Date: Wed, 12 Apr 2023 03:05:19 -0400 Subject: [PATCH] bin/xbps-pkgdb: use -errno values for error states ...when checking a package. This will give more relevant information than before, removes a message that is misleading in many cases, and allows for some minor simplification. before: ``` $ doas xbps-pkgdb runit-void; echo $? ERROR: runit-void: hash mismatch for /etc/runit/2. ERROR: runit-void: files check FAILED. Failed to check `runit-void': Operation not permitted 1 ``` after: ``` $ doas xbps-pkgdb runit-void; echo $? ERROR: runit-void: hash mismatch for /etc/runit/2. ERROR: runit-void: files check FAILED. 1 ``` this does not change the behaviour of `xbps-pkgdb -a` --- bin/xbps-pkgdb/check.c | 6 +++--- bin/xbps-pkgdb/main.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/xbps-pkgdb/check.c b/bin/xbps-pkgdb/check.c index f2918799..f5dcf9da 100644 --- a/bin/xbps-pkgdb/check.c +++ b/bin/xbps-pkgdb/check.c @@ -100,7 +100,7 @@ check_pkg_integrity(struct xbps_handle *xhp, xbps_error_printf("%s: cannot read %s, ignoring...\n", pkgname, buf); free(buf); - return -1; + return -ENOENT; } rv = xbps_file_sha256_check(buf, sha256); free(buf); @@ -112,7 +112,7 @@ check_pkg_integrity(struct xbps_handle *xhp, xbps_object_release(filesd); xbps_error_printf("%s: metadata file has been " "modified!\n", pkgname); - return 1; + return -rv; } } @@ -135,5 +135,5 @@ do { \ #undef RUN_PKG_CHECK - return errors ? EXIT_FAILURE : EXIT_SUCCESS; + return errors; } diff --git a/bin/xbps-pkgdb/main.c b/bin/xbps-pkgdb/main.c index d1a5649c..48751e98 100644 --- a/bin/xbps-pkgdb/main.c +++ b/bin/xbps-pkgdb/main.c @@ -183,9 +183,9 @@ main(int argc, char **argv) } else { for (i = optind; i < argc; i++) { rv = check_pkg_integrity(&xh, NULL, argv[i]); - if (rv != 0) + if (rv < 0) xbps_error_printf("Failed to check " - "`%s': %s\n", argv[i], strerror(rv)); + "`%s': %s\n", argv[i], strerror(-rv)); } }