return pkgid;
}
-int zpm_libraries_needed(struct zpm *zpm, char *pkgid, jsw_atree_t *list) {
- char *pkglibsneeded = "\
- with pkglibs as (\
- select distinct EN.needed as soname, PF.pkgid\
- from elfneeded EN\
- join packagefiles_pkgid PF on PF.hash = EN.file\
- ),\
- pkgprovides as (\
- select distinct EL.soname, PF.pkgid\
- from elflibraries EL\
- join packagefiles_pkgid PF on PF.hash = EL.file\
- )\
- select distinct PL.soname, PP.soname is not null as selfsatisfied\
- from pkglibs PL\
- left join pkgprovides PP on PL.pkgid = PP.pkgid and PL.soname = PP.soname\
- where PL.pkgid = %Q\
- ";
+int zpm_packages_needed(struct zpm *zpm, char *pkgid, jsw_atree_t *list) {
+ char *pkglibsneeded = "select soname, selfsatisfied from package_libraries_needed where pkgid = %Q";
+ sqlite3_stmt *st;
+ int count = 0;
+ int rv;
+
+ st = zpm_dbquery(zpm, pkglibsneeded, pkgid);
+
+ while ((rv = sqlite3_step(st)) == SQLITE_ROW) {
+ char *soname;
+ int self;
+
+ soname = (char *)sqlite3_column_text(st, 0);
+ /* TODO check and skip self sats */
+ self = sqlite3_column_int(st,1);
+ if (self) {
+ continue;
+ }
+ count++;
+
+ /* if it's in needed, we've already looked at this one */
+ if (list && !jsw_afind(list, soname)) {
+ jsw_ainsert(list, soname);
+ }
+ }
+ sqlite3_finalize(st);
+ return count;
+}
+
+
+int zpm_libraries_needed(struct zpm *zpm, char *pkgid, jsw_atree_t *list) {
+ char *pkglibsneeded = "select soname, selfsatisfied from package_libraries_needed where pkgid = %Q";
sqlite3_stmt *st;
int count = 0;
int rv;
}
+ sqlite3_str_appendall(sql, " ");
+ sqlite3_str_appendall(sql, group);
+ sqlite3_str_appendall(sql, " limit 1;");
+
+ if (sqlite3_str_errcode(sql)) {
+ zpm->error = 1;
+ sqlite3_free(sqlite3_str_finish(sql));
+ return 0;
+ }
+
+ query = sqlite3_str_finish(sql);
+
+ pkgid = zpm_db_string(zpm, query);;
+
+ sqlite3_free(query);
+
+ return pkgid;
+}
+
+char *zpm_findpkg_range(struct zpm *zpm, char *minpkg, char *maxpkg, char *where, int wantleast) {
+ int release;
+ char version[32];
+ char package[32];
+
+ char *select = "select pkgid, package, version, release from packages_pkgid";
+ char *last = "order by version collate vercmp desc, cast(release as integer) desc";
+ char *first = "order by version collate vercmp, cast(release as integer)";
+ char *group;
+
+ char *query, *pkgid = 0;
+ sqlite3_str *sql;
+
+ group = wantleast ? first : last;
+ /* null pkgstr find "best" package
+ * best is shortest complete package if any are complete
+ * shortest incomplete if any are incomplete
+ * where more than one version is in those sets, best is
+ * latest as determined by vercmp
+ */
+
+ sql = sqlite3_str_new(zpm->db);
+
+ sqlite3_str_appendall(sql, select);
+ sqlite3_str_appendall(sql, " where true");
+
+ if (minpkg) {
+ sqlite3_str_appendf(sql, " and pkgid >= %Q collate vercmp",
+ minpkg);
+ zpm_parse_package(minpkg, package, version, &release);
+ if (*package != 0) {
+ sqlite3_str_appendf(sql, " and package = %Q",
+ package);
+ }
+ }
+
+ if (maxpkg) {
+ sqlite3_str_appendf(sql, " and pkgid <= %Q collate vercmp",
+ maxpkg);
+ zpm_parse_package(maxpkg, package, version, &release);
+ if (*package != 0) {
+ sqlite3_str_appendf(sql, " and package = %Q",
+ package);
+ }
+ }
+
+ if (where) {
+ sqlite3_str_appendall(sql, " and ");
+ sqlite3_str_appendall(sql, where);
+ }
+
sqlite3_str_appendall(sql, " ");
sqlite3_str_appendall(sql, group);
sqlite3_str_appendall(sql, " limit 1;");
int opt, argn;
struct zpm zpm;
char *dbfile = 0, *pkgstr = 0, *pkgid = 0;
+ int range = 0, wantleast = 0, argismax = 0;
+ char *minpkg = 0, *maxpkg = 0;
char *sql;
sqlite3_str *include;
include = sqlite3_str_new(NULL);
exclude = sqlite3_str_new(NULL);
- while ((opt = getopt(ac, av, "f:s:S:I")) != -1) {
+ while ((opt = getopt(ac, av, "f:s:S:Imrl")) != -1) {
switch (opt) {
case 'f': dbfile = optarg; break;
case 's': sqlite3_str_appendf(include,",%Q", optarg);
break;
case 'I': sqlite3_str_appendall(include,",'installed'");
break;
+ case 'l': wantleast = 1; break;
+ case 'r': range = 1; break;
+ case 'm': argismax = 1; range = 1; break;
default:
usage();
exit(EXIT_FAILURE);
}
argn = optind;
+ if (ac < argn) {
+ usage();
+ exit(EXIT_FAILURE);
+ }
+
+ pkgstr = minpkg = av[argn];
+ if (ac > argn) {
+ maxpkg = av[argn+1];
+ }
+
+ if (maxpkg) {
+ range = 1;
+ }
+
if (!dbfile) {
fprintf(stderr, "must specify db\n");
return 1;
excludes+1);
}
- if (ac >= argn) {
- pkgstr = av[argn];
- }
-
sql = sqlite3_str_value(query);
- pkgid = zpm_findpkg(&zpm, pkgstr, sql);
+ if (range) {
+ if (argismax) {
+ /* swap the sense of the arguments */
+ minpkg = maxpkg;
+ maxpkg = pkgstr;
+ }
+ pkgid = zpm_findpkg_range(&zpm, minpkg, maxpkg, sql, wantleast);
+ } else {
+ pkgid = zpm_findpkg(&zpm, pkgstr, sql);
+ }
sqlite3_free(sql);
if (pkgid) {