]> pd.if.org Git - zpackage/commitdiff
update for repository installing support
authorNathan Wagner <nw@hydaspes.if.org>
Sat, 17 Nov 2018 03:16:08 +0000 (03:16 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Sat, 17 Nov 2018 03:16:08 +0000 (03:16 +0000)
lib/findpkg.c
zpm-gc
zpm-merge
zpm-search.c

index 6ea843cbecad5f39d6d5d280055734f23702a78e..6d7981a315055bbe50024fe73b3fe6ca34e3a698 100644 (file)
@@ -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)) {
diff --git a/zpm-gc b/zpm-gc
index 3c1716c4fcfb264682c0bac2888a3ad53716e77d..95dcbe4cd4e2176c992a7cd6682eeba001554680 100755 (executable)
--- a/zpm-gc
+++ b/zpm-gc
@@ -3,6 +3,26 @@
 # garbage collect a package database
 # flags to skip phases
 
+# -C clear all phases
+# -n dry run
+# -a all phases
+# default is failed packages, orphaned elf, vacuum
+# 
+# phases
+# -cC remove command history by date
+# -dD remove dry run
+# -eE remove orphaned elf
+# -fF remove failed
+# -hH fix file content hash
+# -hH remove install history by date
+# -lL remove old logs, given by date
+# -nN remove acked notes
+# -oO remove outdated packages, unless preserved
+# -pP remove history for removed packages
+# -rR remove orphaned rows in files table packagefiles, notes, scripts, ...
+# -rR remove removed packages, unless preserved
+# -vV compactify the database file
+
 db=${1:-${ZPMDB:-/var/lib/zpm/local.db}}
 
 if [ -z "$db" ]; then
index 451aece98a79b82e5741a291aedc97607c2eafb5..263ac4077d8556bebf7794b698f699617d05172b 100755 (executable)
--- a/zpm-merge
+++ b/zpm-merge
@@ -22,6 +22,8 @@ update=0
 
 target=${ZPMDB:=/var/lib/zpm/local.db}
 
+# TODO option to only update if new
+# new is hash is different or build time is later
 # TODO option to merge all packages found in pkgfile
 while getopts :f:vd:FSs:au opt; do
        case $opt in
index 06439253c8b38f757bc479b428b75f318372223d..290c0834c63dc76212beaeea680faf799d02f5ad 100644 (file)
@@ -24,6 +24,7 @@ struct search_ctl {
        struct zpm *zpmdb;
        glob_t repos;
        int matchallpkgfile;
+       int verbose;
 };
 
 char *pathcat(char *dir, char *path) {
@@ -63,7 +64,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 +78,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);
        }
@@ -150,20 +151,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");
                }
        }
 
@@ -304,8 +316,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;
                        }
 
@@ -409,7 +427,7 @@ 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:M")) != -1) {
                switch (option) {
                        case 'l': findlibs = 1; break;
                        case 'j': json = 1; break;
@@ -421,6 +439,7 @@ int main(int ac, char *av[]) {
                        case 'R': opt.repodir = 0; break;
                        case 'D': opt.localdb = 0; break;
                        case 'M': opt.matchallpkgfile = 1; break;
+                       case 'v': opt.verbose++; break;
                        default:
                                  exit(EXIT_FAILURE);
                                  break;
@@ -443,6 +462,15 @@ int main(int ac, char *av[]) {
                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,