]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add --lrzip option to bsdtar and bsdcpio to use lrzip compression.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sun, 7 Oct 2012 03:56:02 +0000 (12:56 +0900)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sun, 7 Oct 2012 03:57:51 +0000 (12:57 +0900)
14 files changed:
Makefile.am
cpio/bsdcpio.1
cpio/cmdline.c
cpio/cpio.c
cpio/cpio.h
cpio/test/CMakeLists.txt
cpio/test/test_option_lrzip.c [new file with mode: 0644]
tar/bsdtar.1
tar/bsdtar.c
tar/bsdtar.h
tar/cmdline.c
tar/test/CMakeLists.txt
tar/test/test_option_lrzip.c [new file with mode: 0644]
tar/write.c

index 35badf1e383e17db36da6fe8debe6e5a12079a69..ba4e7f4afee054fc6c0d857a4b415f4124ee545b 100644 (file)
@@ -725,6 +725,7 @@ bsdtar_test_SOURCES=                                                \
        tar/test/test_option_gid_gname.c                        \
        tar/test/test_option_k.c                                \
        tar/test/test_option_keep_newer_files.c                 \
+       tar/test/test_option_lrzip.c                            \
        tar/test/test_option_lzma.c                             \
        tar/test/test_option_lzop.c                             \
        tar/test/test_option_n.c                                \
@@ -848,6 +849,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_lrzip.c                           \
        cpio/test/test_option_lzma.c                            \
        cpio/test/test_option_lzop.c                            \
        cpio/test/test_option_m.c                               \
index 05f79d26ca3102c4293b14a368393692fc39eb51..b3d0d40a21ad1f45c5f009b53603f0c4c1026cd4 100644 (file)
@@ -176,6 +176,11 @@ With this option, the target of the link will be archived or copied instead.
 (p mode only)
 Create links from the target directory to the original files,
 instead of copying.
+.It Fl Fl lrzip
+(o mode only)
+Compress the resulting archive with
+.Xr lrzip 1 .
+In input mode, this option is ignored.
 .It Fl Fl lzma
 (o mode only)
 Compress the file with lzma-compatible compression before writing it.
