#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
+#include <string.h>
#include "zpm.h"
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);
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;