From: Tim Kientzle Date: Fri, 17 Apr 2009 07:10:26 +0000 (-0400) Subject: Add --lzma and -J options to cpio. X-Git-Tag: v2.8.0~696 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d100741a07f46bafee91bce6c27dc0e6b548be57;p=thirdparty%2Flibarchive.git Add --lzma and -J options to cpio. 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 --- diff --git a/Makefile.am b/Makefile.am index f37bc54d9..592d8f1cd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -518,6 +518,7 @@ bsdcpio_test_SOURCES= \ 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 \ @@ -526,6 +527,7 @@ bsdcpio_test_SOURCES= \ 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 \ diff --git a/cpio/Makefile b/cpio/Makefile index 070f2c958..28c7b7c50 100644 --- a/cpio/Makefile +++ b/cpio/Makefile @@ -9,7 +9,7 @@ WARNS?= 6 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 diff --git a/cpio/cmdline.c b/cpio/cmdline.c index f0033e983..0082b138c 100644 --- a/cpio/cmdline.c +++ b/cpio/cmdline.c @@ -50,7 +50,7 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/cmdline.c,v 1.5 2008/12/06 07:30:40 kientzl /* * 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. @@ -68,6 +68,7 @@ static const struct option { { "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' }, @@ -79,6 +80,7 @@ static const struct option { { "unconditional", 0, 'u' }, { "verbose", 0, 'v' }, { "version", 0, OPTION_VERSION }, + { "xz", 0, 'J' }, { NULL, 0, 0 } }; diff --git a/cpio/cpio.c b/cpio/cpio.c index db61687bf..2cc46abd0 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -219,6 +219,12 @@ main(int argc, char *argv[]) "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; @@ -229,6 +235,9 @@ main(int argc, char *argv[]) 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; @@ -380,7 +389,7 @@ static const char *long_help_msg = "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"; @@ -446,6 +455,12 @@ mode_out(struct cpio *cpio) 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; @@ -460,7 +475,7 @@ mode_out(struct cpio *cpio) 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)); diff --git a/cpio/cpio.h b/cpio/cpio.h index bbadfe206..7843c6f0f 100644 --- a/cpio/cpio.h +++ b/cpio/cpio.h @@ -100,6 +100,7 @@ int owner_parse(const char *, int *, int *); /* Fake short equivalents for long options that otherwise lack them. */ enum { OPTION_INSECURE = 1, + OPTION_LZMA, OPTION_NO_PRESERVE_OWNER, OPTION_QUIET, OPTION_VERSION diff --git a/cpio/test/CMakeLists.txt b/cpio/test/CMakeLists.txt index 4f9522ed3..e5e0afb1c 100644 --- a/cpio/test/CMakeLists.txt +++ b/cpio/test/CMakeLists.txt @@ -17,6 +17,7 @@ IF(ENABLE_CPIO AND ENABLE_TEST) 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 @@ -25,6 +26,7 @@ IF(ENABLE_CPIO AND ENABLE_TEST) 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 diff --git a/cpio/test/Makefile b/cpio/test/Makefile index 452824e92..e055a91a1 100644 --- a/cpio/test/Makefile +++ b/cpio/test/Makefile @@ -12,14 +12,18 @@ TESTS= \ 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 \ diff --git a/cpio/test/test_option_J_upper.c b/cpio/test/test_option_J_upper.c new file mode 100644 index 000000000..033687e1a --- /dev/null +++ b/cpio/test/test_option_J_upper.c @@ -0,0 +1,60 @@ +/*- + * 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); +} diff --git a/cpio/test/test_option_Z_upper.c b/cpio/test/test_option_Z_upper.c index 8117fee47..241f07bba 100644 --- a/cpio/test/test_option_Z_upper.c +++ b/cpio/test/test_option_Z_upper.c @@ -38,22 +38,23 @@ DEFINE_TEST(test_option_Z_upper) 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); } diff --git a/cpio/test/test_option_lzma.c b/cpio/test/test_option_lzma.c new file mode 100644 index 000000000..4d2d6ef16 --- /dev/null +++ b/cpio/test/test_option_lzma.c @@ -0,0 +1,60 @@ +/*- + * 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); +} diff --git a/cpio/test/test_option_y.c b/cpio/test/test_option_y.c index 92280be2d..a8a5936dc 100644 --- a/cpio/test/test_option_y.c +++ b/cpio/test/test_option_y.c @@ -41,19 +41,21 @@ DEFINE_TEST(test_option_y) /* 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); } diff --git a/cpio/test/test_option_z.c b/cpio/test/test_option_z.c index 20579120e..c4bc480e9 100644 --- a/cpio/test/test_option_z.c +++ b/cpio/test/test_option_z.c @@ -41,19 +41,20 @@ DEFINE_TEST(test_option_z) /* 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); }