index 91f6e1c486bd19031d8125152a7d9e9f56d6ff63..bd54880b6ef888a331d9ed1cac2b2414991976a2 100644 (file)
@@ -70,6 +70,7 @@ static const struct option {
        { "insecure",                   0, OPTION_INSECURE },
        { "link",                       0, 'l' },
        { "list",                       0, 't' },
+       { "lrzip",                      0, OPTION_LRZIP },
        { "lzma",                       0, OPTION_LZMA },
        { "lzop",                       0, OPTION_LZOP },
        { "make-directories",           0, 'd' },
index db342318b535e6d2719e11b185f9a4ba3045a21a..40e7b29fbbeb11f148e7681bd565a415407612af 100644 (file)
@@ -265,6 +265,7 @@ main(int argc, char *argv[])
                case 'l': /* POSIX 1997 */
                        cpio->option_link = 1;
                        break;
+               case OPTION_LRZIP:
                case OPTION_LZMA: /* GNU tar, others */
                case OPTION_LZOP: /* GNU tar, others */
                        cpio->compress = opt;
@@ -521,6 +522,9 @@ mode_out(struct cpio *cpio)
        case 'J':
                r = archive_write_set_compression_xz(cpio->archive);
                break;
+       case OPTION_LRZIP:
+               r = archive_write_add_filter_lrzip(cpio->archive);
+               break;
        case OPTION_LZMA:
                r = archive_write_set_compression_lzma(cpio->archive);
                break;
index af7ef8a893afd965e6370d29950d301e409dfdd8..6d052bbd9546cfadf020b177b5ad6510b963d280 100644 (file)
@@ -97,6 +97,7 @@ const char *owner_parse(const char *, int *, int *);
 /* Fake short equivalents for long options that otherwise lack them. */
 enum {
        OPTION_INSECURE = 1,
+       OPTION_LRZIP,
        OPTION_LZMA,
        OPTION_LZOP,
        OPTION_NO_PRESERVE_OWNER,
index d67856e6c142a8e5975a38f2674bfd3c52e2b0a1..69db631a143e34bcc659442069a96ffb178d712c 100644 (file)
@@ -27,6 +27,7 @@ IF(ENABLE_CPIO AND ENABLE_TEST)
     test_option_f.c
     test_option_help.c
     test_option_l.c
+    test_option_lrzip.c
     test_option_lzma.c
     test_option_lzop.c
     test_option_m.c
diff --git a/cpio/test/test_option_lrzip.c b/cpio/test/test_option_lrzip.c
new file mode 100644 (file)
index 0000000..a84f751
--- /dev/null
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * 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_lrzip)
+{
+       char *p;
+       size_t s;
+
+       if (!canLrzip()) {
+               skipping("lrzip is not supported on this platform");
+               return;
+       }
+
+       /* Create a file. */
+       assertMakeFile("f", 0644, "a");
+
+       /* Archive it with lrzip compression. */
+       assertEqualInt(0,
+           systemf("echo f | %s -o --lrzip >archive.out 2>archive.err",
+           testprog));
+       p = slurpfile(&s, "archive.err");
+       p[s] = '\0';
+       /* Check that the archive file has an lzma signature. */
+       p = slurpfile(&s, "archive.out");
+       assert(s > 2);
+       assertEqualMem(p, "LRZI\x00", 5);
+}
index cd3e8fbce3140421e069f5af466337189939f75b..ff8665a4a4c602fb58542bf7884363637b1136c5 100644 (file)
@@ -286,6 +286,11 @@ With this option, the target of the link will be archived instead.
 .It Fl l , Fl Fl check-links
 (c and r modes only)
 Issue a warning message unless all links to each file are archived.
+.It Fl Fl lrzip
+(c mode only)
+Compress the resulting archive with
+.Xr lrzip 1 .
+In extract or list modes, this option is ignored.
 .It Fl Fl lzma
 (c mode only) Compress the resulting archive with the original LZMA algorithm.
 Use of this option is discouraged and new archives should be created with
@@ -300,10 +305,6 @@ automatically when reading archives.
 Compress the resulting archive with
 .Xr lzop 1 .
 In extract or list modes, this option is ignored.
-Note that, unlike other
-.Nm tar
-implementations, this implementation recognizes lzop compression
-automatically when reading archives.
 .It Fl m , Fl Fl modification-time
 (x mode only)
 Do not extract modification time.
index f8e7e5d87c9fd6d23789b5a1770ea57979eaa229..f4ae865af81df654255dcb049516485c474a6108 100644 (file)
@@ -372,6 +372,7 @@ main(int argc, char **argv)
                        /* GNU tar 1.13  used -l for --one-file-system */
                        bsdtar->option_warn_links = 1;
                        break;
+               case OPTION_LRZIP:
                case OPTION_LZIP: /* GNU tar beginning with 1.23 */
                case OPTION_LZMA: /* GNU tar beginning with 1.20 */
                case OPTION_LZOP: /* GNU tar beginning with 1.21 */
index 810ddc390de088baa7003cb86027234519311cf9..5067028260aaaabc4861874902b8f56bf5144713 100644 (file)
@@ -121,6 +121,7 @@ enum {
        OPTION_HELP,
        OPTION_INCLUDE,
        OPTION_KEEP_NEWER_FILES,
+       OPTION_LRZIP,
        OPTION_LZIP,
        OPTION_LZMA,
        OPTION_LZOP,
index 3ee00e098ef79f0853aaa3dfc6030c6d74572b4e..af599ea53a273b28cfe61ab9843fde576637d8d7 100644 (file)
@@ -96,6 +96,7 @@ static const struct bsdtar_option {
        { "keep-newer-files",     0, OPTION_KEEP_NEWER_FILES },
        { "keep-old-files",       0, 'k' },
        { "list",                 0, 't' },
+       { "lrzip",                0, OPTION_LRZIP },
        { "lzip",                 0, OPTION_LZIP },
        { "lzma",                 0, OPTION_LZMA },
        { "lzop",                 0, OPTION_LZOP },
index 1347ef139a805713f932c20a31e080f7b378442c..862e10007658f7e25609cb720057bb9a609d5f5e 100644 (file)
@@ -32,6 +32,7 @@ IF(ENABLE_TAR AND ENABLE_TEST)
     test_option_gid_gname.c
     test_option_k.c
     test_option_keep_newer_files.c
+    test_option_lrzip.c
     test_option_lzma.c
     test_option_lzop.c
     test_option_n.c
diff --git a/tar/test/test_option_lrzip.c b/tar/test/test_option_lrzip.c
new file mode 100644 (file)
index 0000000..d3486a3
--- /dev/null
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * 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_lrzip)
+{
+       char *p;
+       size_t s;
+
+       if (!canLrzip()) {
+               skipping("lrzip is not supported on this platform");
+               return;
+       }
+
+       /* Create a file. */
+       assertMakeFile("f", 0644, "a");
+
+       /* Archive it with lrzip compression. */
+       assertEqualInt(0,
+           systemf("%s -cf - --lrzip f >archive.out 2>archive.err",
+           testprog));
+       p = slurpfile(&s, "archive.err");
+       p[s] = '\0';
+       /* Check that the archive file has an lzma signature. */
+       p = slurpfile(&s, "archive.out");
+       assert(s > 2);
+       assertEqualMem(p, "LRZI\x00", 5);
+}
index 25aaa184e3f9e25f2cf1fefcd9121f6483736a23..2e9bc90aabc9dc0223393f152c8ea98032ff8429 100644 (file)
@@ -178,6 +178,9 @@ tar_mode_c(struct bsdtar *bsdtar)
                case 'J':
                        r = archive_write_set_compression_xz(a);
                        break;
+               case OPTION_LRZIP:
+                       r = archive_write_add_filter_lrzip(a);
+                       break;
                case OPTION_LZIP:
                        r = archive_write_set_compression_lzip(a);
                        break;