]> pd.if.org Git - zpackage/commitdiff
rework verify v0.7.0
authorNathan Wagner <nw@hydaspes.if.org>
Sun, 3 Mar 2019 02:26:20 +0000 (02:26 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Sun, 3 Mar 2019 02:26:20 +0000 (02:26 +0000)
src/verify.c

index ec9ca7dcfa931dcaf135d4cd4bc7dac1eec28e65..0918f121c2d04bb53930ae478f7b5a941b425e06 100644 (file)
@@ -34,7 +34,7 @@ struct config {
 };
 
 static void usage() {
-       printf("usage: zpm foreach-path [-fncC] args ...\n");
+       printf("usage: zpm verify [-f file] -eF [pkgid ...]\n");
 }
 
 static char *column(char *col, int ncols, char **vals, char **cols) {
@@ -151,9 +151,11 @@ int main(int ac, char **av) {
        jsw_atrav_t *list;
        int i, errors = 0;
        
-       pkglist = jsw_anew(afind_strcmp, (dup_f)strdup, (rel_f)free);
        struct config conf = { 0 };
 
+       /* TODO could do nothing for the dup */
+       pkglist = jsw_anew(afind_strcmp, (dup_f)strdup, (rel_f)free);
+
        conf.dbfile = "/var/lib/zpm/local.db";
 
        if ((s = getenv("ZPMDB"))) {
@@ -182,24 +184,34 @@ int main(int ac, char **av) {
        char *errmsg = 0;
 
        if (argn < ac) {
+               for (i = argn; i < ac; i++) {
+                       pkgid = zpm_findpkg(&pkg, av[i], "status = 'installed'");
+                       if (!pkgid) {
+                               if (conf.skipuninstalled) {
+                                       continue;
+                               }
+                               fprintf(stderr, "no installed package: %s\n", av[i]);
+                               errors++;
+                               free(pkgid);
+                               pkgid = 0;
+                               continue;
+                       }
+                       if (!jsw_ainsert(pkglist, pkgid)) {
+                               fprintf(stderr, "pkglist insert failed\n");
+                               exit(EXIT_FAILURE);
+                       }
+                       free(pkgid);
+               }
        } else {
                fprintf(stderr, "must specify pkgid\n");
                usage();
                exit(EXIT_FAILURE);
        }
 
-       for (i = argn; i < ac; i++) {
-               pkgid = zpm_findpkg(&pkg, av[i], "status = 'installed'");
-               if (!pkgid) {
-                       if (conf.skipuninstalled) {
-                               continue;
-                       }
-                       fprintf(stderr, "no installed package: %s\n", av[i]);
-                       errors++;
-                       free(pkgid);
-                       pkgid = 0;
-                       continue;
-               }
+       list = jsw_atnew();
+
+       for (pkgid = jsw_atfirst(list, pkglist); pkgid; pkgid = jsw_atnext(list)) {
+               conf.pkgid = pkgid;
 
                if (!zpm_foreach_path(&pkg, pkgid, 0, count_plan, &conf, &errmsg)) {
                        if (errmsg) {
@@ -209,15 +221,10 @@ int main(int ac, char **av) {
                        if (pkg.error == 1) {
                                fprintf(stderr, "unable to allocate memory\n");
                        }
-                       fprintf(stderr, "unable to plan\n");
                        exit(EXIT_FAILURE);
                }
-               if (!jsw_ainsert(pkglist, pkgid)) {
-                       fprintf(stderr, "pkglist insert failed\n");
-                       exit(EXIT_FAILURE);
-               }
-               free(pkgid);
        }
+
        if (errors) {
                exit(EXIT_FAILURE);
        }