X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=zpm-search.c;h=a98aa002cd3abe8b570bb6454d4c5de3d2a419ac;hb=1dd10a8ea007ecf04ddaa5a0ab2fa26c572ecc60;hp=06439253c8b38f757bc479b428b75f318372223d;hpb=50b0480e6259c1e4bed6e6dc7990e080ceb5e855;p=zpackage diff --git a/zpm-search.c b/zpm-search.c index 0643925..a98aa00 100644 --- a/zpm-search.c +++ b/zpm-search.c @@ -17,6 +17,7 @@ struct pkgloc { char *id; char *file; int info; + int installed; }; struct search_ctl { @@ -24,6 +25,11 @@ struct search_ctl { struct zpm *zpmdb; glob_t repos; int matchallpkgfile; + int matchinstalled; + int suppressinstalled; + int onlylocalinstalled; + int verbose; + int dbrepos; }; char *pathcat(char *dir, char *path) { @@ -63,7 +69,7 @@ char *checkfile(char *pkgstr, char *path) { return NULL; } - pkgid = zpm_findpkg(&pkgfile, pkgstr, "hash is not null"); + pkgid = zpm_findpkg(&pkgfile, pkgstr, NULL); zpm_close(&pkgfile); return pkgid; @@ -77,7 +83,7 @@ char *checkfileforlib(char *soname, char *path) { return NULL; } - pkgid = zpm_findlib(&pkgfile, soname, "hash is not null"); + pkgid = zpm_findlib(&pkgfile, soname, NULL); if (pkgfile.error) { fprintf(stderr, "sql error: %s\n", pkgfile.errmsg); } @@ -133,7 +139,6 @@ int find_globs(struct search_ctl *opt) { default: break; } - globopts = GLOB_APPEND; free(globstr); } @@ -150,20 +155,31 @@ int find_lib(char *soname, struct search_ctl *opt, struct pkgloc *pkg) { if (opt->localdb) { installed = zpm_findlib(opt->zpmdb, soname, "status = 'installed'"); if (installed) { + if (opt->verbose > 1) { + fprintf(stderr, "library %s installed via %s\n", soname, installed); + } /* we're done, the lib is installed */ return 2; } } for (i = 0; i < opt->repos.gl_pathc; i++) { + if (opt->verbose > 1) { + fprintf(stderr, "checking %s for %s\n", opt->repos.gl_pathv[i], soname); + } found = checkfileforlib(soname, opt->repos.gl_pathv[i]); if (found) { + if (opt->verbose > 1) { + fprintf(stderr, "found %s\n", found); + } rv = zpm_vercmp(found, latest); if (rv == 1) { latest = found; free(pkgfile); pkgfile = strdup(opt->repos.gl_pathv[i]); } + } else if (opt->verbose > 1) { + fprintf(stderr, "not found\n"); } } @@ -179,7 +195,7 @@ int find_lib(char *soname, struct search_ctl *opt, struct pkgloc *pkg) { struct pkgloc *find_package(char *pkgstr, struct search_ctl *opt) { char *latest = 0; char *installed = 0, *found = 0; - char *pkgfile; + char *pkgfile = 0; struct pkgloc *pkg = 0; int rv; unsigned int i; @@ -188,15 +204,24 @@ struct pkgloc *find_package(char *pkgstr, struct search_ctl *opt) { installed = zpm_findpkg(opt->zpmdb, pkgstr, "status = 'installed'"); if (installed) { latest = installed; + pkgfile = opt->zpmdb->path; } - found = zpm_findpkg(opt->zpmdb, pkgstr, NULL); - if (found) { - rv = zpm_vercmp(found, latest); - if (rv == 1) { - latest = found; - pkgfile = opt->zpmdb->path; + if (!opt->onlylocalinstalled) { + found = zpm_findpkg(opt->zpmdb, pkgstr, NULL); + if (found) { + rv = zpm_vercmp(found, latest); + if (rv == 1) { + latest = found; + pkgfile = opt->zpmdb->path; + } } } + +#if 0 + if (opt->dbrepos) { + zpm_foreach_repo(opt->zpmdb, search_repo, pkg) + } +#endif } for (i = 0; i < opt->repos.gl_pathc; i++) { @@ -220,6 +245,10 @@ struct pkgloc *find_package(char *pkgstr, struct search_ctl *opt) { pkg = malloc(sizeof *pkg); pkg->id = strdup(latest); pkg->file = pkgfile; + pkg->installed = 0; + if (installed) { + pkg->installed = !strcmp(latest, installed); + } } return pkg; @@ -304,8 +333,14 @@ void checklibs(struct search_ctl *opts, int found; struct pkgloc pkginfo; + if (opts->verbose > 1) { + fprintf(stderr, "checking for %s\n", soname); + } /* if it's in checked_libs, we've already looked at this one */ if (jsw_afind(checked_libs, soname)) { + if (opts->verbose > 1) { + fprintf(stderr, "already checked for %s\n", soname); + } continue; } @@ -327,12 +362,10 @@ void checklibs(struct search_ctl *opts, } /* shouldn't be in there already */ jsw_hinsert(forlibs, pkginfo.id, pkginfo.file); - } - /* otherwise found == 2, so just continue */ - if (found) { free(pkginfo.file); free(pkginfo.id); - } + } + /* otherwise found == 2, so just continue */ } } free(pkgid); @@ -375,12 +408,15 @@ int main(int ac, char *av[]) { struct search_ctl opt = { 0 }; struct zpm localdb; + opt.dbrepos = 1; + opt.localdb = getenv("ZPMDB"); if (!opt.localdb) opt.localdb = "/var/lib/zpm/local.db"; opt.pkgdir = getenv("ZPM_PACKAGE_DIR"); if (!opt.pkgdir) opt.pkgdir = "/var/lib/zpm/packages"; opt.repodir = getenv("ZPM_REPO_DIR"); - if (!opt.repodir) opt.repodir = "/var/lib/zpm/repo/"; + if (!opt.repodir) opt.repodir = "/var/lib/zpm/repo"; + /* -l also find packages needed for libs * -j output json @@ -390,7 +426,7 @@ int main(int ac, char *av[]) { * * environment: * ZPMDB - path to localdb, /var/lib/zpm/local.db - * ZPM_REPO_DIR - path to *.repo files, '/var/lib/zpm/repos' + * ZPM_REPO_DIR - path to *.repo files, '/var/lib/zpm/repo' * ZPM_PACKAGE_DIRS - : separated paths to *.zpm files, * '/var/lib/zpm/packages' * ZPM_ROOT_DIR :- prepends to above paths @@ -409,18 +445,28 @@ int main(int ac, char *av[]) { */ int output = 1; - while ((option = getopt(ac, av, "ljqPRDp:r:d:M")) != -1) { + while ((option = getopt(ac, av, "ljqPRDvp:r:d:MiIO")) != -1) { switch (option) { case 'l': findlibs = 1; break; case 'j': json = 1; break; - case 'q': output = 0; + case 'q': output = 0; break; + /* show installed files */ + case 'i': opt.matchinstalled = 1; break; + case 'I': opt.suppressinstalled = 1; break; + /* only find localdb pkgs if installed */ + case 'O': opt.onlylocalinstalled = 1; break; case 'd': opt.localdb = optarg; break; case 'p': opt.pkgdir = optarg; break; case 'r': opt.repodir = optarg; break; case 'P': opt.pkgdir = 0; break; case 'R': opt.repodir = 0; break; case 'D': opt.localdb = 0; break; + /* matchallpkgfile means look at + * all .zpm files, not just ones + * that have the pkgid string prefix + */ case 'M': opt.matchallpkgfile = 1; break; + case 'v': opt.verbose++; break; default: exit(EXIT_FAILURE); break; @@ -437,12 +483,20 @@ int main(int ac, char *av[]) { } } - if (!find_globs(&opt)) { fprintf(stderr, "bad globs\n"); return 3; } + if (opt.verbose > 1) { + unsigned int i; + fprintf(stderr, "globs:"); + for (i = 0; i < opt.repos.gl_pathc; i++) { + fprintf(stderr, " %s", opt.repos.gl_pathv[i]); + } + fprintf(stderr, "\n"); + } + packages = jsw_hnew(ac,NULL,(cmp_f)strcmp,(keydup_f)strdup, (itemdup_f)strdup,free,free); check = jsw_hnew(ac,NULL,(cmp_f)strcmp,(keydup_f)strdup, @@ -456,7 +510,10 @@ int main(int ac, char *av[]) { int arg; for (arg = argn; arg < ac; arg++) { found = find_package(av[arg], &opt); - if (found) { + if (found && (opt.matchinstalled || !found->installed)) { + if (found->installed && opt.suppressinstalled) { + continue; + } jsw_hinsert(packages, found->id, found->file); jsw_hinsert(check, found->id, found->file); free(found->id); @@ -470,10 +527,15 @@ int main(int ac, char *av[]) { if (findlibs) { checklibs(&opt, check, forlibs, nolib); + /* remove from forlibs anything already explicitly + * in packages + */ } if (output) { - print_pkghash(packages, json); + if (jsw_hsize(packages)) { + print_pkghash(packages, json); + } if (jsw_hsize(forlibs)) { print_pkghash(forlibs, json); }