Add tests for these.
Edit the existing compression tests so they correctly
distinguish unsupported options (e.g., we're testing GNU cpio)
from unsupported compression.
SVN-Revision: 1025
cpio/test/test_gcpio_compat.c \
cpio/test/test_option_B_upper.c \
cpio/test/test_option_C_upper.c \
+ cpio/test/test_option_J_upper.c \
cpio/test/test_option_L_upper.c \
cpio/test/test_option_Z_upper.c \
cpio/test/test_option_a.c \
cpio/test/test_option_f.c \
cpio/test/test_option_help.c \
cpio/test/test_option_l.c \
+ cpio/test/test_option_lzma.c \
cpio/test/test_option_m.c \
cpio/test/test_option_t.c \
cpio/test/test_option_u.c \
DPADD= ${LIBARCHIVE} ${LIBZ} ${LIBBZ2}
CFLAGS+= -DBSDCPIO_VERSION_STRING=\"${BSDCPIO_VERSION_STRING}\"
CFLAGS+= -DPLATFORM_CONFIG_H=\"config_freebsd.h\"
-LDADD+= -larchive -lz -lbz2
+LDADD+= -larchive -lz -lbz2 -lmd -lcrypto
.if ${MK_GNU_CPIO} != "yes"
SYMLINKS=bsdcpio ${BINDIR}/cpio
/*
* Short options for cpio. Please keep this sorted.
*/
-static const char *short_options = "0AaBC:F:O:cdE:f:H:hijLlmnopR:rtuvW:yZz";
+static const char *short_options = "0AaBC:F:O:cdE:f:H:hiJjLlmnopR:rtuvW:yZz";
/*
* Long options for cpio. Please keep this sorted.
{ "insecure", 0, OPTION_INSECURE },
{ "link", 0, 'l' },
{ "list", 0, 't' },
+ { "lzma", 0, OPTION_LZMA },
{ "make-directories", 0, 'd' },
{ "no-preserve-owner", 0, OPTION_NO_PRESERVE_OWNER },
{ "null", 0, '0' },
{ "unconditional", 0, 'u' },
{ "verbose", 0, 'v' },
{ "version", 0, OPTION_VERSION },
+ { "xz", 0, 'J' },
{ NULL, 0, 0 }
};
"Cannot use both -i and -%c", cpio->mode);
cpio->mode = opt;
break;
+ case 'J': /* GNU tar, others */
+ cpio->compress = opt;
+ break;
+ case 'j': /* GNU tar, others */
+ cpio->compress = opt;
+ break;
case OPTION_INSECURE:
cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_SYMLINKS;
cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NODOTDOT;
case 'l': /* POSIX 1997 */
cpio->option_link = 1;
break;
+ case OPTION_LZMA: /* GNU tar, others */
+ cpio->compress = opt;
+ break;
case 'm': /* POSIX 1997 */
cpio->extract_flags |= ARCHIVE_EXTRACT_TIME;
break;
"Common Options:\n"
" -v Verbose\n"
"Create: %p -o [options] < [list of files] > [archive]\n"
- " -y,-z Compress archive with bzip2/gzip\n"
+ " -J,-y,-z,--lzma Compress archive with xz/bzip2/gzip/lzma\n"
" --format {odc|newc|ustar} Select archive format\n"
"List: %p -it < [archive]\n"
"Extract: %p -i [options] < [archive]\n";
if (cpio->archive == NULL)
cpio_errc(1, 0, "Failed to allocate archive object");
switch (cpio->compress) {
+ case 'J':
+ r = archive_write_set_compression_xz(cpio->archive);
+ break;
+ case OPTION_LZMA:
+ r = archive_write_set_compression_lzma(cpio->archive);
+ break;
case 'j': case 'y':
r = archive_write_set_compression_bzip2(cpio->archive);
break;
break;
}
if (r < ARCHIVE_WARN)
- cpio_errc(1, 0, "Requested compression not supported");
+ cpio_errc(1, 0, "Requested compression not available");
r = archive_write_set_format_by_name(cpio->archive, cpio->format);
if (r != ARCHIVE_OK)
cpio_errc(1, 0, archive_error_string(cpio->archive));
/* Fake short equivalents for long options that otherwise lack them. */
enum {
OPTION_INSECURE = 1,
+ OPTION_LZMA,
OPTION_NO_PRESERVE_OWNER,
OPTION_QUIET,
OPTION_VERSION
test_gcpio_compat.c
test_option_B_upper.c
test_option_C_upper.c
+ test_option_J_upper.c
test_option_L_upper.c
test_option_Z_upper.c
test_option_a.c
test_option_f.c
test_option_help.c
test_option_l.c
+ test_option_lzma.c
test_option_m.c
test_option_t.c
test_option_u.c
test_basic.c \
test_format_newc.c \
test_gcpio_compat.c \
+ test_option_B_upper.c \
+ test_option_C_upper.c \
+ test_option_J_upper.c \
+ test_option_L_upper.c \
+ test_option_Z_upper.c \
test_option_a.c \
- test_option_B.c \
test_option_c.c \
test_option_d.c \
test_option_f.c \
test_option_help.c \
- test_option_L.c \
- test_option_ell.c \
+ test_option_l.c \
+ test_option_lzma.c \
test_option_m.c \
test_option_t.c \
test_option_u.c \
--- /dev/null
+/*-
+ * Copyright (c) 2003-2009 Tim Kientzle
+ * 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(S) ``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(S) 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.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_J_upper)
+{
+ char *p;
+ int fd;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ fd = open("f", O_CREAT | O_WRONLY, 0644);
+ assert(fd >= 0);
+ assertEqualInt(1, write(fd, "a", 1));
+ close(fd);
+
+ /* Archive it with xz compression. */
+ r = systemf("echo f | %s -o -J >archive.out 2>archive.err",
+ testprog);
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (strstr(p, "compression not available") != NULL) {
+ skipping("This version of bsdcpio was compiled "
+ "without xz support");
+ return;
+ }
+ failure("-J option is broken");
+ assertEqualInt(r, 0);
+ return;
+ }
+ /* Check that the archive file has an lzma signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "xxxxx", 5);
+}
assertEqualInt(1, write(fd, "a", 1));
close(fd);
- /* Archive it with gzip compression. */
+ /* Archive it with compress compression. */
r = systemf("echo f | %s -oZ >archive.out 2>archive.err",
testprog);
- failure("-Z option seems to be broken");
- assertEqualInt(r, 0);
- if (r == 0) {
- p = slurpfile(&s, "archive.err");
- p[s] = '\0';
- if (strstr(p, "not supported") != NULL) {
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (strstr(p, "compression not available") != NULL) {
skipping("This version of bsdcpio was compiled "
"without compress support");
- } else {
- /* Check that the archive file has a compress signature. */
- p = slurpfile(&s, "archive.out");
- assert(s > 2);
- assertEqualMem(p, "\x1f\x9d", 2);
+ return;
}
+ failure("-Z option is broken");
+ assertEqualInt(r, 0);
+ return;
}
+ /* Check that the archive file has a compress signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "\x1f\x9d", 2);
}
--- /dev/null
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * 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(S) ``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(S) 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.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_lzma)
+{
+ char *p;
+ int fd;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ fd = open("f", O_CREAT | O_WRONLY, 0644);
+ assert(fd >= 0);
+ assertEqualInt(1, write(fd, "a", 1));
+ close(fd);
+
+ /* Archive it with lzma compression. */
+ r = systemf("echo f | %s -o --lzma >archive.out 2>archive.err",
+ testprog);
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (strstr(p, "compression not available") != NULL) {
+ skipping("This version of bsdcpio was compiled "
+ "without lzma support");
+ return;
+ }
+ failure("--lzma option is broken");
+ assertEqualInt(r, 0);
+ return;
+ }
+ /* Check that the archive file has an lzma signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "\x5b", 1);
+}
/* Archive it with bzip2 compression. */
r = systemf("echo f | %s -oy >archive.out 2>archive.err",
testprog);
- failure("-y (bzip) option seems to be broken");
- if (assertEqualInt(r, 0)) {
- p = slurpfile(&s, "archive.err");
- p[s] = '\0';
- if (strstr(p, "bzip2 compression not supported") != NULL) {
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (strstr(p, "compression not available") != NULL) {
skipping("This version of bsdcpio was compiled "
"without bzip2 support");
- } else {
- assertTextFileContents("1 block\n", "archive.err");
- /* Check that the archive file has a bzip2 signature. */
- p = slurpfile(&s, "archive.out");
- assert(s > 2);
- assertEqualMem(p, "BZh9", 4);
+ return;
}
+ failure("-y option is broken");
+ assertEqualInt(r, 0);
+ return;
}
+ assertTextFileContents("1 block\n", "archive.err");
+ /* Check that the archive file has a bzip2 signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "BZh9", 4);
}
/* Archive it with gzip compression. */
r = systemf("echo f | %s -oz >archive.out 2>archive.err",
testprog);
- failure("-z option seems to be broken");
- assertEqualInt(r, 0);
- if (r == 0) {
- p = slurpfile(&s, "archive.err");
- p[s] = '\0';
- if (strstr(p, "gzip compression not supported") != NULL) {
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (strstr(p, "compression not available") != NULL) {
skipping("This version of bsdcpio was compiled "
"without gzip support");
- } else {
- /* Check that the archive file has a gzip signature. */
- p = slurpfile(&s, "archive.out");
- assert(s > 2);
- assertEqualMem(p, "\x1f\x8b\x08\x00", 4);
+ return;
}
+ failure("-z option is broken");
+ assertEqualInt(r, 0);
+ return;
}
+ /* Check that the archive file has a gzip signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 4);
+ assertEqualMem(p, "\x1f\x8b\x08\x00", 4);
}