aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Matuska <mm@FreeBSD.org>2023-08-03 22:59:05 +0000
committerMartin Matuska <mm@FreeBSD.org>2023-08-03 22:59:05 +0000
commit80517d0d48d96fdd3e9c80d30eb30289d5004133 (patch)
tree41212a02144efd7183aa6e569e864c2cd3921622
parentf8035ed8e51381281e5718a81233fa41b5b9e1d0 (diff)
downloadsrc-80517d0d48d96fdd3e9c80d30eb30289d5004133.tar.gz
src-80517d0d48d96fdd3e9c80d30eb30289d5004133.zip
Update vendor/libarchive to libarchive/libarchive@5c5a9f2b7
Changes to not yet connected unzip command only. Obtained from: libarchive Libarchive commit: 5c5a9f2b76ed51f060752b356c9e96ef3aee1baf
-rw-r--r--build/cmake/config.h.in6
-rw-r--r--unzip/bsdunzip.c19
-rw-r--r--unzip/bsdunzip.h7
-rw-r--r--unzip/cmdline.c2
-rw-r--r--unzip/test/test_d.c22
-rw-r--r--unzip/test/test_x.c40
6 files changed, 85 insertions, 11 deletions
diff --git a/build/cmake/config.h.in b/build/cmake/config.h.in
index 08a3196f2a6d..71d54a4cec71 100644
--- a/build/cmake/config.h.in
+++ b/build/cmake/config.h.in
@@ -1032,6 +1032,12 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the `strrchr' function. */
#cmakedefine HAVE_STRRCHR 1
+/* Define to 1 if the system has the type `struct statfs'. */
+#cmakedefine HAVE_STRUCT_STATFS 1
+
+/* Define to 1 if `f_iosize' is a member of `struct statfs'. */
+#cmakedefine HAVE_STRUCT_STATFS_F_IOSIZE 1
+
/* Define to 1 if `f_namemax' is a member of `struct statfs'. */
#cmakedefine HAVE_STRUCT_STATFS_F_NAMEMAX 1
diff --git a/unzip/bsdunzip.c b/unzip/bsdunzip.c
index b8f6ff4bbf95..29c3a1670483 100644
--- a/unzip/bsdunzip.c
+++ b/unzip/bsdunzip.c
@@ -113,6 +113,9 @@ static int zipinfo_mode;
/* running on tty? */
static int tty;
+/* processing exclude list */
+static int unzip_exclude_mode = 0;
+
int bsdunzip_optind;
/* convenience macro */
@@ -1114,6 +1117,7 @@ getopts(int argc, char *argv[])
bsdunzip->argc = argc;
while ((opt = bsdunzip_getopt(bsdunzip)) != -1) {
+ unzip_exclude_mode = 0;
switch (opt) {
case 'a':
a_opt = 1;
@@ -1171,6 +1175,7 @@ getopts(int argc, char *argv[])
break;
case 'x':
add_pattern(&exclude, bsdunzip->argument);
+ unzip_exclude_mode = 1;
break;
case 'y':
y_str = " ";
@@ -1245,12 +1250,26 @@ main(int argc, char *argv[])
if (strcmp(zipfile, "-") == 0)
zipfile = NULL; /* STDIN */
+ unzip_exclude_mode = 0;
+
while (nopts < argc && *argv[nopts] != '-')
add_pattern(&include, argv[nopts++]);
nopts--; /* fake argv[0] */
nopts += getopts(argc - nopts, argv + nopts);
+ /*
+ * For compatibility with Info-ZIP's unzip(1) we need to treat
+ * non-option arguments following an -x after the zipfile as
+ * exclude list members.
+ */
+ if (unzip_exclude_mode) {
+ while (nopts < argc && *argv[nopts] != '-')
+ add_pattern(&exclude, argv[nopts++]);
+ nopts--; /* fake argv[0] */
+ nopts += getopts(argc - nopts, argv + nopts);
+ }
+
/* There may be residual arguments if we encountered -- */
while (nopts < argc)
add_pattern(&include, argv[nopts++]);
diff --git a/unzip/bsdunzip.h b/unzip/bsdunzip.h
index 12b65cefb466..ab81e3930ec2 100644
--- a/unzip/bsdunzip.h
+++ b/unzip/bsdunzip.h
@@ -48,11 +48,6 @@ struct bsdunzip {
const char *argument;
};
-struct bsdunzip_getopt_ret {
- int index;
- int opt;
-};
-
enum {
OPTION_NONE,
OPTION_VERSION
@@ -60,4 +55,6 @@ enum {
int bsdunzip_getopt(struct bsdunzip *);
+extern int bsdunzip_optind;
+
#endif
diff --git a/unzip/cmdline.c b/unzip/cmdline.c
index 95d4f99b8242..76eb423de116 100644
--- a/unzip/cmdline.c
+++ b/unzip/cmdline.c
@@ -43,8 +43,6 @@ __FBSDID("$FreeBSD$");
#include "bsdunzip.h"
#include "err.h"
-extern int bsdunzip_optind;
-
/*
* Short options for bsdunzip. Please keep this sorted.
*/
diff --git a/unzip/test/test_d.c b/unzip/test/test_d.c
index 64950cbbe165..01ab9b8caaa3 100644
--- a/unzip/test/test_d.c
+++ b/unzip/test/test_d.c
@@ -25,8 +25,8 @@
*/
#include "test.h"
-/* Test d arg - extract to target dir */
-DEFINE_TEST(test_d)
+/* Test d arg - extract to target dir - before zipfile argument */
+DEFINE_TEST(test_d_before_zipfile)
{
const char *reffile = "test_basic.zip";
int r;
@@ -42,3 +42,21 @@ DEFINE_TEST(test_d)
assertTextFileContents("contents c\n", "foobar/test_basic/c");
assertTextFileContents("contents CAPS\n", "foobar/test_basic/CAPS");
}
+
+/* Test d arg - extract to target dir - after zipfile argument */
+DEFINE_TEST(test_d_after_zipfile)
+{
+ const char *reffile = "test_basic.zip";
+ int r;
+
+ extract_reference_file(reffile);
+ r = systemf("%s %s -d foobar >test.out 2>test.err", testprog, reffile);
+ assertEqualInt(0, r);
+ assertNonEmptyFile("test.out");
+ assertEmptyFile("test.err");
+
+ assertTextFileContents("contents a\n", "foobar/test_basic/a");
+ assertTextFileContents("contents b\n", "foobar/test_basic/b");
+ assertTextFileContents("contents c\n", "foobar/test_basic/c");
+ assertTextFileContents("contents CAPS\n", "foobar/test_basic/CAPS");
+}
diff --git a/unzip/test/test_x.c b/unzip/test/test_x.c
index 21f01bf65da8..d55376849ce9 100644
--- a/unzip/test/test_x.c
+++ b/unzip/test/test_x.c
@@ -25,8 +25,8 @@
*/
#include "test.h"
-/* Test x arg - Exclude paths */
-DEFINE_TEST(test_x)
+/* Test x arg with single exclude path */
+DEFINE_TEST(test_x_single)
{
const char *reffile = "test_basic.zip";
int r;
@@ -42,3 +42,39 @@ DEFINE_TEST(test_x)
assertFileNotExists("test_basic/c");
assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
}
+
+/* Test x arg with multiple exclude paths */
+DEFINE_TEST(test_x_multiple)
+{
+ const char *reffile = "test_basic.zip";
+ int r;
+
+ extract_reference_file(reffile);
+ r = systemf("%s %s -x test_basic/c test_basic/b >test.out 2>test.err", testprog, reffile);
+ assertEqualInt(0, r);
+ assertNonEmptyFile("test.out");
+ assertEmptyFile("test.err");
+
+ assertTextFileContents("contents a\n", "test_basic/a");
+ assertFileNotExists("test_basic/b");
+ assertFileNotExists("test_basic/c");
+ assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
+}
+
+/* Test x arg with multiple exclude paths and a d arg afterwards */
+DEFINE_TEST(test_x_multiple_with_d)
+{
+ const char *reffile = "test_basic.zip";
+ int r;
+
+ extract_reference_file(reffile);
+ r = systemf("%s %s -x test_basic/c test_basic/b -d foobar >test.out 2>test.err", testprog, reffile);
+ assertEqualInt(0, r);
+ assertNonEmptyFile("test.out");
+ assertEmptyFile("test.err");
+
+ assertTextFileContents("contents a\n", "foobar/test_basic/a");
+ assertFileNotExists("foobar/test_basic/b");
+ assertFileNotExists("foobar/test_basic/c");
+ assertTextFileContents("contents CAPS\n", "foobar/test_basic/CAPS");
+}