Path: blob/main/contrib/libarchive/tar/test/test_option_fflags.c
39536 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2017 Martin Matuska4* All rights reserved.5*/6#include "test.h"78#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__BORLANDC__)9#define chmod _chmod10#endif1112static void13clear_fflags(const char *pathname)14{15#if defined(HAVE_STRUCT_STAT_ST_FLAGS)16chflags(pathname, 0);17#elif (defined(FS_IOC_GETFLAGS) && defined(HAVE_WORKING_FS_IOC_GETFLAGS)) || \18(defined(EXT2_IOC_GETFLAGS) && defined(HAVE_WORKING_EXT2_IOC_GETFLAGS))19int fd;2021fd = open(pathname, O_RDONLY | O_NONBLOCK);22if (fd < 0)23return;24ioctl(fd,25#ifdef FS_IOC_GETFLAGS26FS_IOC_GETFLAGS,27#else28EXT2_IOC_GETFLAGS,29#endif300);31#else32(void)pathname; /* UNUSED */33#endif34return;35}3637DEFINE_TEST(test_option_fflags)38{39int r;4041if (!canNodump()) {42skipping("Can't test nodump flag on this filesystem");43return;44}4546/* Create a file. */47assertMakeFile("f", 0644, "a");4849/* Set nodump flag on the file */50assertSetNodump("f");5152/* FreeBSD ZFS workaround: ZFS sets uarch on all touched files and dirs */53chmod("f", 0644);5455/* Archive it with fflags */56r = systemf("%s -c --fflags -f fflags.tar f >fflags.out 2>fflags.err", testprog);57assertEqualInt(r, 0);5859/* Archive it without fflags */60r = systemf("%s -c --no-fflags -f nofflags.tar f >nofflags.out 2>nofflags.err", testprog);61assertEqualInt(r, 0);6263/* Extract fflags with fflags */64assertMakeDir("fflags_fflags", 0755);65clear_fflags("fflags_fflags");66r = systemf("%s -x -C fflags_fflags --no-same-permissions --fflags -f fflags.tar >fflags_fflags.out 2>fflags_fflags.err", testprog);67assertEqualInt(r, 0);68assertEqualFflags("f", "fflags_fflags/f");6970/* Extract fflags without fflags */71assertMakeDir("fflags_nofflags", 0755);72clear_fflags("fflags_nofflags");73r = systemf("%s -x -C fflags_nofflags -p --no-fflags -f fflags.tar >fflags_nofflags.out 2>fflags_nofflags.err", testprog);74assertEqualInt(r, 0);75assertUnequalFflags("f", "fflags_nofflags/f");7677/* Extract nofflags with fflags */78assertMakeDir("nofflags_fflags", 0755);79clear_fflags("nofflags_fflags");80r = systemf("%s -x -C nofflags_fflags --no-same-permissions --fflags -f nofflags.tar >nofflags_fflags.out 2>nofflags_fflags.err", testprog);81assertEqualInt(r, 0);82assertUnequalFflags("f", "nofflags_fflags/f");8384/* Extract nofflags with nofflags */85assertMakeDir("nofflags_nofflags", 0755);86clear_fflags("nofflags_nofflags");87r = systemf("%s -x -C nofflags_nofflags -p --no-fflags -f nofflags.tar >nofflags_nofflags.out 2>nofflags_nofflags.err", testprog);88assertEqualInt(r, 0);89assertUnequalFflags("f", "nofflags_nofflags/f");90}919293