]> pd.if.org Git - zpackage/commitdiff
add tracing to zpm-search
authorNathan Wagner <nw@hydaspes.if.org>
Tue, 26 Feb 2019 18:27:01 +0000 (18:27 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Tue, 26 Feb 2019 18:27:01 +0000 (18:27 +0000)
src/search.c

index 1943f3b26265012e5ad3d8685dd73be0d02db746..a546d6ce808868422091ce528f9e9887ec2a9677 100644 (file)
@@ -2,6 +2,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <stdarg.h>
+#include <stdio.h>
 
 #include <glob.h>
 
 
 #include <glob.h>
 
@@ -33,6 +35,16 @@ struct search_ctl {
        int dbrepos;
 };
 
        int dbrepos;
 };
 
+void trace(int level, struct search_ctl *ctl, char *fmt, ...) {
+       va_list ap;
+
+       if (level <= ctl->verbose) {
+               va_start(ap, fmt);
+               vfprintf(stderr, fmt, ap);
+               va_end(ap);
+       }
+}
+
 char *pathcat(char *dir, char *path) {
        size_t dirlen = 0, pathlen = 0;
        char *cat;
 char *pathcat(char *dir, char *path) {
        size_t dirlen = 0, pathlen = 0;
        char *cat;
@@ -272,14 +284,19 @@ struct pkgloc *find_package(char *pkgstr, struct search_ctl *opt) {
        unsigned int i;
 
        if (opt->localdb) {
        unsigned int i;
 
        if (opt->localdb) {
+               trace(1, opt, "checking local database for installed %s\n", pkgstr);
                installed = zpm_findpkg(opt->zpmdb, pkgstr, "status = 'installed'");
                if (installed) {
                installed = zpm_findpkg(opt->zpmdb, pkgstr, "status = 'installed'");
                if (installed) {
+                       trace(1, opt, "found installed %s as %s\n", pkgstr, installed);
                        latest = installed;
                        pkgfile = opt->zpmdb->path;
                }
                        latest = installed;
                        pkgfile = opt->zpmdb->path;
                }
+
                if (!opt->onlylocalinstalled) {
                if (!opt->onlylocalinstalled) {
+                       trace(1, opt, "checking local database for any %s\n", pkgstr);
                        found = zpm_findpkg(opt->zpmdb, pkgstr, NULL);
                        if (found) {
                        found = zpm_findpkg(opt->zpmdb, pkgstr, NULL);
                        if (found) {
+                               trace(1, opt, "found %s as %s\n", pkgstr, installed);
                                rv = zpm_vercmp(found, latest);
                                if (rv == 1) {
                                        latest = found;
                                rv = zpm_vercmp(found, latest);
                                if (rv == 1) {
                                        latest = found;
@@ -295,20 +312,26 @@ struct pkgloc *find_package(char *pkgstr, struct search_ctl *opt) {
 #endif
        }
 
 #endif
        }
 
+       trace(1, opt, "checking repositories\n");
        for (i = 0; i < opt->repos.gl_pathc; i++) {
        for (i = 0; i < opt->repos.gl_pathc; i++) {
+               trace(1, opt, "checking repo/pkg %s\n", opt->repos.gl_pathv[i]);
                if (!opt->matchallpkgfile
                                && !strstr(opt->repos.gl_pathv[i], pkgstr)
                                && !strstr(opt->repos.gl_pathv[i], ".repo")
                                ) {
                if (!opt->matchallpkgfile
                                && !strstr(opt->repos.gl_pathv[i], pkgstr)
                                && !strstr(opt->repos.gl_pathv[i], ".repo")
                                ) {
+                       trace(1, opt, "skipping repo/pkg %s\n", opt->repos.gl_pathv[i]);
                        continue;
                }
                found = checkfile(pkgstr, opt->repos.gl_pathv[i], 0);
                        continue;
                }
                found = checkfile(pkgstr, opt->repos.gl_pathv[i], 0);
+               trace(1, opt, "found %s\n", found);
                if (found) {
                if (found) {
+                       trace(1, opt, "comparing found %s to latest (%s)\n", found, latest);
                        rv = zpm_vercmp(found, latest);
                        if (rv == 1) {
                                latest = found;
                                pkgfile = strdup(opt->repos.gl_pathv[i]);
                        }
                        rv = zpm_vercmp(found, latest);
                        if (rv == 1) {
                                latest = found;
                                pkgfile = strdup(opt->repos.gl_pathv[i]);
                        }
+                       trace(1, opt, "latest %s\n", latest);
                }
        }
 
                }
        }
 
@@ -320,6 +343,7 @@ struct pkgloc *find_package(char *pkgstr, struct search_ctl *opt) {
                if (installed) {
                       pkg->installed = !strcmp(latest, installed);
                }
                if (installed) {
                       pkg->installed = !strcmp(latest, installed);
                }
+               trace(1, opt, "set up pkgloc = {%s, %s, %d}\n", pkg->id, pkg->file, pkg->installed);
        }
 
        return pkg;
        }
 
        return pkg;