Path: blob/main/contrib/libarchive/tar/test/test_option_U_upper.c
39507 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2010 Tim Kientzle4* All rights reserved.5*/6#include "test.h"78DEFINE_TEST(test_option_U_upper)9{10int r;1112assertMakeFile("file1", 0644, "file1");13assertMakeDir("d1", 0755);14assertMakeFile("d1/file1", 0644, "d1/file1");15assertEqualInt(0, systemf("%s -cf archive.tar file1 d1/file1", testprog));1617/*18* bsdtar's man page used to claim that -x without -U would19* not break hard links. This was and is nonsense. The first20* two tests here simply verify that existing hard links get21* broken regardless.22*/2324/* Test 1: -x without -U */25assertMakeDir("test1", 0755);26assertChdir("test1");27assertMakeFile("file1", 0644, "file1new");28assertMakeHardlink("file2", "file1");29assertEqualInt(0,30systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog));31assertFileContents("file1", 5, "file1");32assertFileContents("file1new", 8, "file2");33assertEmptyFile("test.out");34assertEmptyFile("test.err");35assertChdir("..");363738/* Test 2: -x with -U */39assertMakeDir("test2", 0755);40assertChdir("test2");41assertMakeFile("file1", 0644, "file1new");42assertMakeHardlink("file2", "file1");43assertEqualInt(0,44systemf("%s -xUf ../archive.tar >test.out 2>test.err", testprog));45assertFileContents("file1", 5, "file1");46assertFileContents("file1new", 8, "file2");47assertEmptyFile("test.out");48assertEmptyFile("test.err");49assertChdir("..");5051/*52* -U does make a difference in how bsdtar handles unwanted symlinks,53* though. It interacts with -P.54*/55if (!canSymlink())56return;5758/* Test 3: Intermediate dir symlink causes error by default */59assertMakeDir("test3", 0755);60assertChdir("test3");61assertMakeDir("realDir", 0755);62assertMakeSymlink("d1", "realDir", 1);63r = systemf("%s -xf ../archive.tar d1/file1 >test.out 2>test.err", testprog);64assert(r != 0);65assertIsSymlink("d1", "realDir", 1);66assertFileNotExists("d1/file1");67assertEmptyFile("test.out");68assertNonEmptyFile("test.err");69assertChdir("..");7071/* Test 4: Intermediate dir symlink gets removed with -U */72assertMakeDir("test4", 0755);73assertChdir("test4");74assertMakeDir("realDir", 0755);75assertMakeSymlink("d1", "realDir", 1);76assertEqualInt(0,77systemf("%s -xUf ../archive.tar >test.out 2>test.err", testprog));78assertIsDir("d1", -1);79assertFileContents("d1/file1", 8, "d1/file1");80assertEmptyFile("test.out");81assertEmptyFile("test.err");82assertChdir("..");8384/* Test 5: Intermediate dir symlink is followed with -P */85assertMakeDir("test5", 0755);86assertChdir("test5");87assertMakeDir("realDir", 0755);88assertMakeSymlink("d1", "realDir", 1);89assertEqualInt(0,90systemf("%s -xPf ../archive.tar d1/file1 >test.out 2>test.err", testprog));91assertIsSymlink("d1", "realDir", 1);92assertFileContents("d1/file1", 8, "d1/file1");93assertEmptyFile("test.out");94assertEmptyFile("test.err");95assertChdir("..");9697/* Test 6: Intermediate dir symlink is followed with -PU */98assertMakeDir("test6", 0755);99assertChdir("test6");100assertMakeDir("realDir", 0755);101assertMakeSymlink("d1", "realDir", 1);102assertEqualInt(0,103systemf("%s -xPUf ../archive.tar d1/file1 >test.out 2>test.err", testprog));104assertIsSymlink("d1", "realDir", 1);105assertFileContents("d1/file1", 8, "d1/file1");106assertEmptyFile("test.out");107assertEmptyFile("test.err");108assertChdir("..");109110/* Test 7: Final file symlink replaced by default */111assertMakeDir("test7", 0755);112assertChdir("test7");113assertMakeDir("d1", 0755);114assertMakeFile("d1/realfile1", 0644, "realfile1");115assertMakeSymlink("d1/file1", "d1/realfile1", 0);116assertEqualInt(0,117systemf("%s -xf ../archive.tar d1/file1 >test.out 2>test.err", testprog));118assertIsReg("d1/file1", umasked(0644));119assertFileContents("d1/file1", 8, "d1/file1");120assertFileContents("realfile1", 9, "d1/realfile1");121assertEmptyFile("test.out");122assertEmptyFile("test.err");123assertChdir("..");124125/* Test 8: Final file symlink replaced with -PU */126assertMakeDir("test8", 0755);127assertChdir("test8");128assertMakeDir("d1", 0755);129assertMakeFile("d1/realfile1", 0644, "realfile1");130assertMakeSymlink("d1/file1", "d1/realfile1", 0);131assertEqualInt(0,132systemf("%s -xPUf ../archive.tar d1/file1 >test.out 2>test.err", testprog));133assertIsReg("d1/file1", umasked(0644));134assertFileContents("d1/file1", 8, "d1/file1");135assertFileContents("realfile1", 9, "d1/realfile1");136assertEmptyFile("test.out");137assertEmptyFile("test.err");138assertChdir("..");139}140141142