From c681005312351449761f5488f89124ecb0722475 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Fri, 12 Oct 2018 23:36:11 +0000 Subject: [PATCH] add packagehash options add -c option to check package hash add -q option to to suppress output --- zpm-packagehash.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/zpm-packagehash.c b/zpm-packagehash.c index b158780..534f6ad 100644 --- a/zpm-packagehash.c +++ b/zpm-packagehash.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "zpm.h" @@ -19,16 +20,20 @@ int main(int ac, char **av){ char *dbfile; int set = 0; + int check = 0; + int quiet = 0; dbfile = getenv("ZPMDB"); if (!dbfile) { dbfile = "/var/lib/zpm/local.db"; } - while ((opt = getopt(ac, av, "f:s")) != -1) { + while ((opt = getopt(ac, av, "f:scq")) != -1) { switch (opt) { case 'f': dbfile = optarg; break; case 's': set = 1; break; + case 'c': check = 1; break; + case 'q': quiet = 1; break; default: usage(); exit(EXIT_FAILURE); @@ -46,14 +51,22 @@ int main(int ac, char **av){ char hash[ZPM_HASH_STRLEN+1]; if (zpm_open(&pkg, dbfile)) { - if (set) { + if (check) { + found = zpm_package_hash(&pkg, pkgid, hash); + char *ehash = zpm_db_string(&pkg, "select hash from packages_pkgid where pkgid = %Q", pkgid); + if (ehash && found && !strcmp(ehash, hash)) { + found = 1; + } else { + found = 0; + } + } else if (set) { found = zpm_package_sethash(&pkg, pkgid, hash); } else { found = zpm_package_hash(&pkg, pkgid, hash); } } zpm_close(&pkg); - if (found) { + if (found && !quiet) { printf("%s\n", hash); } return found ? 0 : 1; -- 2.40.0