From: Tim Kientzle Date: Sat, 28 May 2016 19:39:10 +0000 (-0700) Subject: Issue 708: tar should fail if a named input file is missing X-Git-Tag: v3.2.1~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ba20a8b3b9de1a4baf018ceeb298dfd63bcaccfb;p=thirdparty%2Flibarchive.git Issue 708: tar should fail if a named input file is missing Tar was exiting with success if an input file named on the command line was not present. Includes tests for both bsdtar and bsdcpio to ensure this does not regress. --- diff --git a/Makefile.am b/Makefile.am index c5250184a..4a1967358 100644 --- a/Makefile.am +++ b/Makefile.am @@ -909,6 +909,7 @@ bsdtar_test_SOURCES= \ tar/test/test_format_newc.c \ tar/test/test_help.c \ tar/test/test_leading_slash.c \ + tar/test/test_missing_file.c \ tar/test/test_option_C_upper.c \ tar/test/test_option_H_upper.c \ tar/test/test_option_L_upper.c \ @@ -1064,6 +1065,7 @@ bsdcpio_test_SOURCES= \ cpio/test/test_extract_cpio_xz.c \ cpio/test/test_format_newc.c \ cpio/test/test_gcpio_compat.c \ + cpio/test/test_missing_file.c \ cpio/test/test_option_0.c \ cpio/test/test_option_B_upper.c \ cpio/test/test_option_C_upper.c \ diff --git a/cpio/test/CMakeLists.txt b/cpio/test/CMakeLists.txt index f2c275408..e3063ee9b 100644 --- a/cpio/test/CMakeLists.txt +++ b/cpio/test/CMakeLists.txt @@ -25,6 +25,7 @@ IF(ENABLE_CPIO AND ENABLE_TEST) test_extract_cpio_xz test_format_newc.c test_gcpio_compat.c + test_missing_file.c test_option_0.c test_option_B_upper.c test_option_C_upper.c diff --git a/cpio/test/test_missing_file.c b/cpio/test/test_missing_file.c new file mode 100644 index 000000000..a908f5301 --- /dev/null +++ b/cpio/test/test_missing_file.c @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 2016 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_missing_file) +{ + int r; + + assertMakeFile("file1", 0644, "file1"); + assertMakeFile("file2", 0644, "file2"); + + assertMakeFile("filelist1", 0644, "file1\nfile2\n"); + r = systemf("%s -o stdout1 2>stderr1", testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "stderr1"); + + assertMakeFile("filelist2", 0644, "file1\nfile2\nfile3\n"); + r = systemf("%s -o stdout2 2>stderr2", testprog); + assert(r != 0); + + assertMakeFile("filelist3", 0644, ""); + r = systemf("%s -o stdout3 2>stderr3", testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "stderr3"); + + assertMakeFile("filelist4", 0644, "file3\n"); + r = systemf("%s -o stdout4 2>stderr4", testprog); + assert(r != 0); +} diff --git a/tar/test/CMakeLists.txt b/tar/test/CMakeLists.txt index 9648e4892..f19a5f69c 100644 --- a/tar/test/CMakeLists.txt +++ b/tar/test/CMakeLists.txt @@ -25,6 +25,7 @@ IF(ENABLE_TAR AND ENABLE_TEST) test_format_newc.c test_help.c test_leading_slash.c + test_missing_file.c test_option_C_upper.c test_option_H_upper.c test_option_L_upper.c diff --git a/tar/test/test_missing_file.c b/tar/test/test_missing_file.c new file mode 100644 index 000000000..e2e5da5bd --- /dev/null +++ b/tar/test/test_missing_file.c @@ -0,0 +1,37 @@ +/*- + * Copyright (c) 2016 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_missing_file) +{ + assertMakeFile("file1", 0644, "file1"); + assertMakeFile("file2", 0644, "file2"); + assert(0 == systemf("%s -cf archive.tar file1 file2 2>stderr1", testprog)); + assertEmptyFile("stderr1"); + assert(0 != systemf("%s -cf archive.tar file1 file2 file3 2>stderr2", testprog)); + assert(0 != systemf("%s -cf archive.tar 2>stderr3", testprog)); + assert(0 != systemf("%s -cf archive.tar file3 2>stderr4", testprog)); +} diff --git a/tar/write.c b/tar/write.c index 53b63834c..2d076f488 100644 --- a/tar/write.c +++ b/tar/write.c @@ -884,7 +884,7 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path) else if (r != ARCHIVE_OK) { lafe_warnc(archive_errno(disk), "%s", archive_error_string(disk)); - if (r == ARCHIVE_FATAL) { + if (r == ARCHIVE_FATAL || r == ARCHIVE_FAILED) { bsdtar->return_value = 1; return; } else if (r < ARCHIVE_WARN)