]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add --lzma and -J options to cpio.
authorTim Kientzle <kientzle@gmail.com>
Fri, 17 Apr 2009 07:10:26 +0000 (03:10 -0400)
committerTim Kientzle <kientzle@gmail.com>
Fri, 17 Apr 2009 07:10:26 +0000 (03:10 -0400)
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

12 files changed:
Makefile.am
cpio/Makefile
cpio/cmdline.c
cpio/cpio.c
cpio/cpio.h
cpio/test/CMakeLists.txt
cpio/test/Makefile
cpio/test/test_option_J_upper.c [new file with mode: 0644]
cpio/test/test_option_Z_upper.c
cpio/test/test_option_lzma.c [new file with mode: 0644]
cpio/test/test_option_y.c
cpio/test/test_option_z.c

index f37bc54d9852ec84089b28a34941aac9a55bb8a2..592d8f1cdd1b512d52d33e05aca3124913cc0e3a 100644 (file)
@@ -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                               \
index 070f2c958cbc32940835e8e95cd6ea2be0855464..28c7b7c50255b4dfae035ee70e93af524eb3eca0 100644 (file)
@@ -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
index f0033e9839972851182f3532db8ce64c978f5133..0082b138c55625a309bf022726f1c7fce560dc29 100644 (file)
@@ -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 }
 };
 
index db61687bf902cf235a6c029eff47bd138d661a2b..2cc46abd045613044cc41784a10440e4b6849438 100644 (file)
@@ -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));
index bbadfe206bb9fa80d098777de51b670c6497e99a..7843c6f0f90ea686ba79e49cf7f009ed3bd815fe 100644 (file)
@@ -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
index 4f9522ed311a9050c5e6f59257957f9c079255de..e5e0afb1c3f299c79e96448c3061e0b651f1cba5 100644 (file)
@@ -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
index 452824e92c3223a096f1fbbfd6184c28926ab210..e055a91a19b81988be793eebe41ce80cc4658421 100644 (file)
@@ -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 (file)
index 0000000..033687e
--- /dev/null
@@ -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);
+}
index 8117fee473289fd0de2df5e39556a6332c69ff03..241f07bba1c770a706fc1e3aaa3ec501123d0756 100644 (file)
@@ -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 (file)
index 0000000..4d2d6ef
--- /dev/null
@@ -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);
+}
index 92280be2dfad3fc687eb0cf75d78ebe114f4226b..a8a5936dcc3bff72ab4d416f6e75cd1012671193 100644 (file)
@@ -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);
 }
index 20579120e785b5c64166b7aa62bfad2fbf049225..c4bc480e980e5799a487e6fbeffd5ab18208736d 100644 (file)
@@ -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);
 }