commit the_silver_searcher for openSUSE:Factory
Hello community, here is the log from the commit of package the_silver_searcher for openSUSE:Factory checked in at 2017-09-28 12:35:14 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/the_silver_searcher (Old) and /work/SRC/openSUSE:Factory/.the_silver_searcher.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "the_silver_searcher" Thu Sep 28 12:35:14 2017 rev:12 rq:528988 version:2.1.0 Changes: -------- --- /work/SRC/openSUSE:Factory/the_silver_searcher/the_silver_searcher.changes 2017-07-24 12:33:21.781553486 +0200 +++ /work/SRC/openSUSE:Factory/.the_silver_searcher.new/the_silver_searcher.changes 2017-09-28 12:35:38.781352392 +0200 @@ -1,0 +2,7 @@ +Wed Sep 27 15:35:34 UTC 2017 - astieger@suse.com + +- update to 2.1.0: + * Make '-A n -B n' act like '-C n' by printing blank lines + * Stream decompress zipped files + +------------------------------------------------------------------- Old: ---- the_silver_searcher-2.0.0.tar.gz the_silver_searcher-2.0.0.tar.gz.asc New: ---- the_silver_searcher-2.1.0.tar.gz the_silver_searcher-2.1.0.tar.gz.asc ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ the_silver_searcher.spec ++++++ --- /var/tmp/diff_new_pack.Nb1GIb/_old 2017-09-28 12:35:39.493252288 +0200 +++ /var/tmp/diff_new_pack.Nb1GIb/_new 2017-09-28 12:35:39.497251726 +0200 @@ -17,7 +17,7 @@ Name: the_silver_searcher -Version: 2.0.0 +Version: 2.1.0 Release: 0 Summary: A code-searching tool similar to ack, but faster License: Apache-2.0 ++++++ the_silver_searcher-2.0.0.tar.gz -> the_silver_searcher-2.1.0.tar.gz ++++++ ++++ 2776 lines of diff (skipped) ++++ retrying with extended exclude list diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/the_silver_searcher-2.0.0/Makefile.am new/the_silver_searcher-2.1.0/Makefile.am --- old/the_silver_searcher-2.0.0/Makefile.am 2017-06-03 06:25:51.000000000 +0200 +++ new/the_silver_searcher-2.1.0/Makefile.am 2017-06-28 07:10:58.000000000 +0200 @@ -1,7 +1,7 @@ ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} bin_PROGRAMS = ag -ag_SOURCES = src/ignore.c src/ignore.h src/log.c src/log.h src/options.c src/options.h src/print.c src/print_w32.c src/print.h src/scandir.c src/scandir.h src/search.c src/search.h src/lang.c src/lang.h src/util.c src/util.h src/decompress.c src/decompress.h src/uthash.h src/main.c +ag_SOURCES = src/ignore.c src/ignore.h src/log.c src/log.h src/options.c src/options.h src/print.c src/print_w32.c src/print.h src/scandir.c src/scandir.h src/search.c src/search.h src/lang.c src/lang.h src/util.c src/util.h src/decompress.c src/decompress.h src/uthash.h src/main.c src/zfile.c ag_LDADD = ${PCRE_LIBS} ${LZMA_LIBS} ${ZLIB_LIBS} $(PTHREAD_LIBS) dist_man_MANS = doc/ag.1 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/the_silver_searcher-2.0.0/README.md new/the_silver_searcher-2.1.0/README.md --- old/the_silver_searcher-2.0.0/README.md 2017-06-03 06:25:51.000000000 +0200 +++ new/the_silver_searcher-2.1.0/README.md 2017-08-25 07:45:20.000000000 +0200 @@ -6,7 +6,7 @@ [![Floobits Status](https://floobits.com/ggreer/ag.svg)](https://floobits.com/ggreer/ag/redirect) -[![#ag on Freenode](http://img.shields.io/Freenode/%23ag.png)](https://webchat.freenode.net/?channels=ag) +[![#ag on Freenode](https://img.shields.io/badge/Freenode-%23ag-brightgreen.svg)](https://webchat.freenode.net/?channels=ag) Do you know C? Want to improve ag? [I invite you to pair with me](http://geoff.greer.fm/2014/10/13/help-me-get-to-ag-10/). @@ -67,7 +67,7 @@ yum install epel-release.noarch the_silver_searcher * Gentoo - emerge the_silver_searcher + emerge -a sys-apps/the_silver_searcher * Arch pacman -S the_silver_searcher @@ -96,9 +96,17 @@ pkg_add the_silver_searcher -### Cygwin +### Windows -Run the relevant [`setup-*.exe`](https://cygwin.com/install.html), and select "the\_silver\_searcher" in the "Utils" category. +* Win32/64 + + Unofficial daily builds are [available](https://github.com/k-takata/the_silver_searcher-win32). +* MSYS2 + + pacman -S mingw-w64-{i686,x86_64}-ag +* Cygwin + + Run the relevant [`setup-*.exe`](https://cygwin.com/install.html), and select "the\_silver\_searcher" in the "Utils" category. ## Building from source @@ -130,7 +138,7 @@ ./build.sh - On Windows (inside an msys/MinGW shell): + On Windows (inside an msys/MinGW shell): make -f Makefile.w32 3. Make install: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/the_silver_searcher-2.0.0/configure.ac new/the_silver_searcher-2.1.0/configure.ac --- old/the_silver_searcher-2.0.0/configure.ac 2017-06-04 23:25:51.000000000 +0200 +++ new/the_silver_searcher-2.1.0/configure.ac 2017-08-25 08:16:37.000000000 +0200 @@ -1,6 +1,6 @@ AC_INIT( [the_silver_searcher], - [2.0.0], + [2.1.0], [https://github.com/ggreer/the_silver_searcher/issues], [the_silver_searcher], [https://github.com/ggreer/the_silver_searcher]) @@ -25,7 +25,7 @@ ) # Run CFLAGS="-pg" ./configure if you want debug symbols -if test "`$GREP -c '\b-O' >/dev/null ; echo $?`" = "0" ; then +if ! echo "$CFLAGS" | "$GREP" '\(^\|[[[:space:]]]\)-O' > /dev/null; then CFLAGS="$CFLAGS -O2" fi @@ -59,11 +59,12 @@ AC_CHECK_DECL([PCRE_CONFIG_JIT], [AC_DEFINE([USE_PCRE_JIT], [], [Use PCRE JIT])], [], [#include <pcre.h>]) AC_CHECK_DECL([CPU_ZERO, CPU_SET], [AC_DEFINE([USE_CPU_SET], [], [Use CPU_SET macros])] , [], [#include <sched.h>]) +AC_CHECK_HEADERS([sys/cpuset.h err.h]) AC_CHECK_MEMBER([struct dirent.d_type], [AC_DEFINE([HAVE_DIRENT_DTYPE], [], [Have dirent struct member d_type])], [], [[#include <dirent.h>]]) AC_CHECK_MEMBER([struct dirent.d_namlen], [AC_DEFINE([HAVE_DIRENT_DNAMLEN], [], [Have dirent struct member d_namlen])], [], [[#include <dirent.h>]]) -AC_CHECK_FUNCS(fgetln getline realpath strlcpy strndup vasprintf madvise posix_fadvise pthread_setaffinity_np pledge) +AC_CHECK_FUNCS(fgetln fopencookie getline realpath strlcpy strndup vasprintf madvise posix_fadvise pthread_setaffinity_np pledge) AC_CONFIG_FILES([Makefile the_silver_searcher.spec]) AC_CONFIG_HEADERS([src/config.h]) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/the_silver_searcher-2.0.0/src/config.h.in new/the_silver_searcher-2.1.0/src/config.h.in --- old/the_silver_searcher-2.0.0/src/config.h.in 2017-06-04 23:26:18.000000000 +0200 +++ new/the_silver_searcher-2.1.0/src/config.h.in 2017-08-25 08:16:44.000000000 +0200 @@ -6,9 +6,15 @@ /* Have dirent struct member d_type */ #undef HAVE_DIRENT_DTYPE +/* Define to 1 if you have the <err.h> header file. */ +#undef HAVE_ERR_H + /* Define to 1 if you have the `fgetln' function. */ #undef HAVE_FGETLN +/* Define to 1 if you have the `fopencookie' function. */ +#undef HAVE_FOPENCOOKIE + /* Define to 1 if you have the `getline' function. */ #undef HAVE_GETLINE @@ -63,6 +69,9 @@ /* Define to 1 if you have the `strndup' function. */ #undef HAVE_STRNDUP +/* Define to 1 if you have the <sys/cpuset.h> header file. */ +#undef HAVE_SYS_CPUSET_H + /* Define to 1 if you have the <sys/stat.h> header file. */ #undef HAVE_SYS_STAT_H diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/the_silver_searcher-2.0.0/src/decompress.h new/the_silver_searcher-2.1.0/src/decompress.h --- old/the_silver_searcher-2.0.0/src/decompress.h 2017-01-12 18:55:40.000000000 +0100 +++ new/the_silver_searcher-2.1.0/src/decompress.h 2017-06-28 07:10:58.000000000 +0200 @@ -1,6 +1,8 @@ #ifndef DECOMPRESS_H #define DECOMPRESS_H +#include <stdio.h> + #include "config.h" #include "log.h" #include "options.h" @@ -16,4 +18,9 @@ ag_compression_type is_zipped(const void *buf, const int buf_len); void *decompress(const ag_compression_type zip_type, const void *buf, const int buf_len, const char *dir_full_path, int *new_buf_len); + +#if HAVE_FOPENCOOKIE +FILE *decompress_open(int fd, const char *mode, ag_compression_type ctype); +#endif + #endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/the_silver_searcher-2.0.0/src/lang.c new/the_silver_searcher-2.1.0/src/lang.c --- old/the_silver_searcher-2.0.0/src/lang.c 2017-06-03 06:25:51.000000000 +0200 +++ new/the_silver_searcher-2.1.0/src/lang.c 2017-08-25 07:47:19.000000000 +0200 @@ -7,6 +7,7 @@ lang_spec_t langs[] = { { "actionscript", { "as", "mxml" } }, { "ada", { "ada", "adb", "ads" } }, + { "asciidoc", { "adoc", "ad", "asc", "asciidoc" } }, { "asm", { "asm", "s" } }, { "batch", { "bat", "cmd" } }, { "bitbake", { "bb", "bbappend", "bbclass", "inc" } }, @@ -22,6 +23,7 @@ { "css", { "css" } }, { "cython", { "pyx", "pxd", "pxi" } }, { "delphi", { "pas", "int", "dfm", "nfm", "dof", "dpk", "dpr", "dproj", "groupproj", "bdsgroup", "bdsproj" } }, + { "dot", { "dot", "gv" } }, { "ebuild", { "ebuild", "eclass" } }, { "elisp", { "el" } }, { "elixir", { "ex", "eex", "exs" } }, @@ -35,11 +37,13 @@ { "go", { "go" } }, { "groovy", { "groovy", "gtmpl", "gpp", "grunit", "gradle" } }, { "haml", { "haml" } }, + { "handlebars", { "hbs" } }, { "haskell", { "hs", "lhs" } }, { "haxe", { "hx" } }, { "hh", { "h" } }, { "html", { "htm", "html", "shtml", "xhtml" } }, { "ini", { "ini" } }, + { "ipython", { "ipynb" } }, { "jade", { "jade" } }, { "java", { "java", "properties" } }, { "js", { "es6", "js", "jsx", "vue" } }, @@ -59,16 +63,20 @@ { "mason", { "mas", "mhtml", "mpl", "mtxt" } }, { "matlab", { "m" } }, { "mathematica", { "m", "wl" } }, + { "md", { "markdown", "mdown", "mdwn", "mkdn", "mkd", "md" } }, { "mercury", { "m", "moo" } }, { "nim", { "nim" } }, + { "nix", { "nix" } }, { "objc", { "m", "h" } }, { "objcpp", { "mm", "h" } }, { "ocaml", { "ml", "mli", "mll", "mly" } }, { "octave", { "m" } }, + { "org", { "org" } }, { "parrot", { "pir", "pasm", "pmc", "ops", "pod", "pg", "tg" } }, { "perl", { "pl", "pm", "pm6", "pod", "t" } }, { "php", { "php", "phpt", "php3", "php4", "php5", "phtml" } }, { "pike", { "pike", "pmod" } }, + { "plist", { "plist" } }, { "plone", { "pt", "cpt", "metadata", "cpy", "py", "xml", "zcml" } }, { "proto", { "proto" } }, { "puppet", { "pp" } }, @@ -107,7 +115,7 @@ { "wix", { "wxi", "wxs" } }, { "wsdl", { "wsdl" } }, { "wadl", { "wadl" } }, - { "xml", { "xml", "dtd", "xsl", "xslt", "ent", "tld" } }, + { "xml", { "xml", "dtd", "xsl", "xslt", "ent", "tld", "plist" } }, { "yaml", { "yaml", "yml" } } }; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/the_silver_searcher-2.0.0/src/main.c new/the_silver_searcher-2.1.0/src/main.c --- old/the_silver_searcher-2.0.0/src/main.c 2017-01-12 18:55:42.000000000 +0100 +++ new/the_silver_searcher-2.1.0/src/main.c 2017-06-27 05:33:25.000000000 +0200 @@ -11,10 +11,18 @@ #include "config.h" +#ifdef HAVE_SYS_CPUSET_H +#include <sys/cpuset.h> +#endif + #ifdef HAVE_PTHREAD_H #include <pthread.h> #endif +#if defined(HAVE_PTHREAD_SETAFFINITY_NP) && defined(__FreeBSD__) +#include <pthread_np.h> +#endif + #include "log.h" #include "options.h" #include "search.h" @@ -144,9 +152,13 @@ if (rv != 0) { die("Error in pthread_create(): %s", strerror(rv)); } -#if defined(HAVE_PTHREAD_SETAFFINITY_NP) && defined(USE_CPU_SET) +#if defined(HAVE_PTHREAD_SETAFFINITY_NP) && (defined(USE_CPU_SET) || defined(HAVE_SYS_CPUSET_H)) if (opts.use_thread_affinity) { +#ifdef __linux__ cpu_set_t cpu_set; +#elif __FreeBSD__ + cpuset_t cpu_set; +#endif CPU_ZERO(&cpu_set); CPU_SET(i % num_cores, &cpu_set); rv = pthread_setaffinity_np(workers[i].thread, sizeof(cpu_set), &cpu_set); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/the_silver_searcher-2.0.0/src/print.c new/the_silver_searcher-2.1.0/src/print.c --- old/the_silver_searcher-2.0.0/src/print.c 2017-05-28 08:07:40.000000000 +0200 +++ new/the_silver_searcher-2.1.0/src/print.c 2017-08-25 07:51:57.000000000 +0200 @@ -150,6 +150,7 @@ ssize_t lines_to_print = 0; char sep = '-'; size_t i, j; + int blanks_between_matches = opts.context || opts.after || opts.before; if (opts.ackmate || opts.vimgrep) { sep = ':'; @@ -175,7 +176,7 @@ if (cur_match < matches_len && i == matches[cur_match].start) { print_context.in_a_match = TRUE; /* We found the start of a match */ - if (cur_match > 0 && opts.context && print_context.lines_since_last_match > (opts.before + opts.after + 1)) { + if (cur_match > 0 && blanks_between_matches && print_context.lines_since_last_match > (opts.before + opts.after + 1)) { fprintf(out_fd, "--\n"); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/the_silver_searcher-2.0.0/src/search.c new/the_silver_searcher-2.1.0/src/search.c --- old/the_silver_searcher-2.0.0/src/search.c 2017-06-04 23:06:19.000000000 +0200 +++ new/the_silver_searcher-2.1.0/src/search.c 2017-06-28 07:10:58.000000000 +0200 @@ -357,6 +357,12 @@ if (opts.search_zip_files) { ag_compression_type zip_type = is_zipped(buf, f_len); if (zip_type != AG_NO_COMPRESSION) { +#if HAVE_FOPENCOOKIE + log_debug("%s is a compressed file. stream searching", file_full_path); + fp = decompress_open(fd, "r", zip_type); + search_stream(fp, file_full_path); + fclose(fp); +#else int _buf_len = (int)f_len; char *_buf = decompress(zip_type, buf, f_len, file_full_path, &_buf_len); if (_buf == NULL || _buf_len == 0) { @@ -365,6 +371,7 @@ } search_buf(_buf, _buf_len, file_full_path); free(_buf); +#endif goto cleanup; } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/the_silver_searcher-2.0.0/src/zfile.c new/the_silver_searcher-2.1.0/src/zfile.c --- old/the_silver_searcher-2.0.0/src/zfile.c 1970-01-01 01:00:00.000000000 +0100 +++ new/the_silver_searcher-2.1.0/src/zfile.c 2017-08-25 07:45:20.000000000 +0200 @@ -0,0 +1,403 @@ +#ifdef __FreeBSD__ +#include <sys/endian.h> +#endif +#include <sys/types.h> + +#ifdef __CYGWIN__ +typedef _off64_t off64_t; +#endif + +#include <assert.h> +#include <errno.h> +#include <inttypes.h> +#include <limits.h> +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "config.h" + +#ifdef HAVE_ERR_H +#include <err.h> +#endif +#ifdef HAVE_ZLIB_H +#include <zlib.h> +#endif +#ifdef HAVE_LZMA_H +#include <lzma.h> +#endif + +#include "decompress.h" + +#if HAVE_FOPENCOOKIE + +#define min(a, b) ({ \ + __typeof (a) _a = (a); \ + __typeof (b) _b = (b); \ + _a < _b ? _a : _b; }) + +static cookie_read_function_t zfile_read; +static cookie_seek_function_t zfile_seek; +static cookie_close_function_t zfile_close; + +static const cookie_io_functions_t zfile_io = { + .read = zfile_read, + .write = NULL, + .seek = zfile_seek, + .close = zfile_close, +}; + +#define KB (1024) +struct zfile { + FILE *in; // Source FILE stream + uint64_t logic_offset, // Logical offset in output (forward seeks) + decode_offset, // Where we've decoded to + actual_len; + uint32_t outbuf_start; + + ag_compression_type ctype; + + union { + z_stream gz; + lzma_stream lzma; + } stream; + + uint8_t inbuf[32 * KB]; + uint8_t outbuf[256 * KB]; + bool eof; +}; + +#define CAVAIL_IN(c) ((c)->ctype == AG_GZIP ? (c)->stream.gz.avail_in : (c)->stream.lzma.avail_in) +#define CNEXT_OUT(c) ((c)->ctype == AG_GZIP ? (c)->stream.gz.next_out : (c)->stream.lzma.next_out) + +static int +zfile_cookie_init(struct zfile *cookie) { +#ifdef HAVE_LZMA_H + lzma_ret lzrc; +#endif + int rc; + + assert(cookie->logic_offset == 0); + assert(cookie->decode_offset == 0); + + cookie->actual_len = 0; + + switch (cookie->ctype) { +#ifdef HAVE_ZLIB_H + case AG_GZIP: + memset(&cookie->stream.gz, 0, sizeof cookie->stream.gz); + rc = inflateInit2(&cookie->stream.gz, 32 + 15); + if (rc != Z_OK) { + log_err("Unable to initialize zlib: %s", zError(rc)); + return EIO; + } + cookie->stream.gz.next_in = NULL; + cookie->stream.gz.avail_in = 0; + cookie->stream.gz.next_out = cookie->outbuf; + cookie->stream.gz.avail_out = sizeof cookie->outbuf; + break; +#endif +#ifdef HAVE_LZMA_H + case AG_XZ: + cookie->stream.lzma = (lzma_stream)LZMA_STREAM_INIT; + lzrc = lzma_auto_decoder(&cookie->stream.lzma, -1, 0); + if (lzrc != LZMA_OK) { + log_err("Unable to initialize lzma_auto_decoder: %d", lzrc); + return EIO; + } + cookie->stream.lzma.next_in = NULL; + cookie->stream.lzma.avail_in = 0; + cookie->stream.lzma.next_out = cookie->outbuf; + cookie->stream.lzma.avail_out = sizeof cookie->outbuf; + break; +#endif + default: + log_err("Unsupported compression type: %d", cookie->ctype); + return EINVAL; + } + + + cookie->outbuf_start = 0; + cookie->eof = false; + return 0; +} + +static void +zfile_cookie_cleanup(struct zfile *cookie) { + switch (cookie->ctype) { +#ifdef HAVE_ZLIB_H + case AG_GZIP: + inflateEnd(&cookie->stream.gz); + break; +#endif +#ifdef HAVE_LZMA_H + case AG_XZ: + lzma_end(&cookie->stream.lzma); + break; +#endif + default: + /* Compiler false positive - unreachable. */ + break; + } +} + +/* + * Open compressed file 'path' as a (forward-)seekable (and rewindable), + * read-only stream. + */ +FILE * +decompress_open(int fd, const char *mode, ag_compression_type ctype) { + struct zfile *cookie; + FILE *res, *in; + int error; + + cookie = NULL; + in = res = NULL; + if (strstr(mode, "w") || strstr(mode, "a")) { + errno = EINVAL; + goto out; + } + + in = fdopen(fd, mode); + if (in == NULL) + goto out; + + /* + * No validation of compression type is done -- file is assumed to + * match input. In Ag, the compression type is already detected, so + * that's ok. + */ + cookie = malloc(sizeof *cookie); + if (cookie == NULL) { + errno = ENOMEM; + goto out; + } + + cookie->in = in; + cookie->logic_offset = 0; + cookie->decode_offset = 0; + cookie->ctype = ctype; + + error = zfile_cookie_init(cookie); + if (error != 0) { + errno = error; + goto out; + } + + res = fopencookie(cookie, mode, zfile_io); + +out: + if (res == NULL) { + if (in != NULL) + fclose(in); + if (cookie != NULL) + free(cookie); + } + return res; +} + +/* + * Return number of bytes into buf, 0 on EOF, -1 on error. Update stream + * offset. + */ +static ssize_t +zfile_read(void *cookie_, char *buf, size_t size) { + struct zfile *cookie = cookie_; + size_t nb, ignorebytes; + ssize_t total = 0; + lzma_ret lzret; + int ret; + + assert(size <= SSIZE_MAX); + + if (size == 0) + return 0; + + if (cookie->eof) + return 0; + + ret = Z_OK; + lzret = LZMA_OK; + + ignorebytes = cookie->logic_offset - cookie->decode_offset; + assert(ignorebytes == 0); + + do { + size_t inflated; + + /* Drain output buffer first */ + while (CNEXT_OUT(cookie) > + &cookie->outbuf[cookie->outbuf_start]) { + size_t left = CNEXT_OUT(cookie) - + &cookie->outbuf[cookie->outbuf_start]; + size_t ignoreskip = min(ignorebytes, left); + size_t toread; + + if (ignoreskip > 0) { + ignorebytes -= ignoreskip; + left -= ignoreskip; + cookie->outbuf_start += ignoreskip; + cookie->decode_offset += ignoreskip; + } + + // Ran out of output before we seek()ed up. + if (ignorebytes > 0) + break; + + toread = min(left, size); + memcpy(buf, &cookie->outbuf[cookie->outbuf_start], + toread); + + buf += toread; + size -= toread; + left -= toread; + cookie->outbuf_start += toread; + cookie->decode_offset += toread; + cookie->logic_offset += toread; + total += toread; + + if (size == 0) + break; + } + + if (size == 0) + break; + + /* + * If we have not satisfied read, the output buffer must be + * empty. + */ + assert(cookie->stream.gz.next_out == + &cookie->outbuf[cookie->outbuf_start]); + + if ((cookie->ctype == AG_XZ && lzret == LZMA_STREAM_END) || + (cookie->ctype == AG_GZIP && ret == Z_STREAM_END)) { + cookie->eof = true; + break; + } + + /* Read more input if empty */ + if (CAVAIL_IN(cookie) == 0) { + nb = fread(cookie->inbuf, 1, sizeof cookie->inbuf, + cookie->in); + if (ferror(cookie->in)) { + warn("error read core"); + exit(1); + } + if (nb == 0 && feof(cookie->in)) { + warn("truncated file"); + exit(1); + } + if (cookie->ctype == AG_XZ) { + cookie->stream.lzma.avail_in = nb; + cookie->stream.lzma.next_in = cookie->inbuf; + } else { + cookie->stream.gz.avail_in = nb; + cookie->stream.gz.next_in = cookie->inbuf; + } + } + + /* Reset stream state to beginning of output buffer */ + if (cookie->ctype == AG_XZ) { + cookie->stream.lzma.next_out = cookie->outbuf; + cookie->stream.lzma.avail_out = sizeof cookie->outbuf; + } else { + cookie->stream.gz.next_out = cookie->outbuf; + cookie->stream.gz.avail_out = sizeof cookie->outbuf; + } + cookie->outbuf_start = 0; + + if (cookie->ctype == AG_GZIP) { + ret = inflate(&cookie->stream.gz, Z_NO_FLUSH); + if (ret != Z_OK && ret != Z_STREAM_END) { + log_err("Found mem/data error while decompressing zlib stream: %s", zError(ret)); + return -1; + } + } else { + lzret = lzma_code(&cookie->stream.lzma, LZMA_RUN); + if (lzret != LZMA_OK && lzret != LZMA_STREAM_END) { + log_err("Found mem/data error while decompressing xz/lzma stream: %d", lzret); + return -1; + } + } + inflated = CNEXT_OUT(cookie) - &cookie->outbuf[0]; + cookie->actual_len += inflated; + } while (!ferror(cookie->in) && size > 0); + + assert(total <= SSIZE_MAX); + return total; +} + +static int +zfile_seek(void *cookie_, off64_t *offset_, int whence) { + struct zfile *cookie = cookie_; + off64_t new_offset = 0, offset = *offset_; + + if (whence == SEEK_SET) { + new_offset = offset; + } else if (whence == SEEK_CUR) { + new_offset = (off64_t)cookie->logic_offset + offset; + } else { + /* SEEK_END not ok */ + return -1; + } + + if (new_offset < 0) + return -1; + + /* Backward seeks to anywhere but 0 are not ok */ + if (new_offset < (off64_t)cookie->logic_offset && new_offset != 0) { + return -1; + } + + if (new_offset == 0) { + /* rewind(3) */ + cookie->decode_offset = 0; + cookie->logic_offset = 0; + zfile_cookie_cleanup(cookie); + zfile_cookie_init(cookie); + } else if ((uint64_t)new_offset > cookie->logic_offset) { + /* Emulate forward seek by skipping ... */ + char *buf; + const size_t bsz = 32 * 1024; + + buf = malloc(bsz); + while ((uint64_t)new_offset > cookie->logic_offset) { + size_t diff = min(bsz, + (uint64_t)new_offset - cookie->logic_offset); + ssize_t err = zfile_read(cookie_, buf, diff); + if (err < 0) { + free(buf); + return -1; + } + + /* Seek past EOF gets positioned at EOF */ + if (err == 0) { + assert(cookie->eof); + new_offset = cookie->logic_offset; + break; + } + } + free(buf); + } + + assert(cookie->logic_offset == (uint64_t)new_offset); + + *offset_ = new_offset; + return 0; +} + +static int +zfile_close(void *cookie_) { + struct zfile *cookie = cookie_; + + zfile_cookie_cleanup(cookie); + fclose(cookie->in); + free(cookie); + + return 0; +} + +#endif /* HAVE_FOPENCOOKIE */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/the_silver_searcher-2.0.0/the_silver_searcher.spec new/the_silver_searcher-2.1.0/the_silver_searcher.spec --- old/the_silver_searcher-2.0.0/the_silver_searcher.spec 2017-06-04 23:29:05.000000000 +0200 +++ new/the_silver_searcher-2.1.0/the_silver_searcher.spec 2017-08-25 08:18:09.000000000 +0200 @@ -2,7 +2,7 @@ Name: the_silver_searcher -Version: 2.0.0 +Version: 2.1.0 Release: 1%{?dist} Summary: A code-searching tool similar to ack, but faster
participants (1)
-
root@hilbert.suse.de