+ return zpm_db_run(zpm, "update packages_pkgid set hash = NULL where pkgid = %Q", pkgid);
+}
+
+char *zpm_package_gethash(struct zpm *zpm, char *pkgid, char *hash) {
+ char *saved;
+
+ if (!zpm || !zpm->db || !pkgid) {
+ return 0;
+ }
+
+ saved = zpm_db_string(zpm, "select hash from packages_pkgid where pkgid = %Q", pkgid);
+ if (saved && hash) {
+ strncpy(hash, saved, ZPM_HASH_STRLEN);
+ free(saved);
+ return hash;
+ }
+ return saved;
+}
+
+/* calc vs stored (hash == 0)
+ *
+ * otherwise check both.
+ * 0 == match both
+ * 1 = no match stored
+ * 2 = no match calc
+ * 3 = no match either
+ * 4 = no such pkgid
+ */
+int zpm_package_checkhash(struct zpm *zpm, char *pkgid, char *hash) {
+ /* check calculated hash against stored hash */
+ char calc[ZPM_HASH_STRLEN];
+ char set[ZPM_HASH_STRLEN];
+ char *current;
+ int rv = 0;
+
+ zpm_package_hash(zpm, pkgid, calc);
+ current = zpm_package_gethash(zpm, pkgid, set);
+ if (!current) {
+ rv |= 1;
+ }
+
+ if (hash) {
+ if (current && memcmp(hash, current, ZPM_HASH_STRLEN)) {
+ rv |= 1;
+ }
+ if (memcmp(hash, calc, ZPM_HASH_STRLEN)) {
+ rv |= 2;
+ }
+ } else {
+ if (current) {
+ rv = memcmp(calc, current, ZPM_HASH_STRLEN) ? 1 : 0;
+ }
+ }
+ return rv;