test_option_L_upper.c revision 348607
172909Sjulian/*- 272909Sjulian * Copyright (c) 2003-2007 Tim Kientzle 372909Sjulian * All rights reserved. 472909Sjulian * 572909Sjulian * Redistribution and use in source and binary forms, with or without 672909Sjulian * modification, are permitted provided that the following conditions 772909Sjulian * are met: 872909Sjulian * 1. Redistributions of source code must retain the above copyright 972909Sjulian * notice, this list of conditions and the following disclaimer. 1072909Sjulian * 2. Redistributions in binary form must reproduce the above copyright 1172909Sjulian * notice, this list of conditions and the following disclaimer in the 1272909Sjulian * documentation and/or other materials provided with the distribution. 1372909Sjulian * 1472909Sjulian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 1572909Sjulian * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1672909Sjulian * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1772909Sjulian * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 1872909Sjulian * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1972909Sjulian * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2072909Sjulian * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2172909Sjulian * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2272909Sjulian * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2372909Sjulian * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2472909Sjulian */ 2572909Sjulian#include "test.h" 2672909Sjulian__FBSDID("$FreeBSD: stable/11/contrib/libarchive/cpio/test/test_option_L_upper.c 348607 2019-06-04 10:35:54Z mm $"); 2772909Sjulian 2880304Sbrooks/* This is a little pointless, as Windows doesn't support symlinks 2972909Sjulian * (except for the seriously crippled CreateSymbolicLink API) so these 3072909Sjulian * tests won't run on Windows. */ 3172909Sjulian#if defined(_WIN32) && !defined(__CYGWIN__) 3272909Sjulian#define CAT "type" 3372909Sjulian#define SEP "\\" 3472909Sjulian#else 3572909Sjulian#define CAT "cat" 3672909Sjulian#define SEP "/" 3772909Sjulian#endif 3872909Sjulian 3972909SjulianDEFINE_TEST(test_option_L_upper) 4072909Sjulian{ 4172909Sjulian FILE *filelist; 4272909Sjulian int r; 4372909Sjulian 4472909Sjulian if (!canSymlink()) { 4572909Sjulian skipping("Symlink tests"); 4672909Sjulian return; 4772909Sjulian } 4872909Sjulian 4980304Sbrooks filelist = fopen("filelist", "w"); 5072909Sjulian 5172909Sjulian /* Create a file and a symlink to the file. */ 5272909Sjulian assertMakeFile("file", 0644, "1234567890"); 5372909Sjulian fprintf(filelist, "file\n"); 5472909Sjulian 5572909Sjulian /* Symlink to above file. */ 56129823Sjulian assertMakeSymlink("symlink", "file", 0); 57129823Sjulian fprintf(filelist, "symlink\n"); 58129823Sjulian 59129823Sjulian fclose(filelist); 60129823Sjulian 61129823Sjulian r = systemf(CAT " filelist | %s -pd copy >copy.out 2>copy.err", testprog); 62129823Sjulian assertEqualInt(r, 0); 6372909Sjulian assertTextFileContents("1 block\n", "copy.err"); 6472909Sjulian 6572909Sjulian failure("Regular -p without -L should preserve symlinks."); 6672909Sjulian assertIsSymlink("copy/symlink", NULL, 0); 6772909Sjulian 6880304Sbrooks r = systemf(CAT " filelist | %s -pd -L copy-L >copy-L.out 2>copy-L.err", testprog); 6980304Sbrooks assertEqualInt(r, 0); 7080304Sbrooks assertEmptyFile("copy-L.out"); 7172909Sjulian assertTextFileContents("1 block\n", "copy-L.err"); 7272909Sjulian failure("-pdL should dereference symlinks and turn them into files."); 7372909Sjulian assertIsReg("copy-L/symlink", -1); 7472909Sjulian 7572909Sjulian r = systemf(CAT " filelist | %s -o >archive.out 2>archive.err", testprog); 7672909Sjulian failure("Error invoking %s -o ", testprog); 7772909Sjulian assertEqualInt(r, 0); 7872909Sjulian assertTextFileContents("1 block\n", "archive.err"); 7972909Sjulian 8072909Sjulian assertMakeDir("unpack", 0755); 8172909Sjulian assertChdir("unpack"); 8272909Sjulian r = systemf(CAT " .." SEP "archive.out | %s -i >unpack.out 2>unpack.err", testprog); 8372909Sjulian 8472909Sjulian failure("Error invoking %s -i", testprog); 8580304Sbrooks assertEqualInt(r, 0); 8672909Sjulian assertTextFileContents("1 block\n", "unpack.err"); 8772909Sjulian assertChdir(".."); 88220768Sglebius 8972909Sjulian assertIsSymlink("unpack/symlink", NULL, 0); 9072909Sjulian 9172909Sjulian r = systemf(CAT " filelist | %s -oL >archive-L.out 2>archive-L.err", testprog); 9272909Sjulian failure("Error invoking %s -oL", testprog); 9372909Sjulian assertEqualInt(r, 0); 9472909Sjulian assertTextFileContents("1 block\n", "archive-L.err"); 9572909Sjulian 9672909Sjulian assertMakeDir("unpack-L", 0755); 9772909Sjulian assertChdir("unpack-L"); 9872909Sjulian r = systemf(CAT " .." SEP "archive-L.out | %s -i >unpack-L.out 2>unpack-L.err", testprog); 9972909Sjulian 10072909Sjulian failure("Error invoking %s -i < archive-L.out", testprog); 10172909Sjulian assertEqualInt(r, 0); 10272909Sjulian assertTextFileContents("1 block\n", "unpack-L.err"); 10372909Sjulian assertChdir(".."); 10480304Sbrooks assertIsReg("unpack-L/symlink", -1); 10580304Sbrooks} 10672909Sjulian