From: Nathan Wagner Date: Tue, 26 Feb 2019 18:27:01 +0000 (+0000) Subject: add tracing to zpm-search X-Git-Tag: v0.7.0~11 X-Git-Url: https://pd.if.org/git/?p=zpackage;a=commitdiff_plain;h=be765ec4d3dc14dd27826326e29da8a62d5603f7 add tracing to zpm-search --- diff --git a/src/search.c b/src/search.c index 1943f3b..a546d6c 100644 --- a/src/search.c +++ b/src/search.c @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include @@ -33,6 +35,16 @@ struct search_ctl { 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; @@ -272,14 +284,19 @@ struct pkgloc *find_package(char *pkgstr, struct search_ctl *opt) { 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) { + trace(1, opt, "found installed %s as %s\n", pkgstr, installed); latest = installed; pkgfile = opt->zpmdb->path; } + if (!opt->onlylocalinstalled) { + trace(1, opt, "checking local database for any %s\n", pkgstr); 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; @@ -295,20 +312,26 @@ struct pkgloc *find_package(char *pkgstr, struct search_ctl *opt) { #endif } + trace(1, opt, "checking repositories\n"); 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") ) { + trace(1, opt, "skipping repo/pkg %s\n", opt->repos.gl_pathv[i]); continue; } found = checkfile(pkgstr, opt->repos.gl_pathv[i], 0); + trace(1, opt, "found %s\n", 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]); } + 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); } + trace(1, opt, "set up pkgloc = {%s, %s, %d}\n", pkg->id, pkg->file, pkg->installed); } return pkg;