]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
bsdunzip: make it possible to pass filenames starting with dash
authorMingye Wang <arthur200126@gmail.com>
Sat, 27 May 2023 13:28:23 +0000 (21:28 +0800)
committerMartin Matuška <martin@matuska.de>
Thu, 13 Jul 2023 22:55:38 +0000 (00:55 +0200)
We now check for residual arguments after the second scan, so any filename protected by `--` is picked up.

unzip/bsdunzip.1
unzip/bsdunzip.c

index 1bf76ead31ae9fd5a184652484606b1dd83d8349..3c656ebc46e268875d3fbe1351e5243c061bdb6e 100644 (file)
@@ -201,3 +201,16 @@ It uses the
 .Xr archive 3
 library developed by
 .An Tim Kientzle Aq Mt kientzle@FreeBSD.org .
+.Sh CAVEATS
+The
+.Nm
+utility performs two scans of the command-line for arguments before
+and after the archive name, so as to maintain compatibility with
+Info-ZIP unzip.
+As a result, the POSIX
+.Ql --
+double-dash string used to separate options from arguments will need to
+be repeated.
+For example, to extract a "-a.jpg" from "-b.zip" with overwrite, one
+would need to invoke
+.Dl bsdunzip -o -- -a.jpg -- -b.zip 
index 1d9a99b513fcff1feeea0c348f60c62a01334daf..e1b9ca5aa6265f40d45b6eba363ae8d943f9ce5a 100644 (file)
@@ -1114,6 +1114,10 @@ main(int argc, char *argv[])
        for (int i = 0; i < argc; ++i)
                debug("%s%c", argv[i], (i < argc - 1) ? ' ' : '\n');
 
+#ifdef __GLIBC__
+       /* Prevent GNU getopt(3) from rearranging options. */
+       setenv("POSIXLY_CORRECT", "");
+#endif
        /*
         * Info-ZIP's unzip(1) expects certain options to come before the
         * zipfile name, and others to come after - though it does not
@@ -1144,6 +1148,10 @@ main(int argc, char *argv[])
        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++]);
+
        if (n_opt + o_opt + u_opt > 1)
                errorx("-n, -o and -u are contradictory");