X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=lib%2Ffindpkg.c;h=8dd0ad14b1a4b7f83b96af8410eaaf9ac54ff79b;hb=HEAD;hp=6ea843cbecad5f39d6d5d280055734f23702a78e;hpb=c907b8ec08b06a4a256fd12b79b4bcf5088fbb19;p=zpackage diff --git a/lib/findpkg.c b/lib/findpkg.c index 6ea843c..8dd0ad1 100644 --- a/lib/findpkg.c +++ b/lib/findpkg.c @@ -36,11 +36,15 @@ void zpm_sqlite_error(struct zpm *zpm) { } char *zpm_findlib(struct zpm *zpm, char *soname, char *where) { - char *select = "select pkgid, package, version, release from packagefiles_status join elflibraries on file = hash"; - char *group = "order by package, version collate vercmp desc, cast(release as integer)"; sqlite3_str *sql; char *query, *pkgid = 0; +char *select = "select printf('%%s-%%s-%%s',P.package,P.version,P.release) as pkgid, P.package, P.version, P.release\ + from packagefiles PF\ + join elflibraries EL on EL.file = PF.hash\ + join packages P on P.package = PF.package and P.version = PF.version and P.release = PF.release"; + char *order = "order by P.package, P.version, cast(P.release as integer)"; + /* null pkgstr find "best" package * best is shortest complete package if any are complete * shortest incomplete if any are incomplete @@ -51,7 +55,7 @@ char *zpm_findlib(struct zpm *zpm, char *soname, char *where) { sql = sqlite3_str_new(zpm->db); sqlite3_str_appendall(sql, select); - sqlite3_str_appendf(sql, " where soname = %Q", soname); + sqlite3_str_appendf(sql, " where P.hash is not null and EL.soname = %Q", soname); if (where) { sqlite3_str_appendall(sql, " and "); @@ -59,7 +63,7 @@ char *zpm_findlib(struct zpm *zpm, char *soname, char *where) { } sqlite3_str_appendall(sql, " "); - sqlite3_str_appendall(sql, group); + sqlite3_str_appendall(sql, order); sqlite3_str_appendall(sql, " limit 1;"); if (sqlite3_str_errcode(sql)) { @@ -77,24 +81,39 @@ char *zpm_findlib(struct zpm *zpm, char *soname, char *where) { 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; @@ -172,6 +191,76 @@ char *zpm_findpkg(struct zpm *zpm, char *pkgstr, char *where) { } + 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;");