From 08e5985823058be70eb45bed9476a78725a3cccb Mon Sep 17 00:00:00 2001 From: Michihiro NAKAJIMA Date: Sun, 7 Oct 2012 12:56:02 +0900 Subject: [PATCH] Add --lrzip option to bsdtar and bsdcpio to use lrzip compression. --- Makefile.am | 2 ++ cpio/bsdcpio.1 | 5 ++++ cpio/cmdline.c | 1 + cpio/cpio.c | 4 +++ cpio/cpio.h | 1 + cpio/test/CMakeLists.txt | 1 + cpio/test/test_option_lrzip.c | 52 +++++++++++++++++++++++++++++++++++ tar/bsdtar.1 | 9 +++--- tar/bsdtar.c | 1 + tar/bsdtar.h | 1 + tar/cmdline.c | 1 + tar/test/CMakeLists.txt | 1 + tar/test/test_option_lrzip.c | 52 +++++++++++++++++++++++++++++++++++ tar/write.c | 3 ++ 14 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 cpio/test/test_option_lrzip.c create mode 100644 tar/test/test_option_lrzip.c diff --git a/Makefile.am b/Makefile.am index 35badf1e3..ba4e7f4af 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/cpio/bsdcpio.1 b/cpio/bsdcpio.1 index 05f79d26c..b3d0d40a2 100644 --- a/cpio/bsdcpio.1 +++ b/cpio/bsdcpio.1 @@ -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. diff --git a/cpio/cmdline.c b/cpio/cmdline.c index 91f6e1c48..bd54880b6 100644 --- a/cpio/cmdline.c +++ b/cpio/cmdline.c @@ -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' }, diff --git a/cpio/cpio.c b/cpio/cpio.c index db342318b..40e7b29fb 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -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; diff --git a/cpio/cpio.h b/cpio/cpio.h index af7ef8a89..6d052bbd9 100644 --- a/cpio/cpio.h +++ b/cpio/cpio.h @@ -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, diff --git a/cpio/test/CMakeLists.txt b/cpio/test/CMakeLists.txt index d67856e6c..69db631a1 100644 --- a/cpio/test/CMakeLists.txt +++ b/cpio/test/CMakeLists.txt @@ -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 index 000000000..a84f75157 --- /dev/null +++ b/cpio/test/test_option_lrzip.c @@ -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); +} diff --git a/tar/bsdtar.1 b/tar/bsdtar.1 index cd3e8fbce..ff8665a4a 100644 --- a/tar/bsdtar.1 +++ b/tar/bsdtar.1 @@ -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. diff --git a/tar/bsdtar.c b/tar/bsdtar.c index f8e7e5d87..f4ae865af 100644 --- a/tar/bsdtar.c +++ b/tar/bsdtar.c @@ -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 */ diff --git a/tar/bsdtar.h b/tar/bsdtar.h index 810ddc390..506702826 100644 --- a/tar/bsdtar.h +++ b/tar/bsdtar.h @@ -121,6 +121,7 @@ enum { OPTION_HELP, OPTION_INCLUDE, OPTION_KEEP_NEWER_FILES, + OPTION_LRZIP, OPTION_LZIP, OPTION_LZMA, OPTION_LZOP, diff --git a/tar/cmdline.c b/tar/cmdline.c index 3ee00e098..af599ea53 100644 --- a/tar/cmdline.c +++ b/tar/cmdline.c @@ -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 }, diff --git a/tar/test/CMakeLists.txt b/tar/test/CMakeLists.txt index 1347ef139..862e10007 100644 --- a/tar/test/CMakeLists.txt +++ b/tar/test/CMakeLists.txt @@ -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 index 000000000..d3486a3a2 --- /dev/null +++ b/tar/test/test_option_lrzip.c @@ -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); +} diff --git a/tar/write.c b/tar/write.c index 25aaa184e..2e9bc90aa 100644 --- a/tar/write.c +++ b/tar/write.c @@ -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; -- 2.47.2