X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=zpm-search.c;h=9b6ec887cd015f45b88f72e0de32df74d31303a2;hb=62f6ff407bc4f2cf03d1fa7cf3dc9a3f4026624a;hp=defbe14fd09173cf243461442b05986b3427ef7d;hpb=154892acacfb9a9f818638b853ef4f4a8f3b7797;p=zpackage diff --git a/zpm-search.c b/zpm-search.c index defbe14..9b6ec88 100644 --- a/zpm-search.c +++ b/zpm-search.c @@ -27,6 +27,7 @@ struct search_ctl { int matchallpkgfile; int matchinstalled; int suppressinstalled; + int onlylocalinstalled; int verbose; int dbrepos; }; @@ -205,12 +206,14 @@ struct pkgloc *find_package(char *pkgstr, struct search_ctl *opt) { 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; + } } } @@ -268,6 +271,10 @@ with pkglibs as (\ where PL.pkgid = %Q\ "; +static int afind_strcmp(const void *a, const void *b) { + return strcmp(a, b); +} + void checklibs(struct search_ctl *opts, jsw_hash_t *check, jsw_hash_t *forlibs, jsw_hash_t *nfound) { char *pkgid = 0, *pkgfile = 0; @@ -283,8 +290,8 @@ void checklibs(struct search_ctl *opts, jsw_atrav_t *i; char *soname; - checked = jsw_anew((cmp_f)strcmp, (dup_f)strdup, (rel_f)free); - checked_libs = jsw_anew((cmp_f)strcmp, (dup_f)strdup, (rel_f)free); + checked = jsw_anew(afind_strcmp, (dup_f)strdup, (rel_f)free); + checked_libs = jsw_anew(afind_strcmp, (dup_f)strdup, (rel_f)free); while (jsw_hsize(check) > 0) { free(pkgid); @@ -303,11 +310,22 @@ void checklibs(struct search_ctl *opts, if (jsw_afind(checked, pkgid)) { /* already checked this one */ + /* fprintf(stderr, "already checked %s\n", pkgid); */ continue; } + fprintf(stderr, "checking libs for %s\n", pkgid); /* we do this now so we catch self deps */ - jsw_ainsert(checked, pkgid); + if (!jsw_ainsert(checked, pkgid)) { + fprintf(stderr, "checked insert failed\n"); + exit(EXIT_FAILURE); + } + + if (!jsw_afind(checked, pkgid)) { + /* already checked this one */ + fprintf(stderr, "checked find failed\n"); + exit(EXIT_FAILURE); + } /* get the libraries needed by this package */ if (!zpm_open(&src, pkgfile)) { @@ -316,7 +334,7 @@ void checklibs(struct search_ctl *opts, } if (needed) jsw_adelete(needed); - needed = jsw_anew((cmp_f)strcmp, (dup_f)strdup, (rel_f)free); + needed = jsw_anew(afind_strcmp, (dup_f)strdup, (rel_f)free); libs = zpm_libraries_needed(&src, pkgid, needed); zpm_close(&src); @@ -330,16 +348,18 @@ 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); + fprintf(stderr, "already checked %s\n", soname); } continue; } +#if 0 + if (opts->verbose > 1) { + fprintf(stderr, "checking for %s\n", soname); + } +#endif /* haven't found this soname */ jsw_ainsert(checked_libs, soname); @@ -442,7 +462,7 @@ int main(int ac, char *av[]) { */ int output = 1; - while ((option = getopt(ac, av, "ljqPRDvp:r:d:MiI")) != -1) { + while ((option = getopt(ac, av, "ljqPRDvp:r:d:MiIO")) != -1) { switch (option) { case 'l': findlibs = 1; break; case 'j': json = 1; break; @@ -450,6 +470,8 @@ int main(int ac, char *av[]) { /* 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; @@ -492,15 +514,24 @@ int main(int ac, char *av[]) { fprintf(stderr, "\n"); } - packages = jsw_hnew(ac,NULL,(cmp_f)strcmp,(keydup_f)strdup, + /* direct packages asked for */ + packages = jsw_hnew(ac,NULL,afind_strcmp,(keydup_f)strdup, (itemdup_f)strdup,free,free); - check = jsw_hnew(ac,NULL,(cmp_f)strcmp,(keydup_f)strdup, + + /* packages we need to check for libs */ + check = jsw_hnew(ac,NULL,afind_strcmp,(keydup_f)strdup, (itemdup_f)strdup,free,free); - forlibs = jsw_hnew(ac,NULL,(cmp_f)strcmp,(keydup_f)strdup, + + /* packages we will also need for library dependences */ + forlibs = jsw_hnew(ac,NULL,afind_strcmp,(keydup_f)strdup, (itemdup_f)strdup,free,free); - nolib = jsw_hnew(ac,NULL,(cmp_f)strcmp,(keydup_f)strdup, + + /* libraries we didn't find */ + nolib = jsw_hnew(ac,NULL,afind_strcmp,(keydup_f)strdup, (itemdup_f)strdup,free,free); - nfound = jsw_anew((cmp_f)strcmp, (dup_f)strdup, (rel_f)free); + + /* packages asked for that we can't find */ + nfound = jsw_anew(afind_strcmp, (dup_f)strdup, (rel_f)free); int arg; for (arg = argn; arg < ac; arg++) { @@ -517,11 +548,13 @@ int main(int ac, char *av[]) { } else { jsw_ainsert(nfound, av[arg]); } - } if (findlibs) { checklibs(&opt, check, forlibs, nolib); + /* remove from forlibs anything already explicitly + * in packages + */ } if (output) {