libarchive: upgraded package to upstream

Upgraded app-arch/libarchive to version 3.5.1.

BUG=None
TEST=CQ passes

Change-Id: I96a2ae523eb5d4c36737cc66eb8e7734bbf527ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/overlays/portage-stable/+/2923072
Tested-by: Mike Frysinger <vapier@chromium.org>
Auto-Submit: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Sergey Frolov <sfrolov@google.com>
Reviewed-by: Sergey Frolov <sfrolov@google.com>
diff --git a/app-arch/libarchive/Manifest b/app-arch/libarchive/Manifest
index dc4b48a..5a2008c 100644
--- a/app-arch/libarchive/Manifest
+++ b/app-arch/libarchive/Manifest
@@ -1 +1 @@
-DIST libarchive-3.4.2.tar.gz 6979481 BLAKE2B eea90e4751ae487cd1a9b0eecd16598d1b81ffff665ae97a160e3858c8ffe60b82003f081af644f3f32260d0e1d3f3077240125e8279bf8111a79d93c68ac25d SHA512 a8922e54f2e985889d205ee8a0594c1d30dad950438b602a5be6bb1b274a735ad20a48ed484efd458013a0810d26ee4ae76e3a6c820823243d24ea0593ed7021
+DIST libarchive-3.5.1.tar.gz 7008338 BLAKE2B 243dfda2bd4582bbc20679328b89aae0c530475c822dcf9ff25c65df2017b8f18bb616142d6ab016ccea4a5aa1b410d46b913c2ee0afefd2fdb1a41cf51585d9 SHA512 08ddd74bef4cef0981739da202879f36cf7ca33a8f6d438724588efe3ab8477f2f1d0cccf7b8ed0bedfc0c8d0cab16ee3ae5c0c6e83b6811bc650d7d7471a996
diff --git a/app-arch/libarchive/files/libarchive-3.3.3-libressl.patch b/app-arch/libarchive/files/libarchive-3.3.3-libressl.patch
deleted file mode 100644
index 4d7c0ec..0000000
--- a/app-arch/libarchive/files/libarchive-3.3.3-libressl.patch
+++ /dev/null
@@ -1,12 +0,0 @@
---- a/libarchive/archive_openssl_evp_private.h
-+++ b/libarchive/archive_openssl_evp_private.h
-@@ -28,7 +28,8 @@
- #include <openssl/evp.h>
- #include <openssl/opensslv.h>
-
--#if OPENSSL_VERSION_NUMBER < 0x10100000L
-+#if OPENSSL_VERSION_NUMBER < 0x10100000L || \
-+(defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L)
- #include <stdlib.h> /* malloc, free */
- #include <string.h> /* memset */
- static inline EVP_MD_CTX *EVP_MD_CTX_new(void)
diff --git a/app-arch/libarchive/files/libarchive-3.4.0-without_zlib_build_fix.patch b/app-arch/libarchive/files/libarchive-3.4.0-without_zlib_build_fix.patch
deleted file mode 100644
index e0a3167..0000000
--- a/app-arch/libarchive/files/libarchive-3.4.0-without_zlib_build_fix.patch
+++ /dev/null
@@ -1,160 +0,0 @@
-From 64333cef68d7bcc67bef6ecf177fbeaa549b9139 Mon Sep 17 00:00:00 2001
-From: Martin Matuska <martin@matuska.org>
-Date: Sat, 29 Jun 2019 00:20:58 +0200
-Subject: [PATCH] Unbreak compilation without zlib
-
-Fixes #1214
----
- libarchive/archive_read_support_filter_gzip.c | 54 ++++++++++++-------
- libarchive/test/test_read_format_raw.c        |  4 ++
- 2 files changed, 39 insertions(+), 19 deletions(-)
-
-diff --git a/libarchive/archive_read_support_filter_gzip.c b/libarchive/archive_read_support_filter_gzip.c
-index 458b6f729..9fa9e2b0d 100644
---- a/libarchive/archive_read_support_filter_gzip.c
-+++ b/libarchive/archive_read_support_filter_gzip.c
-@@ -131,12 +131,20 @@ archive_read_support_filter_gzip(struct archive *_a)
-  */
- static ssize_t
- peek_at_header(struct archive_read_filter *filter, int *pbits,
--	       struct private_data *state)
-+#ifdef HAVE_ZLIB_H
-+	       struct private_data *state
-+#else
-+	       void *state
-+#endif
-+	      )
- {
- 	const unsigned char *p;
- 	ssize_t avail, len;
- 	int bits = 0;
- 	int header_flags;
-+#ifndef HAVE_ZLIB_H
-+	(void)state; /* UNUSED */
-+#endif
- 
- 	/* Start by looking at the first ten bytes of the header, which
- 	 * is all fixed layout. */
-@@ -153,8 +161,10 @@ peek_at_header(struct archive_read_filter *filter, int *pbits,
- 	bits += 3;
- 	header_flags = p[3];
- 	/* Bytes 4-7 are mod time in little endian. */
-+#ifdef HAVE_ZLIB_H
- 	if (state)
- 		state->mtime = archive_le32dec(p + 4);
-+#endif
- 	/* Byte 8 is deflate flags. */
- 	/* XXXX TODO: return deflate flags back to consume_header for use
- 	   in initializing the decompressor. */
-@@ -171,7 +181,9 @@ peek_at_header(struct archive_read_filter *filter, int *pbits,
- 
- 	/* Null-terminated optional filename. */
- 	if (header_flags & 8) {
-+#ifdef HAVE_ZLIB_H
- 		ssize_t file_start = len;
-+#endif
- 		do {
- 			++len;
- 			if (avail < len)
-@@ -181,11 +193,13 @@ peek_at_header(struct archive_read_filter *filter, int *pbits,
- 				return (0);
- 		} while (p[len - 1] != 0);
- 
-+#ifdef HAVE_ZLIB_H
- 		if (state) {
- 			/* Reset the name in case of repeat header reads. */
- 			free(state->name);
- 			state->name = strdup((const char *)&p[file_start]);
- 		}
-+#endif
- 	}
- 
- 	/* Null-terminated optional comment. */
-@@ -236,24 +250,6 @@ gzip_bidder_bid(struct archive_read_filter_bidder *self,
- 	return (0);
- }
- 
--static int
--gzip_read_header(struct archive_read_filter *self, struct archive_entry *entry)
--{
--	struct private_data *state;
--
--	state = (struct private_data *)self->data;
--
--	/* A mtime of 0 is considered invalid/missing. */
--	if (state->mtime != 0)
--		archive_entry_set_mtime(entry, state->mtime, 0);
--
--	/* If the name is available, extract it. */
--	if (state->name)
--		archive_entry_set_pathname(entry, state->name);
--
--	return (ARCHIVE_OK);
--}
--
- #ifndef HAVE_ZLIB_H
- 
- /*
-@@ -277,6 +273,24 @@ gzip_bidder_init(struct archive_read_filter *self)
- 
- #else
- 
-+static int
-+gzip_read_header(struct archive_read_filter *self, struct archive_entry *entry)
-+{
-+	struct private_data *state;
-+
-+	state = (struct private_data *)self->data;
-+
-+	/* A mtime of 0 is considered invalid/missing. */
-+	if (state->mtime != 0)
-+		archive_entry_set_mtime(entry, state->mtime, 0);
-+
-+	/* If the name is available, extract it. */
-+	if (state->name)
-+		archive_entry_set_pathname(entry, state->name);
-+
-+	return (ARCHIVE_OK);
-+}
-+
- /*
-  * Initialize the filter object.
-  */
-@@ -306,7 +320,9 @@ gzip_bidder_init(struct archive_read_filter *self)
- 	self->read = gzip_filter_read;
- 	self->skip = NULL; /* not supported */
- 	self->close = gzip_filter_close;
-+#ifdef HAVE_ZLIB_H
- 	self->read_header = gzip_read_header;
-+#endif
- 
- 	state->in_stream = 0; /* We're not actually within a stream yet. */
- 
-diff --git a/libarchive/test/test_read_format_raw.c b/libarchive/test/test_read_format_raw.c
-index 0dac8bfba..3961723b4 100644
---- a/libarchive/test/test_read_format_raw.c
-+++ b/libarchive/test/test_read_format_raw.c
-@@ -36,7 +36,9 @@ DEFINE_TEST(test_read_format_raw)
- 	const char *reffile1 = "test_read_format_raw.data";
- 	const char *reffile2 = "test_read_format_raw.data.Z";
- 	const char *reffile3 = "test_read_format_raw.bufr";
-+#ifdef HAVE_ZLIB_H
- 	const char *reffile4 = "test_read_format_raw.data.gz";
-+#endif
- 
- 	/* First, try pulling data out of an uninterpretable file. */
- 	extract_reference_file(reffile1);
-@@ -119,6 +121,7 @@ DEFINE_TEST(test_read_format_raw)
- 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- 	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
- 
-+#ifdef HAVE_ZLIB_H
- 	/* Fourth, try with gzip which has metadata. */
- 	extract_reference_file(reffile4);
- 	assert((a = archive_read_new()) != NULL);
-@@ -144,4 +147,5 @@ DEFINE_TEST(test_read_format_raw)
- 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
- 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- 	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-+#endif
- }
diff --git a/app-arch/libarchive/files/libarchive-3.5.0-darwin-strnlen.patch b/app-arch/libarchive/files/libarchive-3.5.0-darwin-strnlen.patch
new file mode 100644
index 0000000..8f540e4
--- /dev/null
+++ b/app-arch/libarchive/files/libarchive-3.5.0-darwin-strnlen.patch
@@ -0,0 +1,27 @@
+https://github.com/macports/macports-ports/blob/master/archivers/libarchive/files/patch-libarchive-3.5-strnlen.diff
+
+next release should have a fix for this
+
+--- a/libarchive/archive_read_support_format_mtree.c
++++ b/libarchive/archive_read_support_format_mtree.c
+@@ -65,6 +65,20 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_mtree.c 2011
+ #define O_CLOEXEC	0
+ #endif
+ 
++#ifdef __APPLE__
++#if  __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1070
++static size_t strnlen(const char *s, size_t maxlen) {
++  size_t l = 0;
++  while (l < maxlen && *s) {
++    l++;
++    s++;
++  }
++  return l;
++}
++#endif
++#endif
++
++
+ #define	MTREE_HAS_DEVICE	0x0001
+ #define	MTREE_HAS_FFLAGS	0x0002
+ #define	MTREE_HAS_GID		0x0004
diff --git a/app-arch/libarchive/libarchive-3.4.2.ebuild b/app-arch/libarchive/libarchive-3.5.1.ebuild
similarity index 81%
rename from app-arch/libarchive/libarchive-3.4.2.ebuild
rename to app-arch/libarchive/libarchive-3.5.1.ebuild
index 8f8dcf1..ec84407 100644
--- a/app-arch/libarchive/libarchive-3.4.2.ebuild
+++ b/app-arch/libarchive/libarchive-3.5.1.ebuild
@@ -1,4 +1,4 @@
-# Copyright 1999-2020 Gentoo Authors
+# Copyright 1999-2021 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI=7
@@ -11,7 +11,7 @@
 LICENSE="BSD BSD-2 BSD-4 public-domain"
 SLOT="0/13"
 KEYWORDS="*"
-IUSE="acl blake2 +bzip2 +e2fsprogs expat +iconv kernel_linux libressl lz4 +lzma lzo nettle static-libs +threads xattr +zlib zstd"
+IUSE="acl blake2 +bzip2 +e2fsprogs expat +iconv kernel_linux lz4 +lzma lzo nettle static-libs +threads xattr +zlib zstd"
 
 RDEPEND="
 	acl? ( virtual/acl[${MULTILIB_USEDEP}] )
@@ -23,8 +23,7 @@
 	kernel_linux? (
 		xattr? ( sys-apps/attr[${MULTILIB_USEDEP}] )
 	)
-	!libressl? ( dev-libs/openssl:0=[${MULTILIB_USEDEP}] )
-	libressl? ( dev-libs/libressl:0=[${MULTILIB_USEDEP}] )
+	dev-libs/openssl:0=[${MULTILIB_USEDEP}]
 	lz4? ( >=app-arch/lz4-0_p131:0=[${MULTILIB_USEDEP}] )
 	lzma? ( app-arch/xz-utils[threads=,${MULTILIB_USEDEP}] )
 	lzo? ( >=dev-libs/lzo-2[${MULTILIB_USEDEP}] )
@@ -38,13 +37,9 @@
 	)"
 
 PATCHES=(
-	"${FILESDIR}"/${PN}-3.3.3-libressl.patch
+	"${FILESDIR}"/${PN}-3.5.0-darwin-strnlen.patch  # drop on next release
 )
 
-# Various test problems, starting with the fact that sandbox
-# explodes on long paths. https://bugs.gentoo.org/598806
-RESTRICT="test"
-
 src_prepare() {
 	default
 	elibtoolize  # is required for Solaris sol2_ld linker fix
@@ -97,9 +92,21 @@
 	fi
 }
 
+src_test() {
+	mkdir -p "${T}"/bin || die
+	# tests fail when lbzip2[symlink] is used in place of ref bunzip2
+	ln -s "${BROOT}/bin/bunzip2" "${T}"/bin || die
+	local -x PATH=${T}/bin:${PATH}
+	multilib-minimal_src_test
+}
+
 multilib_src_test() {
-	# Replace the default src_test so that it builds tests in parallel
-	multilib_is_native_abi && emake check
+	# sandbox is breaking long symlink behavior
+	local -x SANDBOX_ON=0
+	local -x LD_PRELOAD=
+	# some locales trigger different output that breaks tests
+	local -x LC_ALL=C
+	emake check
 }
 
 multilib_src_install() {