diff --git a/Makefile.am b/Makefile.am index 16a30da..24e4b01 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,8 @@ -SUBDIRS = lzma/C src +SUBDIRS = +if ENABLE_7ZIP +SUBDIRS += lzma/C +endif +SUBDIRS += src man1_MANS = man/ugrep-indexer.1 diff --git a/Makefile.in b/Makefile.in index 4421f60..a1021e0 100644 --- a/Makefile.in +++ b/Makefile.in @@ -87,6 +87,7 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ +@ENABLE_7ZIP_TRUE@am__append_1 = lzma/C subdir = . ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_brotlilib.m4 \ @@ -193,7 +194,7 @@ am__define_uniq_tagged_files = \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` -DIST_SUBDIRS = $(SUBDIRS) +DIST_SUBDIRS = lzma/C src am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in \ README.md ar-lib compile config.guess config.sub depcomp \ install-sh missing @@ -350,7 +351,7 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -SUBDIRS = lzma/C src +SUBDIRS = $(am__append_1) src man1_MANS = man/ugrep-indexer.1 EXTRA_DIST = README.md LICENSE.txt CONTRIBUTING.md CODE_OF_CONDUCT.md all: config.h diff --git a/bin/win32/ugrep-indexer.exe b/bin/win32/ugrep-indexer.exe index 64f2950..c091a86 100755 Binary files a/bin/win32/ugrep-indexer.exe and b/bin/win32/ugrep-indexer.exe differ diff --git a/bin/win64/ugrep-indexer.exe b/bin/win64/ugrep-indexer.exe index 1083390..cf3c187 100755 Binary files a/bin/win64/ugrep-indexer.exe and b/bin/win64/ugrep-indexer.exe differ diff --git a/configure b/configure index e5940fc..3a6267a 100755 --- a/configure +++ b/configure @@ -653,6 +653,8 @@ LIBOBJS PTHREAD_LIBS PTHREAD_CFLAGS EXTRA_CFLAGS +ENABLE_7ZIP_FALSE +ENABLE_7ZIP_TRUE PLATFORM host_os host_vendor @@ -7808,6 +7810,14 @@ printf "%s\n" "yes" >&6; } fi fi + if test "x$with_7zip" = "xyes"; then + ENABLE_7ZIP_TRUE= + ENABLE_7ZIP_FALSE='#' +else + ENABLE_7ZIP_TRUE='#' + ENABLE_7ZIP_FALSE= +fi + PTHREAD_CFLAGS="" @@ -7959,6 +7969,10 @@ if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then as_fn_error $? "conditional \"am__fastdepCC\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi +if test -z "${ENABLE_7ZIP_TRUE}" && test -z "${ENABLE_7ZIP_FALSE}"; then + as_fn_error $? "conditional \"ENABLE_7ZIP\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi : "${CONFIG_STATUS=./config.status}" ac_write_fail=0 diff --git a/configure.ac b/configure.ac index c1b6457..b133c9c 100644 --- a/configure.ac +++ b/configure.ac @@ -76,6 +76,7 @@ else fi fi +AM_CONDITIONAL([ENABLE_7ZIP],[test "x$with_7zip" = "xyes"]) AC_SUBST(EXTRA_CFLAGS) AC_SUBST([PTHREAD_CFLAGS], [""]) diff --git a/lzma/7zls.c b/lzma/7zls.c index 34639db..bb28b00 100644 --- a/lzma/7zls.c +++ b/lzma/7zls.c @@ -34,6 +34,11 @@ @copyright (c) BSD-3 License - see LICENSE.txt */ +/* to build and run 7zls: + cc -o 7zls 7zls.c C/libviiz.a + ./7zls ../tests/archive.7z +*/ + #include #include #include diff --git a/lzma/C/7zCrc.c b/lzma/C/7zCrc.c index c995a8b..bcd318c 100644 --- a/lzma/C/7zCrc.c +++ b/lzma/C/7zCrc.c @@ -84,8 +84,9 @@ UInt32 Z7_FASTCALL CrcUpdateT1(UInt32 v, const void *data, size_t size, const UI #endif #endif #endif - #elif (defined(__clang__) && (__clang_major__ >= 3)) \ - || (defined(__GNUC__) && (__GNUC__ > 4)) + #elif ( (defined(__clang__) && (__clang_major__ >= 3)) || \ + (defined(__GNUC__) && (__GNUC__ > 4) ) ) && \ + (__ARM_ARCH >= 8) #if !defined(__ARM_FEATURE_CRC32) #define __ARM_FEATURE_CRC32 1 #if defined(__clang__) diff --git a/lzma/C/Makefile.in b/lzma/C/Makefile.in index 3abdfba..3f3d47c 100644 --- a/lzma/C/Makefile.in +++ b/lzma/C/Makefile.in @@ -90,13 +90,11 @@ build_triplet = @build@ host_triplet = @host@ subdir = lzma/C ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/ax_boost_regex.m4 \ - $(top_srcdir)/m4/ax_check_brotlilib.m4 \ +am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_brotlilib.m4 \ $(top_srcdir)/m4/ax_check_bz2lib.m4 \ $(top_srcdir)/m4/ax_check_bzip3lib.m4 \ $(top_srcdir)/m4/ax_check_lz4lib.m4 \ $(top_srcdir)/m4/ax_check_lzmalib.m4 \ - $(top_srcdir)/m4/ax_check_pcre2.m4 \ $(top_srcdir)/m4/ax_check_zlib.m4 \ $(top_srcdir)/m4/ax_check_zstdlib.m4 \ $(top_srcdir)/m4/ax_cxx_compile_stdcxx.m4 \ @@ -212,9 +210,6 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ -BASH_COMPLETION_CFLAGS = @BASH_COMPLETION_CFLAGS@ -BASH_COMPLETION_DIR = @BASH_COMPLETION_DIR@ -BASH_COMPLETION_LIBS = @BASH_COMPLETION_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -222,7 +217,6 @@ CPPFLAGS = @CPPFLAGS@ CSCOPE = @CSCOPE@ CTAGS = @CTAGS@ CXX = @CXX@ -CXXCPP = @CXXCPP@ CXXDEPMODE = @CXXDEPMODE@ CXXFLAGS = @CXXFLAGS@ CYGPATH_W = @CYGPATH_W@ @@ -234,10 +228,6 @@ ECHO_T = @ECHO_T@ ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ EXTRA_CFLAGS = @EXTRA_CFLAGS@ -FISH_COMPLETION_CFLAGS = @FISH_COMPLETION_CFLAGS@ -FISH_COMPLETION_DIR = @FISH_COMPLETION_DIR@ -FISH_COMPLETION_LIBS = @FISH_COMPLETION_LIBS@ -GREP_PATH = @GREP_PATH@ HAVE_CXX11 = @HAVE_CXX11@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ @@ -260,22 +250,14 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ -PKG_CONFIG = @PKG_CONFIG@ -PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ -PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PLATFORM = @PLATFORM@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_LIBS = @PTHREAD_LIBS@ RANLIB = @RANLIB@ -SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ -SIMD_AVX2_FLAGS = @SIMD_AVX2_FLAGS@ -SIMD_AVX512BW_FLAGS = @SIMD_AVX512BW_FLAGS@ -SIMD_FLAGS = @SIMD_FLAGS@ STRIP = @STRIP@ VERSION = @VERSION@ -ZSH_COMPLETION_DIR = @ZSH_COMPLETION_DIR@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ diff --git a/lzma/C/README.txt b/lzma/C/README.txt index 63b57c6..9c772dd 100644 --- a/lzma/C/README.txt +++ b/lzma/C/README.txt @@ -6,6 +6,9 @@ LZMA SDK is placed in the public domain. LZMA SDK by Igor Pavlov. +Updated to apply YOKOTA Hiroshi's patches: +https://salsa.debian.org/debian/7zip/-/blob/master/debian/patches/0002-Disable-hardware-acceleration-support-on-armel.patch?ref_type=heads + Included in this directory is a new C API to simplify decompression: - viizip.h declarations, see below (hides implementation details) diff --git a/lzma/C/viizip.c b/lzma/C/viizip.c index d6d7bef..ead1dbf 100644 --- a/lzma/C/viizip.c +++ b/lzma/C/viizip.c @@ -333,10 +333,11 @@ int viiget(struct viizip *viizip, char *name, size_t max, time_t *mtime, uint64_ return res == SZ_OK ? 0 : -1; } -/* decompress up to len bytes into buf[], return number of bytes decompressed */ +/* decompress up to len bytes into buf[], return number of bytes decompressed or -1 on error */ ssize_t viidec(struct viizip *viizip, unsigned char *buf, size_t len) { - if (viizip == NULL) + /* if not initialized or not called viiget() then return error */ + if (viizip == NULL || viizip->index == 0) return -1; switch (viizip->state) diff --git a/man/ugrep-indexer.1 b/man/ugrep-indexer.1 index bffd374..cc426fd 100644 --- a/man/ugrep-indexer.1 +++ b/man/ugrep-indexer.1 @@ -1,4 +1,4 @@ -.TH UGREP-INDEXER "1" "December 31, 2023" "ugrep-indexer 0.9.5" "User Commands" +.TH UGREP-INDEXER "1" "February 29, 2024" "ugrep-indexer 0.9.6" "User Commands" .SH NAME \fBugrep-indexer\fR -- file indexer to accelerate recursive searching .SH SYNOPSIS @@ -33,7 +33,7 @@ Specifies indexing accuracy. A low accuracy reduces the indexing storage overhead at the cost of a higher rate of false positive pattern matches (more noise). A high accuracy reduces the rate of false positive regex pattern matches (less noise) at the cost of an -increased indexing storage overhead. An accuracy between 3 and 7 +increased indexing storage overhead. An accuracy between 2 and 7 is recommended. The default accuracy is 5. .TP \fB\-.\fR, \fB\-\-hidden\fR diff --git a/src/ugrep-indexer.cpp b/src/ugrep-indexer.cpp index 756f802..876f3b0 100644 --- a/src/ugrep-indexer.cpp +++ b/src/ugrep-indexer.cpp @@ -34,7 +34,7 @@ @copyright (c) BSD-3 License - see LICENSE.txt */ -#define UGREP_INDEXER_VERSION "0.9.5 beta" +#define UGREP_INDEXER_VERSION "0.9.6" // use a task-parallel thread to decompress the stream into a pipe to search, also handles nested archives #define WITH_DECOMPRESSION_THREAD @@ -350,6 +350,10 @@ struct Stream { void close() { + // close input separately when not associated with the file + if (input.file() != file && input.file() != NULL) + fclose(input.file()); + // close the file if (file != NULL) fclose(file); file = NULL; @@ -367,6 +371,14 @@ struct Stream { if (flag_decompress) { + // close the underlying pipe previously created with pipe() and fdopen() + if (input.file() != NULL) + { + // close and unassign input + fclose(input.file()); + input.clear(); + } + partname.clear(); // start decompression thread if not running, get pipe with decompressed input @@ -378,7 +390,7 @@ struct Stream { } // read archive/compressed/plain data from the decompression thread chain pipe - input = reflex::Input(pipe_in); + input = pipe_in; } else { @@ -434,10 +446,10 @@ struct Stream { // -z: open next archived file if any or close the compressed file/archive if (flag_decompress) { - // close the input FILE* and its underlying pipe previously created with pipe() and fdopen() + // close the pipe previously created with pipe() and fdopen() if (input.file() != NULL) { - // close and unassign input, i.e. input.file() == NULL, also closes pipe_fd[0] per fdopen() + // close and unassign input fclose(input.file()); input.clear(); } @@ -449,7 +461,7 @@ struct Stream { if (pipe_in != NULL) { // assign the next extracted file as input to search - input = reflex::Input(pipe_in); + input = pipe_in; // start searching the next file in the archive return true; diff --git a/src/zstream.hpp b/src/zstream.hpp index 6439a6c..a0dd262 100644 --- a/src/zstream.hpp +++ b/src/zstream.hpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -538,8 +539,8 @@ class zstreambuf : public std::streambuf { // read and decompress zip file data into buf[0..len-1], return number of bytes decompressed, 0 for EOF or -1 for error std::streamsize decompress(unsigned char *buf, size_t len) { - // if no more data to decompress, then return 0 to indicate EOF - if (zend_) + // if header() was not called or no more data to decompress, then return 0 to indicate EOF + if (znew_ || zend_) return 0; std::streamsize num = 0; @@ -1362,8 +1363,8 @@ class zstreambuf : public std::streambuf { catch (const std::invalid_argument&) { - /* non-seekable 7zip files cannot be decompressed, */ - cannot_decompress("non-seekable 7zip archive", pathname); + /* non-seekable and password-protected 7zip files cannot be decompressed */ + cannot_decompress("7zip archive: encrypted data or 7z input is not seekable", pathname); file_ = NULL; }