]> pd.if.org Git - zpackage/blobdiff - src/packagehash.c
remove stray debug fprintf
[zpackage] / src / packagehash.c
index 6d5b9128fabb5e4a007305f10637111af24dd649..76cd60123021117dc36a81c3071ee22c72091448 100644 (file)
@@ -13,13 +13,15 @@ void usage(void) {
 }
 
 int main(int ac, char **av){
-       int opt;
+       int opt, argn;
        struct zpm pkg;
        char *dbfile;
+       int fail = 0;
 
        int set = 0, clear = 0, showcurrent = 0;
-       int check = 0;
-       int quiet = 0;
+       int check = 0, quiet = 0, checkfail = 0, verbose = 0;
+       char hash[ZPM_HASH_STRLEN+1] = { 0 };
+       char *pkgid = 0, *current = 0, *display = hash;
 
        dbfile = getenv("ZPMDB");
        if (!dbfile) {
@@ -31,7 +33,7 @@ int main(int ac, char **av){
         * show current -e
         * check -c
         */ 
-       while ((opt = getopt(ac, av, "f:sScqe")) != -1) {
+       while ((opt = getopt(ac, av, "f:sScqev")) != -1) {
                switch (opt) {
                        case 'f': dbfile = optarg; break;
                        case 's': set = 1; break;
@@ -39,48 +41,46 @@ int main(int ac, char **av){
                        case 'c': check = 1; break;
                        case 'q': quiet = 1; break;
                        case 'e': showcurrent = 1; break;
+                       case 'v': verbose = 1; break;
                        default:
                                  usage();
                                  exit(EXIT_FAILURE);
                                  break;
                }
        }
-       int argn = optind;
+       argn = optind;
 
        if (!dbfile) {
                fprintf(stderr, "must specify db\n");
                return 1;
        }
 
-       char *pkgid = av[argn];
-       char hash[ZPM_HASH_STRLEN+1];
-       char *current = 0, *display = hash;
-       int checkfail = 0;
-
        if (zpm_open(&pkg, dbfile)) {
+               pkgid = zpm_findpkg(&pkg, av[argn], NULL);
+               if (!pkgid) {
+                       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);
+                       }
                        printf("%s\n", display);
                }
                free(current);