]> pd.if.org Git - zpackage/blobdiff - src/packagehash.c
add scripts to package hashing
[zpackage] / src / packagehash.c
index ee4f67655d4f770327337057748afc7917476b11..76cd60123021117dc36a81c3071ee22c72091448 100644 (file)
@@ -16,10 +16,11 @@ int main(int ac, char **av){
        int opt, argn;
        struct zpm pkg;
        char *dbfile;
+       int fail = 0;
 
        int set = 0, clear = 0, showcurrent = 0;
        int check = 0, quiet = 0, checkfail = 0, verbose = 0;
-       char hash[ZPM_HASH_STRLEN+1];
+       char hash[ZPM_HASH_STRLEN+1] = { 0 };
        char *pkgid = 0, *current = 0, *display = hash;
 
        dbfile = getenv("ZPMDB");
@@ -60,28 +61,23 @@ int main(int ac, char **av){
                        exit(EXIT_FAILURE);
                }
                if (check || showcurrent) {
-                       current = zpm_db_string(&pkg, "select hash from packages_pkgid where pkgid = %Q", pkgid);
+                       current = zpm_package_gethash(&pkg, pkgid, 0);
                }
 
                if (check) {
-                       checkfail = 1;
-                       if (current) {
-                               zpm_package_hash(&pkg, pkgid, hash);
-                               checkfail = strcmp(current, hash);
-                       }
+                       fail = zpm_package_checkhash(&pkg, pkgid, 0);
                } else if (set) {
-                       zpm_package_sethash(&pkg, pkgid, hash);
+                       fail = zpm_package_sethash(&pkg, pkgid, hash);
                } else if (clear) {
-                       zpm_package_sethash(&pkg, pkgid, NULL);
-                       display = NULL;
+                       fail = zpm_package_clearhash(&pkg, pkgid);
                } else if (showcurrent) {
                        display = current;
                } else {
-                       zpm_package_hash(&pkg, pkgid, hash);
+                       fail = zpm_package_hash(&pkg, pkgid, hash);
                }
 
                zpm_close(&pkg);
-               if (display && !quiet) {
+               if (display && !quiet && !fail) {
                        if (verbose) {
                                printf("%s ", pkgid);
                        }