From b9eb4486d50a2af606c6b776fcb5dfe065ccee9e Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Sun, 17 Feb 2019 20:41:30 +0000 Subject: [PATCH] update search --- doc/zpm-search.8 | 98 ++++++++++++++++++++++++++++++++++++++++++++++++ doc/zpm-update.8 | 7 +++- src/search.c | 61 ++++++++++++++++++++++-------- zpm-repo | 4 +- zpm-update | 3 +- 5 files changed, 151 insertions(+), 22 deletions(-) create mode 100644 doc/zpm-search.8 diff --git a/doc/zpm-search.8 b/doc/zpm-search.8 new file mode 100644 index 0000000..d711e1d --- /dev/null +++ b/doc/zpm-search.8 @@ -0,0 +1,98 @@ +.TH zpm-search 8 2019-02-16 "ZPM 0.5" +.SH NAME +zpm-search \- search repositories for packages +.SH SYNOPSIS +.B zpm search +[ +.B -ljqiIOfPRDMvn +] +[ +.BI -d " localdb" +] +[ +.BI -p " packagedir" +] +[ +.BI -r " repodir" +] +.RI [ package ...] +.SH DESCRIPTION +\fBzpm-search\fR +searches for packages in repositories, the local database, and +a directory of package files. Packages needed for library +dependencies will be recursively searched for. +.SH OPTIONS +.TP +.BI \-d localdb +Specify the local database, if other than the default local database. +.TP +.BI \-p packagedir +Specify a directory to search for packages in. Defaults to +/var/lib/zpm/packages +.TP +.BI \-r repodir +Specify the directory to find repository information in. Defaults +to /var/lib/zpm/repo +.TP +.B \-i +Match against installed packages. Normally, packages are searched +for against the local database, but the output omits packages that +are already installed. This option adds found but installed packages +to the output. +.TP +.B \-l +In addition to finding packages, also find packages supplying libraries +needed by found packages. +.TP +.B \-I +Suppress installed. +.TP +.B \-O +Only local installed. +.TP +.B \-j +Output results in json format. You will get a list with the \-n option, +or an object of package id to location without the \-n option. A list +of object is always output, even if empty. +.TP +.B \-f +Only output found packages. Normally it is an error if a package +can't be found. This option makes that not an error, and suppresses +printing unfound packages to stderr. +.TP +.B \-q +Suppress output. The exit status is the same as it would otherwise be. +.TP +.B \-v +Increase verbosity. May be given multiple times. +.TP +.B \-M +Match all package files. Normally when looking at files ending in .zpm, +packages will only be searched for if the filename has the package id +as a prefix. This is an optimization to speed up the search. +.TP +.B \-P +Don't look in the package directory. +.TP +.B \-R +Don't search repositories. +.TP +.B \-D +Don't search the local database. +.TP +.B \-n +list package names only, not name and location found. +.SH EXAMPLES +.TP +.B zpm search +lists all files in the local database +.SH EXIT STATUS +0 on success non zero on failure +.SH FILES +/var/lib/zpm/local.db +.SH ENVIRONMENT +ZPMDB +.SH AUTHOR +Nathan Wagner +.SH SEE ALSO +.BR zpm (8) diff --git a/doc/zpm-update.8 b/doc/zpm-update.8 index 4f10ca6..c25751e 100644 --- a/doc/zpm-update.8 +++ b/doc/zpm-update.8 @@ -1,4 +1,4 @@ -.TH zpm-update 8 2018-12-10 "ZPM 0.4" +.TH zpm-update 8 2019-02-16 "ZPM 0.4" .SH NAME zpm-update \- update set of installed packages .SH SYNOPSIS @@ -7,7 +7,7 @@ zpm-update \- update set of installed packages .BI -f " pkgfile" ] [ -.B -LAOUnzvpSC +.B -LAOUnzvpSCl ] .RI [ \fB[+|-]\fIpackage ...] .SH DESCRIPTION @@ -58,6 +58,9 @@ and doesn't run any package scripts. Since scripts aren't run and no files are changed, this can only detect and report some types of errors. .TP +\-l +Just list the computed set of packages to update. +.TP \-R \fIrootdir\fR Specify a root directory for the package installs. Files will be installed relative to this directory. diff --git a/src/search.c b/src/search.c index 9b6ec88..dd324d5 100644 --- a/src/search.c +++ b/src/search.c @@ -28,6 +28,7 @@ struct search_ctl { int matchinstalled; int suppressinstalled; int onlylocalinstalled; + int foundonly; int verbose; int dbrepos; }; @@ -389,19 +390,39 @@ void checklibs(struct search_ctl *opts, free(pkgfile); } -void print_pkghash(jsw_hash_t *hash, int json) { +void print_pkghash(jsw_hash_t *hash, int json, int idonly) { const char *pkgid, *file; char *fmt; - char *sep; + char *sep = "\n"; int count = 0; - - fmt = json ? "\"%s\": \"%s\"" : "%s:%s"; - sep = json ? ", " : "\n"; + char *start = ""; + char *end = ""; if (json) { - printf("{ "); + sep = ", "; + if (idonly) { + fmt = "\"%s\""; + start = "[ "; + end = " ]\n"; + } else { + fmt = "\"%s\": \"%s\""; + start = "{ "; + end = " }\n"; + } + } else { + if (idonly) { + fmt = "%s"; + start = ""; + end = ""; + } else { + fmt = "%s:%s"; + start = ""; + end = ""; + } } + printf("%s", start); + if (jsw_hsize(hash) > 0) { for (jsw_hreset(hash); jsw_hitem(hash); jsw_hnext(hash)) { pkgid = jsw_hkey(hash); @@ -409,16 +430,20 @@ void print_pkghash(jsw_hash_t *hash, int json) { if (count++) { printf("%s", sep); } - printf(fmt, pkgid, file); + if (idonly) { + printf(fmt, pkgid); + } else { + printf(fmt, pkgid, file); + } } + if (!json) printf("\n"); } - if (json) printf(" }"); - printf("\n"); + printf("%s", end); } int main(int ac, char *av[]) { - int option, argn; - int findlibs = 0, json = 0; + int option, argn, rv = 0; + int findlibs = 0, json = 0, idonly = 0; struct pkgloc *found; jsw_hash_t *packages, *check, *forlibs, *nolib; jsw_atree_t *nfound; @@ -462,7 +487,7 @@ int main(int ac, char *av[]) { */ int output = 1; - while ((option = getopt(ac, av, "ljqPRDvp:r:d:MiIO")) != -1) { + while ((option = getopt(ac, av, "fljqPRDvp:r:d:MiIOn")) != -1) { switch (option) { case 'l': findlibs = 1; break; case 'j': json = 1; break; @@ -472,6 +497,7 @@ int main(int ac, char *av[]) { case 'I': opt.suppressinstalled = 1; break; /* only find localdb pkgs if installed */ case 'O': opt.onlylocalinstalled = 1; break; + case 'f': opt.foundonly = 1; break; case 'd': opt.localdb = optarg; break; case 'p': opt.pkgdir = optarg; break; case 'r': opt.repodir = optarg; break; @@ -484,6 +510,7 @@ int main(int ac, char *av[]) { */ case 'M': opt.matchallpkgfile = 1; break; case 'v': opt.verbose++; break; + case 'n': idonly = 1; break; default: exit(EXIT_FAILURE); break; @@ -559,10 +586,10 @@ int main(int ac, char *av[]) { if (output) { if (jsw_hsize(packages)) { - print_pkghash(packages, json); + print_pkghash(packages, json, idonly); } if (jsw_hsize(forlibs)) { - print_pkghash(forlibs, json); + print_pkghash(forlibs, json, idonly); } } @@ -573,9 +600,10 @@ int main(int ac, char *av[]) { file = jsw_hitem(nolib); fprintf(stderr, "no lib found %s:%s\n", pkgid, file); } + rv = 1; } - if (jsw_asize(nfound) > 0) { + if (jsw_asize(nfound) > 0 && !opt.foundonly) { jsw_atrav_t *i; i = jsw_atnew(); char *pkgstr; @@ -583,7 +611,8 @@ int main(int ac, char *av[]) { for (pkgstr = jsw_atfirst(i, nfound); pkgstr; pkgstr = jsw_atnext(i)) { fprintf(stderr, "%s: not found\n", pkgstr); } + rv = 1; } - return jsw_asize(nfound) > 0 || jsw_hsize(nolib) > 0 ? 1 : 0; + return rv; } diff --git a/zpm-repo b/zpm-repo index 4fe8845..76359b8 100755 --- a/zpm-repo +++ b/zpm-repo @@ -105,10 +105,10 @@ update_info() { fi if [ -f "$rf" ]; then # TODO merge in so packages aren't deleted - zpm fetchurl -f '-#' -z "$rf" -o "$rf.tmp" "$url" + zpm fetchurl -fpn -z "$rf" -o "$rf.tmp" "$url" rv=$? else - zpm fetchurl -f '-#' -o "$rf.tmp" "$url" && refresh "$repo" + zpm fetchurl -fpn -o "$rf.tmp" "$url" && refresh "$repo" rv=$? fi if [ $rv -eq 0 ]; then diff --git a/zpm-update b/zpm-update index 39c111a..0bac954 100755 --- a/zpm-update +++ b/zpm-update @@ -109,7 +109,7 @@ uninstall=0 # TODO option to attempt to resume an ongoing install # zpm-install [-SCn] [ -d localdb ] [ -f pkgfile ] [ -R installroot ] pkgstr ... -while getopts f:d:R:nSCvAObBLUzp opt; do +while getopts f:d:R:nSCvAObBLUzpl opt; do case $opt in f) pkgfile="$OPTARG" ;; d) localdb="$OPTARG" ;; @@ -237,7 +237,6 @@ for mergepkg in $merge; do nlist="$nlist $pkgid:$zpmfile" continue else - echo downloading $zpmfile zpm repo fetch $reponame $pkgid if [ -f "$zpmfile" ]; then nlist="$nlist $pkgid:$zpmfile" -- 2.40.0