char *id;
char *file;
int info;
+ int installed;
};
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) {
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++) {
pkg = malloc(sizeof *pkg);
pkg->id = strdup(latest);
pkg->file = pkgfile;
+ pkg->installed = 0;
+ if (installed) {
+ pkg->installed = !strcmp(latest, installed);
+ }
}
return pkg;
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;
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);
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)) {
}
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);
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);
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
*
* 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
*/
int output = 1;
- while ((option = getopt(ac, av, "ljqPRDvp: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:
}
}
-
if (!find_globs(&opt)) {
fprintf(stderr, "bad globs\n");
return 3;
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++) {
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);
} else {
jsw_ainsert(nfound, av[arg]);
}
-
}
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);
}