mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 21:05:08 +00:00
unzip: swtich to bsdunzip from libarchive
Unzip from FreeBSD has been ported to libarchive. Change usr.bin/unzip to use bsdunzip from libarchive. Differential Revision: https://reviews.freebsd.org/D41239 PR: 272845 (exp-run) MFC after: 1 month
This commit is contained in:
parent
dd3055a75f
commit
b5a3a89c50
|
@ -1134,6 +1134,8 @@
|
|||
..
|
||||
uniq
|
||||
..
|
||||
unzip
|
||||
..
|
||||
vmstat
|
||||
..
|
||||
wc
|
||||
|
|
|
@ -113,6 +113,8 @@
|
|||
#define HAVE_FCNTL 1
|
||||
#define HAVE_FCNTL_H 1
|
||||
#define HAVE_FDOPENDIR 1
|
||||
#define HAVE_FNMATCH 1
|
||||
#define HAVE_FNMATCH_H 1
|
||||
#define HAVE_FORK 1
|
||||
#define HAVE_FSEEKO 1
|
||||
#define HAVE_FSTAT 1
|
||||
|
@ -125,6 +127,8 @@
|
|||
#define HAVE_GETEUID 1
|
||||
#define HAVE_GETGRGID_R 1
|
||||
#define HAVE_GETGRNAM_R 1
|
||||
#define HAVE_GETLINE 1
|
||||
#define HAVE_GETOPT_OPTRESET 1
|
||||
#define HAVE_GETPID 1
|
||||
#define HAVE_GETPWNAM_R 1
|
||||
#define HAVE_GETPWUID_R 1
|
||||
|
@ -205,6 +209,7 @@
|
|||
#define HAVE_SYS_MOUNT_H 1
|
||||
#define HAVE_SYS_PARAM_H 1
|
||||
#define HAVE_SYS_POLL_H 1
|
||||
#define HAVE_SYS_QUEUE_H 1
|
||||
#define HAVE_SYS_SELECT_H 1
|
||||
#define HAVE_SYS_STATVFS_H 1
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
|
|
@ -1,6 +1,32 @@
|
|||
# $FreeBSD$
|
||||
|
||||
PROG = unzip
|
||||
.include <src.opts.mk>
|
||||
|
||||
_LIBARCHIVEDIR= ${SRCTOP}/contrib/libarchive
|
||||
_LIBARCHIVECONFDIR= ${SRCTOP}/lib/libarchive
|
||||
|
||||
PROG= bsdunzip
|
||||
|
||||
BSDUNZIP_VERSION_STRING!= sed -n '/define.*ARCHIVE_VERSION_ONLY_STRING/{s,[^0-9.],,gp;q;}' \
|
||||
${_LIBARCHIVEDIR}/libarchive/archive.h
|
||||
|
||||
.PATH: ${_LIBARCHIVEDIR}/unzip
|
||||
SRCS= bsdunzip.c
|
||||
|
||||
.PATH: ${_LIBARCHIVEDIR}/libarchive_fe
|
||||
SRCS+= cmdline.c err.c passphrase.c
|
||||
|
||||
CFLAGS+= -DBSDUNZIP_VERSION_STRING=\"${BSDUNZIP_VERSION_STRING}\"
|
||||
CFLAGS+= -DPLATFORM_CONFIG_H=\"${_LIBARCHIVECONFDIR}/config_freebsd.h\"
|
||||
CFLAGS+= -I${_LIBARCHIVEDIR}/unzip -I${_LIBARCHIVEDIR}/libarchive_fe
|
||||
|
||||
LIBADD= archive
|
||||
|
||||
SYMLINKS=bsdunzip ${BINDIR}/unzip
|
||||
MLINKS= bsdunzip.1 unzip.1
|
||||
|
||||
HAS_TESTS=
|
||||
SUBDIR.${MK_TESTS}+= tests
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
# DO NOT DELETE
|
||||
|
|
74
usr.bin/unzip/tests/Makefile
Normal file
74
usr.bin/unzip/tests/Makefile
Normal file
|
@ -0,0 +1,74 @@
|
|||
# $FreeBSD$
|
||||
|
||||
PACKAGE= tests
|
||||
|
||||
_LIBARCHIVEDIR= ${SRCTOP}/contrib/libarchive
|
||||
|
||||
ATF_TESTS_SH+= functional_test
|
||||
|
||||
BINDIR= ${TESTSDIR}
|
||||
|
||||
PROGS+= bsdunzip_test
|
||||
|
||||
CFLAGS+= -DPLATFORM_CONFIG_H=\"${SRCTOP}/lib/libarchive/config_freebsd.h\"
|
||||
CFLAGS+= -I${SRCTOP}/lib/libarchive -I${.OBJDIR}
|
||||
|
||||
CFLAGS+= -I${.OBJDIR}
|
||||
CFLAGS+= -I${_LIBARCHIVEDIR}/unzip -I${_LIBARCHIVEDIR}/unzip/test
|
||||
CFLAGS+= -I${_LIBARCHIVEDIR}/libarchive
|
||||
CFLAGS+= -I${_LIBARCHIVEDIR}/libarchive_fe -I${_LIBARCHIVEDIR}/test_utils
|
||||
|
||||
# Uncomment to link against dmalloc
|
||||
#LDADD+= -L/usr/local/lib -ldmalloc
|
||||
#CFLAGS+= -I/usr/local/include -DUSE_DMALLOC
|
||||
|
||||
CFLAGS.test_utils.c+= -Wno-cast-align
|
||||
|
||||
.PATH: ${_LIBARCHIVEDIR}/libarchive_fe
|
||||
UNZIP_SRCS+= err.c
|
||||
|
||||
.PATH: ${_LIBARCHIVEDIR}/unzip/test
|
||||
TESTS_SRCS= \
|
||||
test_0.c \
|
||||
test_C.c \
|
||||
test_L.c \
|
||||
test_P_encryption.c \
|
||||
test_Z1.c \
|
||||
test_basic.c \
|
||||
test_d.c \
|
||||
test_glob.c \
|
||||
test_j.c \
|
||||
test_n.c \
|
||||
test_not_exist.c \
|
||||
test_o.c \
|
||||
test_p.c \
|
||||
test_q.c \
|
||||
test_singlefile.c \
|
||||
test_t.c \
|
||||
test_t_bad.c \
|
||||
test_version.c \
|
||||
test_x.c
|
||||
|
||||
SRCS.bsdunzip_test= list.h \
|
||||
${UNZIP_SRCS} \
|
||||
${TESTS_SRCS}
|
||||
|
||||
.PATH: ${_LIBARCHIVEDIR}/test_utils
|
||||
SRCS.bsdunzip_test+= test_main.c \
|
||||
test_utils.c
|
||||
|
||||
LIBADD.bsdunzip_test= archive
|
||||
|
||||
list.h: ${TESTS_SRCS} Makefile
|
||||
@(cd ${_LIBARCHIVEDIR}/unzip/test && \
|
||||
grep -h DEFINE_TEST ${.ALLSRC:N*Makefile}) > ${.TARGET}.tmp
|
||||
@mv ${.TARGET}.tmp ${.TARGET}
|
||||
|
||||
CLEANFILES+= list.h list.h.tmp
|
||||
|
||||
${PACKAGE}FILES+= test_basic.zip.uu
|
||||
${PACKAGE}FILES+= test_encrypted.zip.uu
|
||||
${PACKAGE}FILES+= test_singlefile.zip.uu
|
||||
${PACKAGE}FILES+= test_t_bad.zip.uu
|
||||
|
||||
.include <bsd.test.mk>
|
24
usr.bin/unzip/tests/Makefile.depend
Normal file
24
usr.bin/unzip/tests/Makefile.depend
Normal file
|
@ -0,0 +1,24 @@
|
|||
# $FreeBSD$
|
||||
# Autogenerated - do NOT edit!
|
||||
|
||||
DIRDEPS = \
|
||||
gnu/lib/csu \
|
||||
include \
|
||||
include/xlocale \
|
||||
lib/${CSU_DIR} \
|
||||
lib/libarchive \
|
||||
lib/libbz2 \
|
||||
lib/libc \
|
||||
lib/libcompiler_rt \
|
||||
lib/libexpat \
|
||||
lib/liblzma \
|
||||
lib/libthr \
|
||||
lib/libz \
|
||||
secure/lib/libcrypto \
|
||||
|
||||
|
||||
.include <dirdeps.mk>
|
||||
|
||||
.if ${DEP_RELDIR} == ${_DEP_RELDIR}
|
||||
# local dependencies - needed for -jN in clean tree
|
||||
.endif
|
56
usr.bin/unzip/tests/functional_test.sh
Executable file
56
usr.bin/unzip/tests/functional_test.sh
Executable file
|
@ -0,0 +1,56 @@
|
|||
#
|
||||
# Copyright 2015 EMC Corp.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# $FreeBSD$
|
||||
|
||||
SRCDIR=$(atf_get_srcdir)
|
||||
TESTER="${SRCDIR}/bsdunzip_test"
|
||||
export BSDUNZIP=$(which bsdunzip)
|
||||
|
||||
check()
|
||||
{
|
||||
local testcase=${1}; shift
|
||||
|
||||
# For some odd reason /bin/sh spuriously writes
|
||||
# "write error on stdout" with some of the testcases
|
||||
#
|
||||
# Probably an issue with how they're written as it calls system(3) to
|
||||
# clean up directories..
|
||||
atf_check -e ignore -o ignore -s exit:0 ${TESTER} -d -r "${SRCDIR}" -v "${testcase}"
|
||||
}
|
||||
|
||||
atf_init_test_cases()
|
||||
{
|
||||
# Redirect stderr to stdout for the usage message because if you don't
|
||||
# kyua list/kyua test will break:
|
||||
# https://github.com/jmmv/kyua/issues/149
|
||||
testcases=$(${TESTER} -h 2>&1 | awk 'p != 0 && $1 ~ /^[0-9]+:/ { print $NF } /Available tests:/ { p=1 }')
|
||||
for testcase in ${testcases}; do
|
||||
atf_test_case ${testcase}
|
||||
eval "${testcase}_body() { check ${testcase}; }"
|
||||
atf_add_test_case ${testcase}
|
||||
done
|
||||
}
|
|
@ -1,207 +0,0 @@
|
|||
.\"-
|
||||
.\" Copyright (c) 2007-2008 Dag-Erling Smørgrav
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd June 27, 2023
|
||||
.Dt UNZIP 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm unzip
|
||||
.Nd extract files from a ZIP archive
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl aCcfjLlnopqtuvy
|
||||
.Op { Fl O | Fl I No } Ar encoding
|
||||
.Op Fl d Ar dir
|
||||
.Op Fl x Ar pattern
|
||||
.Op Fl P Ar password
|
||||
.Ar zipfile
|
||||
.Op Ar member ...
|
||||
.Sh DESCRIPTION
|
||||
.\" ...
|
||||
The following options are available:
|
||||
.Bl -tag -width Fl
|
||||
.It Fl a
|
||||
When extracting a text file, convert DOS-style line endings to
|
||||
Unix-style line endings.
|
||||
.It Fl C
|
||||
Match file names case-insensitively.
|
||||
.It Fl c
|
||||
Extract to stdout/screen.
|
||||
When extracting files from the zipfile, they are written to stdout.
|
||||
This is similar to
|
||||
.Fl p ,
|
||||
but does not suppress normal output.
|
||||
.It Fl d Ar dir
|
||||
Extract files into the specified directory rather than the current
|
||||
directory.
|
||||
.It Fl f
|
||||
Update existing.
|
||||
Extract only files from the zipfile if a file with the same name
|
||||
already exists on disk and is older than the former.
|
||||
Otherwise, the file is silently skipped.
|
||||
.It Fl I Ar encoding
|
||||
.It Fl O Ar encoding
|
||||
Convert filenames from the specified encoding.
|
||||
.It Fl j
|
||||
Ignore directories stored in the zipfile; instead, extract all files
|
||||
directly into the extraction directory.
|
||||
.It Fl L
|
||||
Convert the names of the extracted files and directories to lowercase.
|
||||
.It Fl l
|
||||
List, rather than extract, the contents of the zipfile.
|
||||
.It Fl n
|
||||
No overwrite.
|
||||
When extracting a file from the zipfile, if a file with the same name
|
||||
already exists on disk, the file is silently skipped.
|
||||
.It Fl o
|
||||
Overwrite.
|
||||
When extracting a file from the zipfile, if a file with the same name
|
||||
already exists on disk, the existing file is replaced with the file
|
||||
from the zipfile.
|
||||
.It Fl p
|
||||
Extract to stdout.
|
||||
When extracting files from the zipfile, they are written to stdout.
|
||||
The normal output is suppressed as if
|
||||
.Fl q
|
||||
was specified.
|
||||
.It Fl P Ar password
|
||||
Extract encrypted files using a password.
|
||||
Putting a password on the command line using this option can be
|
||||
insecure.
|
||||
.It Fl q
|
||||
Quiet: print less information while extracting.
|
||||
.It Fl t
|
||||
Test: do not extract anything, but verify the checksum of every file
|
||||
in the archive.
|
||||
.It Fl u
|
||||
Update.
|
||||
When extracting a file from the zipfile, if a file with the same name
|
||||
already exists on disk, the existing file is replaced with the file
|
||||
from the zipfile if and only if the latter is newer than the former.
|
||||
Otherwise, the file is silently skipped.
|
||||
.It Fl v
|
||||
List verbosely, rather than extract, the contents of the zipfile.
|
||||
This differs from
|
||||
.Fl l
|
||||
by using the long listing.
|
||||
Note that most of the data is currently fake and does not reflect the
|
||||
content of the archive.
|
||||
.It Fl x Ar pattern
|
||||
Exclude files matching the pattern
|
||||
.Ar pattern .
|
||||
.It Fl y
|
||||
Print four digit years in listings instead of two.
|
||||
.It Fl Z Ar mode
|
||||
Emulate
|
||||
.Xr zipinfo 1L
|
||||
mode.
|
||||
Enabling
|
||||
.Xr zipinfo 1L
|
||||
mode changes the way in which additional arguments are parsed.
|
||||
Currently only
|
||||
.Xr zipinfo 1L
|
||||
mode 1 is supported, which lists the file names one per line.
|
||||
.It Ar [member ...]
|
||||
Optional list of members to extract from the zipfile.
|
||||
Can include patterns, e.g.,
|
||||
.Ar 'memberdir/*'
|
||||
will extract all files and dirs below memberdir.
|
||||
.El
|
||||
.Pp
|
||||
Note that only one of
|
||||
.Fl n ,
|
||||
.Fl o ,
|
||||
and
|
||||
.Fl u
|
||||
may be specified.
|
||||
If specified filename is
|
||||
.Qq - ,
|
||||
then data is read from
|
||||
.Va stdin .
|
||||
.Sh ENVIRONMENT
|
||||
If the
|
||||
.Ev UNZIP_DEBUG
|
||||
environment variable is defined, the
|
||||
.Fl q
|
||||
command-line option has no effect, and additional debugging
|
||||
information will be printed to
|
||||
.Va stderr .
|
||||
.Sh COMPATIBILITY
|
||||
The
|
||||
.Nm
|
||||
utility aims to be sufficiently compatible with other implementations
|
||||
to serve as a drop-in replacement in the context of the
|
||||
.Xr ports 7
|
||||
system.
|
||||
No attempt has been made to replicate functionality which is not
|
||||
required for that purpose.
|
||||
.Pp
|
||||
For compatibility reasons, command-line options will be recognized if
|
||||
they are listed not only before but also after the name of the
|
||||
zipfile.
|
||||
.Pp
|
||||
Normally, the
|
||||
.Fl a
|
||||
option should only affect files which are marked as text files in the
|
||||
zipfile's central directory.
|
||||
Since the
|
||||
.Xr archive 3
|
||||
library does not provide access to that information, it is not available
|
||||
to the
|
||||
.Nm
|
||||
utility.
|
||||
Instead, the
|
||||
.Nm
|
||||
utility will assume that a file is a text file if no non-ASCII
|
||||
characters are present within the first block of data decompressed for
|
||||
that file.
|
||||
If non-ASCII characters appear in subsequent blocks of data, a warning
|
||||
will be issued.
|
||||
.Pp
|
||||
The
|
||||
.Nm
|
||||
utility is only able to process ZIP archives handled by
|
||||
.Xr libarchive 3 .
|
||||
Depending on the installed version of
|
||||
.Xr libarchive 3 ,
|
||||
this may or may not include self-extracting or ZIPX archives.
|
||||
.Sh SEE ALSO
|
||||
.Xr libarchive 3
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
utility appeared in
|
||||
.Fx 8.0 .
|
||||
.Sh AUTHORS
|
||||
The
|
||||
.Nm
|
||||
utility and this manual page were written by
|
||||
.An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org .
|
||||
It uses the
|
||||
.Xr archive 3
|
||||
library developed by
|
||||
.An Tim Kientzle Aq Mt kientzle@FreeBSD.org .
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue