Qt/QML edition

This commit is contained in:
Floris Bos 2020-03-04 16:55:40 +01:00
commit d7b361ba44
2168 changed files with 721948 additions and 0 deletions

View file

@ -0,0 +1,127 @@
############################################
#
# How to build bsdtar_test
#
############################################
IF(ENABLE_TAR AND ENABLE_TEST)
SET(bsdtar_test_SOURCES
../../test_utils/test_utils.c
../../test_utils/test_main.c
test.h
test_0.c
test_basic.c
test_copy.c
test_empty_mtree.c
test_extract_tar_Z.c
test_extract_tar_bz2.c
test_extract_tar_grz.c
test_extract_tar_gz.c
test_extract_tar_lrz.c
test_extract_tar_lz.c
test_extract_tar_lz4.c
test_extract_tar_lzma.c
test_extract_tar_lzo.c
test_extract_tar_xz.c
test_extract_tar_zstd.c
test_format_newc.c
test_help.c
test_leading_slash.c
test_missing_file.c
test_option_C_upper.c
test_option_C_mtree.c
test_option_H_upper.c
test_option_L_upper.c
test_option_O_upper.c
test_option_T_upper.c
test_option_U_upper.c
test_option_X_upper.c
test_option_a.c
test_option_acls.c
test_option_b.c
test_option_b64encode.c
test_option_exclude.c
test_option_exclude_vcs.c
test_option_fflags.c
test_option_gid_gname.c
test_option_grzip.c
test_option_j.c
test_option_k.c
test_option_keep_newer_files.c
test_option_lrzip.c
test_option_lz4.c
test_option_lzma.c
test_option_lzop.c
test_option_n.c
test_option_newer_than.c
test_option_nodump.c
test_option_older_than.c
test_option_passphrase.c
test_option_q.c
test_option_r.c
test_option_s.c
test_option_safe_writes.c
test_option_uid_uname.c
test_option_uuencode.c
test_option_xattrs.c
test_option_xz.c
test_option_z.c
test_option_zstd.c
test_patterns.c
test_print_longpath.c
test_stdio.c
test_strip_components.c
test_symlink_dir.c
test_version.c
test_windows.c
)
#
# Register target
#
ADD_EXECUTABLE(bsdtar_test ${bsdtar_test_SOURCES})
IF(ENABLE_ACL)
SET(TEST_ACL_LIBS "")
IF(HAVE_LIBACL)
LIST(APPEND TEST_ACL_LIBS ${ACL_LIBRARY})
ENDIF(HAVE_LIBACL)
IF(HAVE_LIBRICHACL)
LIST(APPEND TEST_ACL_LIBS ${RICHACL_LIBRARY})
ENDIF(HAVE_LIBRICHACL)
TARGET_LINK_LIBRARIES(bsdtar_test ${TEST_ACL_LIBS})
ENDIF(ENABLE_ACL)
SET_PROPERTY(TARGET bsdtar_test PROPERTY COMPILE_DEFINITIONS LIST_H)
#
# Generate list.h by grepping DEFINE_TEST() lines out of the C sources.
#
GENERATE_LIST_H(${CMAKE_CURRENT_BINARY_DIR}/list.h
${CMAKE_CURRENT_LIST_FILE} ${bsdtar_test_SOURCES})
SET_PROPERTY(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES
${CMAKE_CURRENT_BINARY_DIR})
# list.h has a line DEFINE_TEST(testname) for every
# test. We can use that to define the tests for cmake by
# defining a DEFINE_TEST macro and reading list.h in.
MACRO (DEFINE_TEST _testname)
ADD_TEST(
NAME bsdtar_${_testname}
COMMAND bsdtar_test -vv
-p $<TARGET_FILE:bsdtar>
-r ${CMAKE_CURRENT_SOURCE_DIR}
${_testname})
ENDMACRO (DEFINE_TEST _testname)
INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/list.h)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/test_utils)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/tar/test)
# Experimental new test handling
ADD_CUSTOM_TARGET(run_bsdtar_test
COMMAND bsdtar_test -p $<TARGET_FILE:bsdtar>
-r ${CMAKE_CURRENT_SOURCE_DIR}
-vv)
ADD_DEPENDENCIES(run_bsdtar_test bsdtar)
ADD_DEPENDENCIES(run_all_tests run_bsdtar_test)
ENDIF(ENABLE_TAR AND ENABLE_TEST)

View file

@ -0,0 +1,65 @@
DEFINE_TEST(test_0)
DEFINE_TEST(test_basic)
DEFINE_TEST(test_copy)
DEFINE_TEST(test_empty_mtree)
DEFINE_TEST(test_extract_tar_Z)
DEFINE_TEST(test_extract_tar_bz2)
DEFINE_TEST(test_extract_tar_grz)
DEFINE_TEST(test_extract_tar_gz)
DEFINE_TEST(test_extract_tar_lrz)
DEFINE_TEST(test_extract_tar_lz)
DEFINE_TEST(test_extract_tar_lz4)
DEFINE_TEST(test_extract_tar_lzma)
DEFINE_TEST(test_extract_tar_lzo)
DEFINE_TEST(test_extract_tar_xz)
DEFINE_TEST(test_extract_tar_zstd)
DEFINE_TEST(test_format_newc)
DEFINE_TEST(test_help)
DEFINE_TEST(test_leading_slash)
DEFINE_TEST(test_missing_file)
DEFINE_TEST(test_option_C_mtree)
DEFINE_TEST(test_option_C_upper)
DEFINE_TEST(test_option_H_upper)
DEFINE_TEST(test_option_L_upper)
DEFINE_TEST(test_option_O_upper)
DEFINE_TEST(test_option_T_upper)
DEFINE_TEST(test_option_U_upper)
DEFINE_TEST(test_option_X_upper)
DEFINE_TEST(test_option_a)
DEFINE_TEST(test_option_acls)
DEFINE_TEST(test_option_b)
DEFINE_TEST(test_option_b64encode)
DEFINE_TEST(test_option_exclude)
DEFINE_TEST(test_option_exclude_vcs)
DEFINE_TEST(test_option_fflags)
DEFINE_TEST(test_option_gid_gname)
DEFINE_TEST(test_option_grzip)
DEFINE_TEST(test_option_j)
DEFINE_TEST(test_option_k)
DEFINE_TEST(test_option_keep_newer_files)
DEFINE_TEST(test_option_lrzip)
DEFINE_TEST(test_option_lz4)
DEFINE_TEST(test_option_lzma)
DEFINE_TEST(test_option_lzop)
DEFINE_TEST(test_option_n)
DEFINE_TEST(test_option_newer_than)
DEFINE_TEST(test_option_nodump)
DEFINE_TEST(test_option_older_than)
DEFINE_TEST(test_option_passphrase)
DEFINE_TEST(test_option_q)
DEFINE_TEST(test_option_r)
DEFINE_TEST(test_option_s)
DEFINE_TEST(test_option_safe_writes)
DEFINE_TEST(test_option_uid_uname)
DEFINE_TEST(test_option_uuencode)
DEFINE_TEST(test_option_xattrs)
DEFINE_TEST(test_option_xz)
DEFINE_TEST(test_option_z)
DEFINE_TEST(test_option_zstd)
DEFINE_TEST(test_patterns)
DEFINE_TEST(test_print_longpath)
DEFINE_TEST(test_stdio)
DEFINE_TEST(test_strip_components)
DEFINE_TEST(test_symlink_dir)
DEFINE_TEST(test_version)
DEFINE_TEST(test_windows)

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2003-2017 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.
*
* $FreeBSD$
*/
/* Every test program should #include "test.h" as the first thing. */
#define KNOWNREF "test_patterns_2.tar.uu"
#define ENVBASE "BSDTAR" /* Prefix for environment variables. */
#define PROGRAM "bsdtar" /* Name of program being tested. */
#define PROGRAM_ALIAS "tar" /* Generic alias for program */
#undef LIBRARY /* Not testing a library. */
#undef EXTRA_DUMP /* How to dump extra data */
#undef EXTRA_ERRNO /* How to dump errno */
/* How to generate extra version info. */
#define EXTRA_VERSION (systemf("%s --version", testprog) ? "" : "")
#include "test_common.h"

View file

@ -0,0 +1,75 @@
/*-
* Copyright (c) 2003-2007 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: src/usr.bin/tar/test/test_0.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $");
/*
* This first test does basic sanity checks on the environment. For
* most of these, we just exit on failure.
*/
#if !defined(_WIN32) || defined(__CYGWIN__)
#define DEV_NULL "/dev/null"
#else
#define DEV_NULL "NUL"
#endif
DEFINE_TEST(test_0)
{
struct stat st;
failure("File %s does not exist?!", testprog);
if (!assertEqualInt(0, stat(testprogfile, &st))) {
fprintf(stderr,
"\nFile %s does not exist; aborting test.\n\n",
testprog);
exit(1);
}
failure("%s is not executable?!", testprog);
if (!assert((st.st_mode & 0111) != 0)) {
fprintf(stderr,
"\nFile %s not executable; aborting test.\n\n",
testprog);
exit(1);
}
/*
* Try to successfully run the program; this requires that
* we know some option that will succeed.
*/
if (0 == systemf("%s --version >" DEV_NULL, testprog)) {
/* This worked. */
} else if (0 == systemf("%s -W version >" DEV_NULL, testprog)) {
/* This worked. */
} else {
failure("Unable to successfully run any of the following:\n"
" * %s --version\n"
" * %s -W version\n",
testprog, testprog);
assert(0);
}
/* TODO: Ensure that our reference files are available. */
}

View file

@ -0,0 +1,135 @@
/*-
* Copyright (c) 2003-2007 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: src/usr.bin/tar/test/test_basic.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $");
static const char *
make_files(void)
{
FILE *f;
/* File with 10 bytes content. */
f = fopen("file", "wb");
assert(f != NULL);
assertEqualInt(10, fwrite("123456789", 1, 10, f));
fclose(f);
/* hardlink to above file. */
assertMakeHardlink("linkfile", "file");
assertIsHardlink("file", "linkfile");
/* Symlink to above file. */
if (canSymlink())
assertMakeSymlink("symlink", "file", 0);
/* Directory. */
assertMakeDir("dir", 0775);
return canSymlink()
? "file linkfile symlink dir"
: "file linkfile dir";
}
static void
verify_files(const char *target)
{
assertChdir(target);
/* Regular file with 2 links. */
failure("%s", target);
assertIsReg("file", -1);
failure("%s", target);
assertFileSize("file", 10);
failure("%s", target);
assertFileContents("123456789", 10, "file");
failure("%s", target);
assertFileNLinks("file", 2);
/* Another name for the same file. */
failure("%s", target);
assertIsReg("linkfile", -1);
failure("%s", target);
assertFileSize("linkfile", 10);
assertFileContents("123456789", 10, "linkfile");
assertFileNLinks("linkfile", 2);
assertIsHardlink("file", "linkfile");
/* Symlink */
if (canSymlink())
assertIsSymlink("symlink", "file", 0);
/* dir */
failure("%s", target);
assertIsDir("dir", 0775);
assertChdir("..");
}
static void
run_tar(const char *target, const char *pack_options,
const char *unpack_options, const char *flist)
{
int r;
assertMakeDir(target, 0775);
/* Use the tar program to create an archive. */
r = systemf("%s cf - %s %s >%s/archive 2>%s/pack.err", testprog, pack_options, flist, target, target);
failure("Error invoking %s cf -%s", testprog, pack_options);
assertEqualInt(r, 0);
assertChdir(target);
/* Verify that nothing went to stderr. */
assertEmptyFile("pack.err");
/*
* Use tar to unpack the archive into another directory.
*/
r = systemf("%s xf archive %s >unpack.out 2>unpack.err",
testprog, unpack_options);
failure("Error invoking %s xf archive %s", testprog, unpack_options);
assertEqualInt(r, 0);
/* Verify that nothing went to stderr. */
assertEmptyFile("unpack.err");
assertChdir("..");
}
DEFINE_TEST(test_basic)
{
const char *flist;
assertUmask(0);
flist = make_files();
/* Archive/dearchive with a variety of options. */
run_tar("copy", "", "", flist);
verify_files("copy");
run_tar("copy_ustar", "--format=ustar", "", flist);
verify_files("copy_ustar");
/* tar doesn't handle cpio symlinks correctly */
/* run_tar("copy_odc", "--format=odc", ""); */
}

View file

@ -0,0 +1,375 @@
/*-
* Copyright (c) 2003-2007 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: src/usr.bin/tar/test/test_copy.c,v 1.3 2008/08/15 06:12:02 kientzle Exp $");
#if defined(__CYGWIN__)
# include <limits.h>
# include <sys/cygwin.h>
#endif
#if defined(_WIN32) && !defined(__CYGWIN__)
# include <direct.h>
#endif
/*
* Try to figure out how deep we can go in our tests. Assumes that
* the first call to this function has the longest starting cwd (which
* is currently "<testdir>/original"). This is mostly to work around
* limits in our Win32 support.
*
* Background: On Posix systems, PATH_MAX is merely a limit on the
* length of the string passed into a system call. By repeatedly
* calling chdir(), you can work with arbitrarily long paths on such
* systems. In contrast, Win32 APIs apply PATH_MAX limits to the full
* absolute path, so the permissible length of a system call argument
* varies with the cwd. Some APIs actually enforce limits
* significantly less than PATH_MAX to ensure that you can create
* files within the current working directory. The Win32 limits also
* apply to Cygwin before 1.7.
*
* Someday, I want to convert the Win32 support to use newer
* wide-character paths with '\\?\' prefix, which has a 32k PATH_MAX
* instead of the rather anemic 260 character limit of the older
* system calls. Then we can drop this mess (unless we want to
* continue to special-case Cygwin 1.5 and earlier).
*/
static int
compute_loop_max(void)
{
#if defined(_WIN32) && !defined(__CYGWIN__)
static int LOOP_MAX = 0;
char buf[MAX_PATH];
size_t cwdlen;
if (LOOP_MAX == 0) {
assert(_getcwd(buf, MAX_PATH) != NULL);
cwdlen = strlen(buf);
/* 12 characters = length of 8.3 filename */
/* 4 characters = length of "/../" used in symlink tests */
/* 1 character = length of extra "/" separator */
LOOP_MAX = MAX_PATH - (int)cwdlen - 12 - 4 - 1;
}
return LOOP_MAX;
#elif defined(__CYGWIN__) && !defined(HAVE_CYGWIN_CONV_PATH)
static int LOOP_MAX = 0;
if (LOOP_MAX == 0) {
char wbuf[PATH_MAX];
char pbuf[PATH_MAX];
size_t wcwdlen;
size_t pcwdlen;
size_t cwdlen;
assert(getcwd(pbuf, PATH_MAX) != NULL);
pcwdlen = strlen(pbuf);
cygwin_conv_to_full_win32_path(pbuf, wbuf);
wcwdlen = strlen(wbuf);
cwdlen = ((wcwdlen > pcwdlen) ? wcwdlen : pcwdlen);
/* Cygwin helper needs an extra few characters. */
LOOP_MAX = PATH_MAX - (int)cwdlen - 12 - 4 - 4;
}
return LOOP_MAX;
#else
/* cygwin-1.7 ends up here, along with "normal" unix */
return 200; /* restore pre-r278 depth */
#endif
}
/* filenames[i] is a distinctive filename of length i. */
/* To simplify interpreting failures, each filename ends with a
* decimal integer which is the length of the filename. E.g., A
* filename ending in "_92" is 92 characters long. To detect errors
* which drop or misplace characters, the filenames use a repeating
* "abcdefghijklmnopqrstuvwxyz..." pattern. */
static char *filenames[201];
static void
compute_filenames(void)
{
char buff[250];
size_t i,j;
filenames[0] = strdup("");
filenames[1] = strdup("1");
filenames[2] = strdup("a2");
for (i = 3; i < sizeof(filenames)/sizeof(filenames[0]); ++i) {
/* Fill with "abcdefghij..." */
for (j = 0; j < i; ++j)
buff[j] = 'a' + (j % 26);
buff[j--] = '\0';
/* Work from the end to fill in the number portion. */
buff[j--] = '0' + (i % 10);
if (i > 9) {
buff[j--] = '0' + ((i / 10) % 10);
if (i > 99)
buff[j--] = '0' + (char)(i / 100);
}
buff[j] = '_';
/* Guard against obvious screwups in the above code. */
assertEqualInt(strlen(buff), i);
filenames[i] = strdup(buff);
}
}
static void
create_tree(void)
{
char buff[260];
char buff2[260];
int i;
int LOOP_MAX;
compute_filenames();
/* Log that we'll be omitting some checks. */
if (!canSymlink()) {
skipping("Symlink checks");
}
assertMakeDir("original", 0775);
assertEqualInt(0, chdir("original"));
LOOP_MAX = compute_loop_max();
assertMakeDir("f", 0775);
assertMakeDir("l", 0775);
assertMakeDir("m", 0775);
assertMakeDir("s", 0775);
assertMakeDir("d", 0775);
for (i = 1; i < LOOP_MAX; i++) {
failure("Internal sanity check failed: i = %d", i);
assert(filenames[i] != NULL);
sprintf(buff, "f/%s", filenames[i]);
assertMakeFile(buff, 0777, buff);
/* Create a link named "l/abcdef..." to the above. */
sprintf(buff2, "l/%s", filenames[i]);
assertMakeHardlink(buff2, buff);
/* Create a link named "m/abcdef..." to the above. */
sprintf(buff2, "m/%s", filenames[i]);
assertMakeHardlink(buff2, buff);
if (canSymlink()) {
/* Create a symlink named "s/abcdef..." to the above. */
sprintf(buff, "s/%s", filenames[i]);
sprintf(buff2, "../f/%s", filenames[i]);
failure("buff=\"%s\" buff2=\"%s\"", buff, buff2);
assertMakeSymlink(buff, buff2, 0);
}
/* Create a dir named "d/abcdef...". */
buff[0] = 'd';
failure("buff=\"%s\"", buff);
assertMakeDir(buff, 0775);
}
assertEqualInt(0, chdir(".."));
}
#define LIMIT_NONE 200
#define LIMIT_USTAR 100
static void
verify_tree(size_t limit)
{
char name1[260];
char name2[260];
size_t i, LOOP_MAX;
LOOP_MAX = compute_loop_max();
/* Generate the names we know should be there and verify them. */
for (i = 1; i < LOOP_MAX; i++) {
/* Verify a file named "f/abcdef..." */
sprintf(name1, "f/%s", filenames[i]);
if (i <= limit) {
assertFileExists(name1);
assertFileContents(name1, (int)strlen(name1), name1);
}
sprintf(name2, "l/%s", filenames[i]);
if (i + 2 <= limit) {
/* Verify hardlink "l/abcdef..." */
assertIsHardlink(name1, name2);
/* Verify hardlink "m/abcdef..." */
name2[0] = 'm';
assertIsHardlink(name1, name2);
}
if (canSymlink()) {
/* Verify symlink "s/abcdef..." */
sprintf(name1, "s/%s", filenames[i]);
sprintf(name2, "../f/%s", filenames[i]);
if (strlen(name2) <= limit)
assertIsSymlink(name1, name2, 0);
}
/* Verify dir "d/abcdef...". */
sprintf(name1, "d/%s", filenames[i]);
if (i + 1 <= limit) { /* +1 for trailing slash */
if (assertIsDir(name1, -1)) {
/* TODO: opendir/readdir this
* directory and make sure
* it's empty.
*/
}
}
}
#if !defined(_WIN32) || defined(__CYGWIN__)
{
const char *dp;
/* Now make sure nothing is there that shouldn't be. */
for (dp = "dflms"; *dp != '\0'; ++dp) {
DIR *d;
struct dirent *de;
char dir[2];
dir[0] = *dp; dir[1] = '\0';
d = opendir(dir);
failure("Unable to open dir '%s'", dir);
if (!assert(d != NULL))
continue;
while ((de = readdir(d)) != NULL) {
char *p = de->d_name;
if (p[0] == '.')
continue;
switch(dp[0]) {
case 'l': case 'm': case 'd':
failure("strlen(p)=%zu", strlen(p));
assert(strlen(p) < limit);
assertEqualString(p,
filenames[strlen(p)]);
break;
case 'f': case 's':
failure("strlen(p)=%zu", strlen(p));
assert(strlen(p) < limit + 1);
assertEqualString(p,
filenames[strlen(p)]);
break;
default:
failure("File %s shouldn't be here", p);
assert(0);
}
}
closedir(d);
}
}
#endif
}
static void
copy_basic(void)
{
int r;
/* NOTE: for proper operation on cygwin-1.5 and windows, the
* length of the name of the directory below, "plain", must be
* less than or equal to the length of the name of the original
* directory, "original" This restriction derives from the
* extremely limited pathname lengths on those platforms.
*/
assertMakeDir("plain", 0775);
assertEqualInt(0, chdir("plain"));
/*
* Use the tar program to create an archive.
*/
r = systemf("%s cf archive -C ../original f d l m s >pack.out 2>pack.err",
testprog);
failure("Error invoking \"%s cf\"", testprog);
assertEqualInt(r, 0);
/* Verify that nothing went to stdout or stderr. */
assertEmptyFile("pack.err");
assertEmptyFile("pack.out");
/*
* Use tar to unpack the archive into another directory.
*/
r = systemf("%s xf archive >unpack.out 2>unpack.err", testprog);
failure("Error invoking %s xf archive", testprog);
assertEqualInt(r, 0);
/* Verify that nothing went to stdout or stderr. */
assertEmptyFile("unpack.err");
assertEmptyFile("unpack.out");
verify_tree(LIMIT_NONE);
assertEqualInt(0, chdir(".."));
}
static void
copy_ustar(void)
{
const char *target = "ustar";
int r;
/* NOTE: for proper operation on cygwin-1.5 and windows, the
* length of the name of the directory below, "ustar", must be
* less than or equal to the length of the name of the original
* directory, "original" This restriction derives from the
* extremely limited pathname lengths on those platforms.
*/
assertMakeDir(target, 0775);
assertEqualInt(0, chdir(target));
/*
* Use the tar program to create an archive.
*/
r = systemf("%s cf archive --format=ustar -C ../original f d l m s >pack.out 2>pack.err",
testprog);
failure("Error invoking \"%s cf archive --format=ustar\"", testprog);
assertEqualInt(r, 0);
/* Verify that nothing went to stdout. */
assertEmptyFile("pack.out");
/* Stderr is non-empty, since there are a bunch of files
* with filenames too long to archive. */
/*
* Use tar to unpack the archive into another directory.
*/
r = systemf("%s xf archive >unpack.out 2>unpack.err", testprog);
failure("Error invoking %s xf archive", testprog);
assertEqualInt(r, 0);
/* Verify that nothing went to stdout or stderr. */
assertEmptyFile("unpack.err");
assertEmptyFile("unpack.out");
verify_tree(LIMIT_USTAR);
assertEqualInt(0, chdir("../.."));
}
DEFINE_TEST(test_copy)
{
assertUmask(0);
create_tree(); /* Create sample files in "original" dir. */
/* Test simple "tar -c | tar -x" pipeline copy. */
copy_basic();
/* Same, but constrain to ustar format. */
copy_ustar();
}

View file

@ -0,0 +1,45 @@
/*-
* Copyright (c) 2003-2009 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$");
/*
* Regression test: We used to get a bogus error message when we
* asked tar to copy entries out of an empty archive. See
* Issue 51 on libarchive.googlecode.com for details.
*/
DEFINE_TEST(test_empty_mtree)
{
int r;
assertMakeFile("test1.mtree", 0777, "#mtree\n");
r = systemf("%s cf test1.tar @test1.mtree >test1.out 2>test1.err",
testprog);
failure("Error invoking %s cf", testprog);
assertEqualInt(r, 0);
assertEmptyFile("test1.out");
assertEmptyFile("test1.err");
}

View file

@ -0,0 +1,9 @@
begin 664 test_extract.tar.Z
M'YV09M*P*1,#@,&#"!,J7,BPH<.'$",BA$'1A@T:(`!0C'&C!HR,&SM^U$BQ
M9$D9,T#$D`%CAHP;-&"@Q`@C1HP9-FH```%#HL^?0(,*!5!G#ITP<DB.J5-F
M:,.E39TN-$D1)-6,4K-JW<JUZ]`Q;]S0*2-V#H@W9D`$'!C#A0*O<./*G4NW
MKMV[>//JW<O7X=HR,OH*=EC2(D:2'#U:33R2JDF4*EFZA"F31@V>-F?<Z,ES
ML.>'18\FI0@5;FFOCJV:Q/JYM>NM8,62I6,6K5J!@-V^WLV[M^_?P(,+'TZ\
0N/'CR),K7\Z\N?/GT*,K!P``
`
end

View file

@ -0,0 +1,7 @@
begin 664 test_extract.tar.bz2
M0EIH.3%!629368N]6:```'U[D=(0`"!``7^```AK)9X`!```$0`(,`"X#&$Q
M,F`F``,83$R8"8``*J:")M0TCQ30-/%-3*]V3EE!&(DSM8?BJ4J)=TSJ4/"B
M,?#R_6>?9K=+H02NT0V040P3.SHF:(573*)M5&;!-%6RO=6F5":N"+,"YZ;L
AV+<]%F[GWYCR<%FRKAPR=7VY+'+1)_B[DBG"A(1=ZLT`
`
end

View file

@ -0,0 +1,7 @@
begin 644 test_extract.tar.grz
M1U)::7!)20`"!#HI``P``*P,``#U````SP```'<````[-=0OM"R^UP#^C?Z<
MFGU0]I:>SW7]H01)1\WY:59("M_=V4[N[R*'`H&:'E=O@5B(?T,0?@)%-:_D
M;EUP)!JVN)@V_:ABYS3+[[6/R(NU,-::]'X&;,]:,HR[*3#R!@:W)IGC`,&G
8L+IZ7]FP=8U_R?CZ2XPO)"H-ME3@P]$`
`
end

View file

@ -0,0 +1,7 @@
begin 664 test_extract.tar.gz
M'XL(""S!:U```W1E<W1?97AT<F%C="YT87(`2\O,235DH"TP,#`P,S-1`-*&
MYJ8&R#04&!DK&!H9&!N9FP"9)@H&AH;&9J8,"@8T=A<8E!:7)!8!G9)<FHI7
M'2%YB$\4X/00`<GY>26I>27%"OEI"FF@M*#'-=!.&@5T!*`X-Z*Q'23E?Q-3
A</XW-QC-__0`Z/G?:#3_CX)1,`I&P8@```&.A<``#```
`
end

View file

@ -0,0 +1,9 @@
begin 664 test_extract.tar.lrz
M3%):20`&``P``````````%T````!`0```@$`$`,`````#@`#`````$P``S<`
M-P`````5``%/`!```#H``6,``0``6``!IP`!```%`@%/`/`#`3T```0`"0`!
M=@$`!`#P!0```(5'8Z<&<`"E"````#,:2=:X2EY$(`=+>P?_D@0*H:&)P-5?
MZX%NI60,IT@(N<,S%?7H2TLP5)FN#[-;&&[/2A#BNH4(7#C+*&ZP<>K&B)AG
M:Z(;Y=]3<5Q$)_[[5M\7=]N7A$%\ZF:H2/,Q%BK$JA4L!,K(-RZU2X[/`%69
.9U@/B[!N",NH4]8F,M(`
`
end

View file

@ -0,0 +1,7 @@
begin 664 test_extract.tar.lz
M3%I)4`$,`#,:2=:X2EY2J/TZ6]L7]]N4K?J&A)E2#"A'E"T1EP+MU&;(P1FY
MV\,8BTS,N0/O2=#67;G5)%I'C,D.U?*T!NX("FYPYI9I40F>X))?^8\?E?#>
MOP";"GD#8(9*K;XP318H<O&!L/<?HIOYPSNA8V5:E"239/Z<6[6>XZ\?_^SZ
6K-(!CH7```P```````"=````````````
`
end

View file

@ -0,0 +1,8 @@
begin 644 test_extract.tar.lz4
M!")-&&1PN:L```!O9FEL93$``0!+Z#`P,#8V-"``,#`Q-S4P"``#`@#_"3(S
M(#$R,#,R-S0P,C,T(#`Q,3,V-0`@,)<`2P("`+)U<W1A<@`P,&-U91$`#P(`
M!`\@``T"RP``W0```@`?($8`!`\"`'[!8V]N=&5N=',@;V8@#`(O+@JD`'X/
M`@#_2@#T`1\R80%,#P`$&B$T-0`$+S<P``3_9!\R``3_W0\"`/___^M0````
*````````J.?`=```
`
end

View file

@ -0,0 +1,7 @@
begin 664 test_extract.tar.lzma
M70``@`#__________P`S&DG6N$I>4JC].EO;%_?;E*WZAH294@PH1Y0M$9<"
M[=1FR,$9N=O#&(M,Q24U'H+5Z^7^*J;G!)OU]O'2D;AZ&0^IO?>-YA]$:-X_
MD^O)YVM(4`^-MT$X`.D(6)*$]3HNB9KJ_H=1$QKYZ:`:,H_L"H[#"?#Z5A<]
%O_OZW=D`
`
end

View file

@ -0,0 +1,9 @@
begin 664 test_extract.tar.lzo
MB4Q:3P`-"AH*$#`@8`E``04#```!``"!M%!R@T``````$'1E<W1?97AT<F%C
M="YT87*FJ0IM```,`````+BYG#.C`V9I;&4Q`"`]```+,#`P-C8T(``P,#$W
M-3`J'0`PH```!C(S(#$R,#,R-S0P,C,T(#`Q,3,V-0`@,"`]6`*T"PAU<W1A
M<@`P,&-U9:`"-10`/GP`I!EP&V4!(#44`2!P6``)8V]N=&5N=',@;V8@CD$N
M"B!PC`(@`#Q``FT^,B`^@`4@#/X/-#6>?S<P(`!6_0\R(`#/_`\@/N@/(```
=`')X`0X``````````````````````!$`````````
`
end

View file

@ -0,0 +1,8 @@
begin 664 test_extract.tar.xz
M_3=Z6%H```3FUK1&`@`A`18```!T+^6CX`O_`'E=`#,:2=:X2EY2J/TZ6]L7
M]]N4K?J&A)E2#"A'E"T1EP+MU&;(P1FYV\,8BTS%)34>@M7KY?XJIN<$F_7V
M\=*1N'H9#ZF]]XWF'T1HWC^3Z\GG:TA0#XVW03@`Z0A8DH3U.BZ)FNK^AU$3
M&OGIH!HRC^P*CL,)\/,MGP``````2IVA+$<(^YX``94!@!@``&X^\DRQQ&?[
(`@`````$65H`
`
end

View file

@ -0,0 +1,6 @@
begin 644 test_extract.tar.zst
M*+4O_010S0,`<L40$Z`5.(2U_RNV_[]L4V;Z_/R@1:7Y$3;9E`8$D$WI:W1)
M'58'D3->Y+>!0*5E/PM"$7^K^1VI3SS-AX&_W0KQWY!-Z1(`_4$%[$"]<T!A
L(*`#I!DXC4[J!6J8$!DJ$D"9$T*L]#G-$$/A`#`I`-(`UUKAU$Z@"`UXII``
`
end

View file

@ -0,0 +1,42 @@
/*-
* 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_extract_tar_Z)
{
const char *reffile = "test_extract.tar.Z";
extract_reference_file(reffile);
assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
testprog, reffile));
assertFileExists("file1");
assertTextFileContents("contents of file1.\n", "file1");
assertFileExists("file2");
assertTextFileContents("contents of file2.\n", "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
}

View file

@ -0,0 +1,48 @@
/*-
* 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_extract_tar_bz2)
{
const char *reffile = "test_extract.tar.bz2";
int f;
extract_reference_file(reffile);
f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
if (f == 0 || canBzip2()) {
assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
testprog, reffile));
assertFileExists("file1");
assertTextFileContents("contents of file1.\n", "file1");
assertFileExists("file2");
assertTextFileContents("contents of file2.\n", "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
} else {
skipping("It seems bzip2 is not supported on this platform");
}
}

View file

@ -0,0 +1,48 @@
/*-
* 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_extract_tar_grz)
{
const char *reffile = "test_extract.tar.grz";
int f;
extract_reference_file(reffile);
f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
if (f == 0 || canGrzip()) {
assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
testprog, reffile));
assertFileExists("file1");
assertTextFileContents("contents of file1.\n", "file1");
assertFileExists("file2");
assertTextFileContents("contents of file2.\n", "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
} else {
skipping("It seems grzip is not supported on this platform");
}
}

View file

@ -0,0 +1,48 @@
/*-
* 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_extract_tar_gz)
{
const char *reffile = "test_extract.tar.gz";
int f;
extract_reference_file(reffile);
f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
if (f == 0 || canGzip()) {
assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
testprog, reffile));
assertFileExists("file1");
assertTextFileContents("contents of file1.\n", "file1");
assertFileExists("file2");
assertTextFileContents("contents of file2.\n", "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
} else {
skipping("It seems gzip is not supported on this platform");
}
}

View file

@ -0,0 +1,48 @@
/*-
* 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_extract_tar_lrz)
{
const char *reffile = "test_extract.tar.lrz";
int f;
extract_reference_file(reffile);
f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
if (f == 0 || canLrzip()) {
assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
testprog, reffile));
assertFileExists("file1");
assertTextFileContents("contents of file1.\n", "file1");
assertFileExists("file2");
assertTextFileContents("contents of file2.\n", "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
} else {
skipping("It seems lrzip is not supported on this platform");
}
}

View file

@ -0,0 +1,48 @@
/*-
* 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_extract_tar_lz)
{
const char *reffile = "test_extract.tar.lz";
int f;
extract_reference_file(reffile);
f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
if (f == 0 || canLzip()) {
assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
testprog, reffile));
assertFileExists("file1");
assertTextFileContents("contents of file1.\n", "file1");
assertFileExists("file2");
assertTextFileContents("contents of file2.\n", "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
} else {
skipping("It seems lzip is not supported on this platform");
}
}

View file

@ -0,0 +1,48 @@
/*-
* Copyright (c) 2012,2014 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_extract_tar_lz4)
{
const char *reffile = "test_extract.tar.lz4";
int f;
extract_reference_file(reffile);
f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
if (f == 0 || canLz4()) {
assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
testprog, reffile));
assertFileExists("file1");
assertTextFileContents("contents of file1.\n", "file1");
assertFileExists("file2");
assertTextFileContents("contents of file2.\n", "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
} else {
skipping("It seems lz4 is not supported on this platform");
}
}

View file

@ -0,0 +1,48 @@
/*-
* 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_extract_tar_lzma)
{
const char *reffile = "test_extract.tar.lzma";
int f;
extract_reference_file(reffile);
f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
if (f == 0 || canLzma()) {
assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
testprog, reffile));
assertFileExists("file1");
assertTextFileContents("contents of file1.\n", "file1");
assertFileExists("file2");
assertTextFileContents("contents of file2.\n", "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
} else {
skipping("It seems lzma is not supported on this platform");
}
}

View file

@ -0,0 +1,48 @@
/*-
* 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_extract_tar_lzo)
{
const char *reffile = "test_extract.tar.lzo";
int f;
extract_reference_file(reffile);
f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
if (f == 0 || canLzop()) {
assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
testprog, reffile));
assertFileExists("file1");
assertTextFileContents("contents of file1.\n", "file1");
assertFileExists("file2");
assertTextFileContents("contents of file2.\n", "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
} else {
skipping("It seems lzop is not supported on this platform");
}
}

View file

@ -0,0 +1,48 @@
/*-
* 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_extract_tar_xz)
{
const char *reffile = "test_extract.tar.xz";
int f;
extract_reference_file(reffile);
f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
if (f == 0 || canXz()) {
assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
testprog, reffile));
assertFileExists("file1");
assertTextFileContents("contents of file1.\n", "file1");
assertFileExists("file2");
assertTextFileContents("contents of file2.\n", "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
} else {
skipping("It seems xz is not supported on this platform");
}
}

View file

@ -0,0 +1,48 @@
/*-
* Copyright (c) 2017 Sean Purcell
* 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_extract_tar_zstd)
{
const char *reffile = "test_extract.tar.zst";
int f;
extract_reference_file(reffile);
f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
if (f == 0 || canZstd()) {
assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
testprog, reffile));
assertFileExists("file1");
assertTextFileContents("contents of file1.\n", "file1");
assertFileExists("file2");
assertTextFileContents("contents of file2.\n", "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
} else {
skipping("It seems zstd is not supported on this platform");
}
}

View file

@ -0,0 +1,64 @@
/*-
* 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_format_newc)
{
assertMakeFile("file1", 0644, "file1");
assertMakeFile("file2", 0644, "file2");
assertMakeHardlink("file3", "file1");
/* Test 1: Create an archive file with a newc format. */
assertEqualInt(0,
systemf("%s -cf test1.cpio --format newc file1 file2 file3",
testprog));
assertMakeDir("test1", 0755);
assertChdir("test1");
assertEqualInt(0,
systemf("%s -xf ../test1.cpio >test.out 2>test.err", testprog));
assertFileContents("file1", 5, "file1");
assertFileContents("file2", 5, "file2");
assertFileContents("file1", 5, "file3");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 2: Exclude one of hardlinked files. */
assertEqualInt(0,
systemf("%s -cf test2.cpio --format newc file1 file2",
testprog));
assertMakeDir("test2", 0755);
assertChdir("test2");
assertEqualInt(0,
systemf("%s -xf ../test2.cpio >test.out 2>test.err", testprog));
assertFileContents("file1", 5, "file1");
assertFileContents("file2", 5, "file2");
assertFileNotExists("file3");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
}

View file

@ -0,0 +1,84 @@
/*-
* Copyright (c) 2003-2007 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: src/usr.bin/tar/test/test_help.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $");
/*
* Test that "--help", "-h", and "-W help" options all work and
* generate reasonable output.
*/
static int
in_first_line(const char *p, const char *substring)
{
size_t l = strlen(substring);
while (*p != '\0' && *p != '\n') {
if (memcmp(p, substring, l) == 0)
return (1);
++p;
}
return (0);
}
DEFINE_TEST(test_help)
{
int r;
char *p;
size_t plen;
/* Exercise --help option. */
r = systemf("%s --help >help.stdout 2>help.stderr", testprog);
assertEqualInt(r, 0);
failure("--help should generate nothing to stderr.");
assertEmptyFile("help.stderr");
/* Help message should start with name of program. */
p = slurpfile(&plen, "help.stdout");
failure("Help output should be long enough.");
assert(plen >= 6);
failure("First line of help output should contain 'bsdtar': %s", p);
assert(in_first_line(p, "bsdtar"));
/*
* TODO: Extend this check to further verify that --help output
* looks approximately right.
*/
free(p);
/* -h option should generate the same output. */
r = systemf("%s -h >h.stdout 2>h.stderr", testprog);
assertEqualInt(r, 0);
failure("-h should generate nothing to stderr.");
assertEmptyFile("h.stderr");
failure("stdout should be same for -h and --help");
assertEqualFile("h.stdout", "help.stdout");
/* -W help should be another synonym. */
r = systemf("%s -W help >Whelp.stdout 2>Whelp.stderr", testprog);
assertEqualInt(r, 0);
failure("-W help should generate nothing to stderr.");
assertEmptyFile("Whelp.stderr");
failure("stdout should be same for -W help and --help");
assertEqualFile("Whelp.stdout", "help.stdout");
}

View file

@ -0,0 +1,50 @@
/*-
* Copyright (c) 2003-2014 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_leading_slash)
{
const char *reffile = "test_leading_slash.tar";
char *errfile;
size_t errfile_size;
const char *expected_errmsg = "Removing leading '/' from member names";
extract_reference_file(reffile);
assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err", testprog, reffile));
assertFileExists("foo/file");
assertTextFileContents("foo\x0a", "foo/file");
assertTextFileContents("foo\x0a", "foo/hardlink");
assertIsHardlink("foo/file", "foo/hardlink");
assertEmptyFile("test.out");
/* Verify the error output contains the expected text somewhere in it */
if (assertFileExists("test.err")) {
errfile = slurpfile(&errfile_size, "test.err");
assert(strstr(errfile, expected_errmsg) != NULL);
free(errfile);
}
}

View file

@ -0,0 +1,60 @@
begin 644 test_leading_slash.tar
M+V9O;R]F:6QE````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````#`P,#8T-"``,#`P,#`P(``P,#`P,#`@`#`P,#`P,#`P,#`T
M(#$R-#$V,S4U-34V(#`Q,C8V-P`@,```````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````````!U<W1A<@`P,')O;W0`
M````````````````````````````````````=VAE96P`````````````````
M```````````````````P,#`P,#`@`#`P,#`P,"``````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````!F;V\*````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````````"]F;V\O:&%R9&QI
M;FL`````````````````````````````````````````````````````````
M```````````````````````````````````````````````````````````P
M,#`V-#0@`#`P,#`P,"``,#`P,#`P(``P,#`P,#`P,#`P,"`Q,C0Q-C,U-34U
M-B`P,34R-#,`(#$O9F]O+V9I;&4`````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````=7-T87(`,#!R;V]T````````````````
M`````````````````````'=H965L````````````````````````````````
M````,#`P,#`P(``P,#`P,#`@````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
H````````````````````````````````````````````````````````
`
end

View file

@ -0,0 +1,41 @@
/*-
* 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)
{
const char * invalid_stderr[] = { "INTERNAL ERROR", NULL };
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));
assertFileContainsNoInvalidStrings("stderr2", invalid_stderr);
assert(0 != systemf("%s -cf archive.tar 2>stderr3", testprog));
assertFileContainsNoInvalidStrings("stderr3", invalid_stderr);
assert(0 != systemf("%s -cf archive.tar file3 file4 2>stderr4", testprog));
assertFileContainsNoInvalidStrings("stderr4", invalid_stderr);
}

View file

@ -0,0 +1,89 @@
/*-
* Copyright (c) 2018 The FreeBSD Foundation
* All rights reserved.
*
* This software was developed by Arshan Khanifar <arshankhanifar@gmail.com>
* under sponsorship from the FreeBSD Foundation.
*
* 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_C_mtree)
{
char *p0;
size_t s;
int r;
p0 = NULL;
char *content = "./foo type=file uname=root gname=root mode=0755\n";
char *filename = "output.tar";
#if defined(_WIN32) && !defined(CYGWIN)
char *p;
#endif
/* an absolute path to mtree file */
char *mtree_file = "/METALOG.mtree";
char *absolute_path = malloc(strlen(testworkdir) + strlen(mtree_file) + 1);
strcpy(absolute_path, testworkdir);
strcat(absolute_path, mtree_file );
/* Create an archive using an mtree file. */
assertMakeFile(absolute_path, 0777, content);
assertMakeDir("bar", 0775);
assertMakeFile("bar/foo", 0777, "abc");
#if defined(_WIN32) && !defined(CYGWIN)
p = absolute_path;
while(*p != '\0') {
if (*p == '/')
*p = '\\';
p++;
}
r = systemf("%s -cf %s -C bar @%s >step1.out 2>step1.err", testprog, filename, absolute_path);
failure("Error invoking %s -cf %s -C bar @%s", testprog, filename, absolute_path);
#else
r = systemf("%s -cf %s -C bar \"@%s\" >step1.out 2>step1.err", testprog, filename, absolute_path);
failure("Error invoking %s -cf %s -C bar \"@%s\"", testprog, filename, absolute_path);
#endif
assertEqualInt(r, 0);
assertEmptyFile("step1.out");
assertEmptyFile("step1.err");
/* Do validation of the constructed archive. */
p0 = slurpfile(&s, "output.tar");
if (!assert(p0 != NULL))
goto done;
if (!assert(s >= 2048))
goto done;
assertEqualMem(p0 + 0, "./foo", 5);
assertEqualMem(p0 + 512, "abc", 3);
assertEqualMem(p0 + 1024, "\0\0\0\0\0\0\0\0", 8);
assertEqualMem(p0 + 1536, "\0\0\0\0\0\0\0\0", 8);
done:
free(p0);
free(absolute_path);
}

View file

@ -0,0 +1,149 @@
/*-
* Copyright (c) 2010 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_option_C_upper)
{
int r;
assertMakeDir("d1", 0755);
assertMakeDir("d2", 0755);
assertMakeFile("d1/file1", 0644, "d1/file1");
assertMakeFile("d1/file2", 0644, "d1/file2");
assertMakeFile("d2/file1", 0644, "d2/file1");
assertMakeFile("d2/file2", 0644, "d2/file2");
/*
* Test 1: Basic use of -C
*/
assertMakeDir("test1", 0755);
assertChdir("test1");
assertEqualInt(0, systemf("%s -cf archive.tar -C ../d1 file1 -C ../d2 file2", testprog));
assertEqualInt(0,
systemf("%s -xf archive.tar >test.out 2>test.err", testprog));
assertFileContents("d1/file1", 8, "file1");
assertFileContents("d2/file2", 8, "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/*
* Test 2: Multiple -C
*/
assertMakeDir("test2", 0755);
assertChdir("test2");
assertEqualInt(0, systemf("%s -cf archive.tar -C .. -C d1 file1 -C .. -C d2 file2", testprog));
assertEqualInt(0,
systemf("%s -xf archive.tar >test.out 2>test.err", testprog));
assertFileContents("d1/file1", 8, "file1");
assertFileContents("d2/file2", 8, "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/*
* Test 3: -C fail
*/
assertMakeDir("test3", 0755);
assertChdir("test3");
r = systemf("%s -cf archive.tar -C ../XXX file1 -C ../d2 file2 2>write.err", testprog);
assert(r != 0);
assertNonEmptyFile("write.err");
assertEqualInt(0,
systemf("%s -xf archive.tar >test.out 2>test.err", testprog));
assertFileNotExists("file1");
assertFileNotExists("file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/*
* Test 4: Absolute -C
*/
assertMakeDir("test4", 0755);
assertChdir("test4");
assertEqualInt(0,
systemf("%s -cf archive.tar -C %s/d1 file1",
testprog, testworkdir));
assertEqualInt(0,
systemf("%s -xf archive.tar >test.out 2>test.err", testprog));
assertFileContents("d1/file1", 8, "file1");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/*
* Test 5: Unnecessary -C ignored even if directory named doesn't exist
*/
assertMakeDir("test5", 0755);
assertChdir("test5");
assertEqualInt(0,
systemf("%s -cf archive.tar -C XXX -C %s/d1 file1",
testprog, testworkdir));
assertEqualInt(0,
systemf("%s -xf archive.tar >test.out 2>test.err", testprog));
assertFileContents("d1/file1", 8, "file1");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/*
* Test 6: Necessary -C not ignored if directory doesn't exist
*/
assertMakeDir("test6", 0755);
assertChdir("test6");
r = systemf("%s -cf archive.tar -C XXX -C ../d1 file1 2>write.err",
testprog);
assert(r != 0);
assertNonEmptyFile("write.err");
assertEqualInt(0,
systemf("%s -xf archive.tar >test.out 2>test.err", testprog));
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/*
* Test 7: -C used without specifying directory
*/
assertMakeDir("test7", 0755);
assertChdir("test7");
r = systemf("%s -cf archive.tar ../d1/file1 -C 2>write.err", testprog);
assert(r != 0);
assertNonEmptyFile("write.err");
assertChdir("..");
/*
* Test 8: -C used with meaningless option ''
*/
assertMakeDir("test8", 0755);
assertChdir("test8");
r = systemf("%s -cf archive.tar ../d1/file1 -C \"\" 2>write.err",
testprog);
assert(r != 0);
assertNonEmptyFile("write.err");
assertChdir("..");
}

View file

@ -0,0 +1,92 @@
/*-
* Copyright (c) 2010 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_option_H_upper)
{
if (!canSymlink()) {
skipping("Can't test symlinks on this filesystem");
return;
}
/*
* Create a sample archive.
*/
assertMakeDir("in", 0755);
assertChdir("in");
assertMakeDir("d1", 0755);
assertMakeSymlink("ld1", "d1", 1);
assertMakeFile("d1/file1", 0644, "d1/file1");
assertMakeFile("d1/file2", 0644, "d1/file2");
assertMakeSymlink("d1/link1", "file1", 0);
assertMakeSymlink("d1/linkX", "fileX", 0);
assertMakeSymlink("link2", "d1/file2", 0);
assertMakeSymlink("linkY", "d1/fileY", 0);
assertChdir("..");
/* Test 1: Without -H */
assertMakeDir("test1", 0755);
assertEqualInt(0,
systemf("%s -cf test1/archive.tar -C in . >test1/c.out 2>test1/c.err", testprog));
assertChdir("test1");
assertEqualInt(0,
systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
assertIsSymlink("ld1", "d1", 1);
assertIsSymlink("d1/link1", "file1", 0);
assertIsSymlink("d1/linkX", "fileX", 0);
assertIsSymlink("link2", "d1/file2", 0);
assertIsSymlink("linkY", "d1/fileY", 0);
assertChdir("..");
/* Test 2: With -H, no symlink on command line. */
assertMakeDir("test2", 0755);
assertEqualInt(0,
systemf("%s -cf test2/archive.tar -H -C in . >test2/c.out 2>test2/c.err", testprog));
assertChdir("test2");
assertEqualInt(0,
systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
assertIsSymlink("ld1", "d1", 1);
assertIsSymlink("d1/link1", "file1", 0);
assertIsSymlink("d1/linkX", "fileX", 0);
assertIsSymlink("link2", "d1/file2", 0);
assertIsSymlink("linkY", "d1/fileY", 0);
assertChdir("..");
/* Test 3: With -H, some symlinks on command line. */
assertMakeDir("test3", 0755);
assertEqualInt(0,
systemf("%s -cf test3/archive.tar -H -C in ld1 d1 link2 linkY >test2/c.out 2>test2/c.err", testprog));
assertChdir("test3");
assertEqualInt(0,
systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
assertIsDir("ld1", umasked(0755));
assertIsSymlink("d1/linkX", "fileX", 0);
assertIsSymlink("d1/link1", "file1", 0);
assertIsReg("link2", umasked(0644));
assertIsSymlink("linkY", "d1/fileY", 0);
assertChdir("..");
}

View file

@ -0,0 +1,92 @@
/*-
* Copyright (c) 2010 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_option_L_upper)
{
if (!canSymlink()) {
skipping("Can't test symlinks on this filesystem");
return;
}
/*
* Create a sample archive.
*/
assertMakeDir("in", 0755);
assertChdir("in");
assertMakeDir("d1", 0755);
assertMakeSymlink("ld1", "d1", 1);
assertMakeFile("d1/file1", 0644, "d1/file1");
assertMakeFile("d1/file2", 0644, "d1/file2");
assertMakeSymlink("d1/link1", "file1", 0);
assertMakeSymlink("d1/linkX", "fileX", 0);
assertMakeSymlink("link2", "d1/file2", 0);
assertMakeSymlink("linkY", "d1/fileY", 0);
assertChdir("..");
/* Test 1: Without -L */
assertMakeDir("test1", 0755);
assertEqualInt(0,
systemf("%s -cf test1/archive.tar -C in . >test1/c.out 2>test1/c.err", testprog));
assertChdir("test1");
assertEqualInt(0,
systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
assertIsSymlink("ld1", "d1", 1);
assertIsSymlink("d1/link1", "file1", 0);
assertIsSymlink("d1/linkX", "fileX", 0);
assertIsSymlink("link2", "d1/file2", 0);
assertIsSymlink("linkY", "d1/fileY", 0);
assertChdir("..");
/* Test 2: With -L, no symlink on command line. */
assertMakeDir("test2", 0755);
assertEqualInt(0,
systemf("%s -cf test2/archive.tar -L -C in . >test2/c.out 2>test2/c.err", testprog));
assertChdir("test2");
assertEqualInt(0,
systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
assertIsDir("ld1", umasked(0755));
assertIsReg("d1/link1", umasked(0644));
assertIsSymlink("d1/linkX", "fileX", 0);
assertIsReg("link2", umasked(0644));
assertIsSymlink("linkY", "d1/fileY", 0);
assertChdir("..");
/* Test 3: With -L, some symlinks on command line. */
assertMakeDir("test3", 0755);
assertEqualInt(0,
systemf("%s -cf test3/archive.tar -L -C in ld1 d1 link2 linkY >test2/c.out 2>test2/c.err", testprog));
assertChdir("test3");
assertEqualInt(0,
systemf("%s -xf archive.tar >c.out 2>c.err", testprog));
assertIsDir("ld1", umasked(0755));
assertIsReg("d1/link1", umasked(0644));
assertIsSymlink("d1/linkX", "fileX", 0);
assertIsReg("link2", umasked(0644));
assertIsSymlink("linkY", "d1/fileY", 0);
assertChdir("..");
}

View file

@ -0,0 +1,87 @@
/*-
* Copyright (c) 2010 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$");
static const char *test4out[] = {"file1", "file2", NULL};
static const char *test5err[] = {"file1", "file2", NULL};
DEFINE_TEST(test_option_O_upper)
{
assertMakeFile("file1", 0644, "file1");
assertMakeFile("file2", 0644, "file2");
assertEqualInt(0, systemf("%s -cf archive.tar file1 file2", testprog));
/* Test 1: -x without -O */
assertMakeDir("test1", 0755);
assertChdir("test1");
assertEqualInt(0,
systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog));
assertFileContents("file1", 5, "file1");
assertFileContents("file2", 5, "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 2: -x with -O */
assertMakeDir("test2", 0755);
assertChdir("test2");
assertEqualInt(0,
systemf("%s -xOf ../archive.tar file1 >test.out 2>test.err", testprog));
assertFileNotExists("file1");
assertFileNotExists("file2");
assertFileContents("file1", 5, "test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 3: -x with -O and multiple files */
assertMakeDir("test3", 0755);
assertChdir("test3");
assertEqualInt(0,
systemf("%s -xOf ../archive.tar >test.out 2>test.err", testprog));
assertFileNotExists("file1");
assertFileNotExists("file2");
assertFileContents("file1file2", 10, "test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 4: -t without -O */
assertMakeDir("test4", 0755);
assertChdir("test4");
assertEqualInt(0,
systemf("%s -tf ../archive.tar >test.out 2>test.err", testprog));
assertFileContainsLinesAnyOrder("test.out", test4out);
assertEmptyFile("test.err");
assertChdir("..");
/* Test 5: -t with -O */
assertMakeDir("test5", 0755);
assertChdir("test5");
assertEqualInt(0,
systemf("%s -tOf ../archive.tar >test.out 2>test.err", testprog));
assertEmptyFile("test.out");
assertFileContainsLinesAnyOrder("test.err", test5err);
assertChdir("..");
}

View file

@ -0,0 +1,160 @@
/*-
* Copyright (c) 2003-2008 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: src/usr.bin/tar/test/test_option_T.c,v 1.3 2008/08/15 06:12:02 kientzle Exp $");
static int
tryMakeFile(const char *fn)
{
FILE *f = fopen(fn, "w");
if (f == NULL)
return (0);
fclose(f);
return (1);
}
DEFINE_TEST(test_option_T_upper)
{
FILE *f;
int r;
int gnarlyFilesSupported;
/* Create a simple dir hierarchy; bail if anything fails. */
if (!assertMakeDir("d1", 0755)) return;
if (!assertMakeDir("d1/d2", 0755)) return;
if (!assertMakeFile("f", 0644, "")) return;
if (!assertMakeFile("d1/f1", 0644, "")) return;
if (!assertMakeFile("d1/f2", 0644, "")) return;
if (!assertMakeFile("d1/d2/f3", 0644, "")) return;
if (!assertMakeFile("d1/d2/f4", 0644, "")) return;
if (!assertMakeFile("d1/d2/f5", 0644, "")) return;
if (!assertMakeFile("d1/d2/f6", 0644, "")) return;
/* Some platforms don't permit such things; just skip it. */
gnarlyFilesSupported = tryMakeFile("d1/d2/f\x0a");
/* Populate a file list */
f = fopen("filelist", "w+");
if (!assert(f != NULL))
return;
/* Use a variety of text line endings. */
fprintf(f, "f\x0d"); /* CR */
fprintf(f, "d1/f1\x0d\x0a"); /* CRLF */
fprintf(f, "d1/d2/f4\x0a"); /* NL */
fprintf(f, "d1/d2/f6"); /* EOF */
fclose(f);
/* Populate a second file list */
f = fopen("filelist2", "w+");
if (!assert(f != NULL))
return;
/* Use null-terminated names. */
fprintf(f, "d1/d2/f3");
assertEqualInt(1, fwrite("\0", 1, 1, f));
fprintf(f, "d1/d2/f5");
assertEqualInt(1, fwrite("\0", 1, 1, f));
if (gnarlyFilesSupported) {
fprintf(f, "d1/d2/f\x0a");
assertEqualInt(1, fwrite("\0", 1, 1, f));
}
fclose(f);
/* Use -c -T to archive up the files. */
r = systemf("%s -c -f test1.tar -T filelist > test1.out 2> test1.err",
testprog);
assert(r == 0);
assertEmptyFile("test1.out");
assertEmptyFile("test1.err");
/* Use -x -T to dearchive the files */
if (!assertMakeDir("test1", 0755)) return;
systemf("%s -x -f test1.tar -T filelist -C test1"
" > test1b.out 2> test1b.err", testprog);
assertEmptyFile("test1b.out");
assertEmptyFile("test1b.err");
/* Verify the files were extracted. */
assertFileExists("test1/f");
assertFileExists("test1/d1/f1");
assertFileNotExists("test1/d1/f2");
assertFileNotExists("test1/d1/d2/f3");
assertFileExists("test1/d1/d2/f4");
assertFileNotExists("test1/d1/d2/f5");
assertFileExists("test1/d1/d2/f6");
if (gnarlyFilesSupported) {
assertFileNotExists("test1/d1/d2/f\x0a");
}
/* Use -r -T to add more files to the archive. */
systemf("%s -r -f test1.tar --null -T filelist2 > test2.out 2> test2.err",
testprog);
assertEmptyFile("test2.out");
assertEmptyFile("test2.err");
/* Use -x without -T to dearchive the files (ensure -r worked) */
if (!assertMakeDir("test3", 0755)) return;
systemf("%s -x -f test1.tar -C test3"
" > test3.out 2> test3.err", testprog);
assertEmptyFile("test3.out");
assertEmptyFile("test3.err");
/* Verify the files were extracted.*/
assertFileExists("test3/f");
assertFileExists("test3/d1/f1");
assertFileNotExists("test3/d1/f2");
assertFileExists("test3/d1/d2/f3");
assertFileExists("test3/d1/d2/f4");
assertFileExists("test3/d1/d2/f5");
assertFileExists("test3/d1/d2/f6");
if (gnarlyFilesSupported) {
assertFileExists("test3/d1/d2/f\x0a");
}
/* Use -x -T to dearchive the files (verify -x -T together) */
if (!assertMakeDir("test2", 0755)) return;
systemf("%s -x -f test1.tar -T filelist -C test2"
" > test2b.out 2> test2b.err", testprog);
assertEmptyFile("test2b.out");
assertEmptyFile("test2b.err");
/* Verify the files were extracted.*/
assertFileExists("test2/f");
assertFileExists("test2/d1/f1");
assertFileNotExists("test2/d1/f2");
assertFileNotExists("test2/d1/d2/f3");
assertFileExists("test2/d1/d2/f4");
assertFileNotExists("test2/d1/d2/f5");
assertFileExists("test2/d1/d2/f6");
if (gnarlyFilesSupported) {
assertFileNotExists("test2/d1/d2/f\x0a");
}
assertMakeDir("test4", 0755);
assertMakeDir("test4_out", 0755);
assertMakeDir("test4_out2", 0755);
assertMakeDir("test4/d1", 0755);
assertMakeFile("test4/d1/foo", 0644, "");
/* TODO: Include some use of -C directory-changing within the filelist. */
/* I'm pretty sure -C within the filelist is broken on extract. */
}

View file

@ -0,0 +1,159 @@
/*-
* Copyright (c) 2010 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_option_U_upper)
{
int r;
assertMakeFile("file1", 0644, "file1");
assertMakeDir("d1", 0755);
assertMakeFile("d1/file1", 0644, "d1/file1");
assertEqualInt(0, systemf("%s -cf archive.tar file1 d1/file1", testprog));
/*
* bsdtar's man page used to claim that -x without -U would
* not break hard links. This was and is nonsense. The first
* two tests here simply verify that existing hard links get
* broken regardless.
*/
/* Test 1: -x without -U */
assertMakeDir("test1", 0755);
assertChdir("test1");
assertMakeFile("file1", 0644, "file1new");
assertMakeHardlink("file2", "file1");
assertEqualInt(0,
systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog));
assertFileContents("file1", 5, "file1");
assertFileContents("file1new", 8, "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 2: -x with -U */
assertMakeDir("test2", 0755);
assertChdir("test2");
assertMakeFile("file1", 0644, "file1new");
assertMakeHardlink("file2", "file1");
assertEqualInt(0,
systemf("%s -xUf ../archive.tar >test.out 2>test.err", testprog));
assertFileContents("file1", 5, "file1");
assertFileContents("file1new", 8, "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/*
* -U does make a difference in how bsdtar handles unwanted symlinks,
* though. It interacts with -P.
*/
if (!canSymlink())
return;
/* Test 3: Intermediate dir symlink causes error by default */
assertMakeDir("test3", 0755);
assertChdir("test3");
assertMakeDir("realDir", 0755);
assertMakeSymlink("d1", "realDir", 1);
r = systemf("%s -xf ../archive.tar d1/file1 >test.out 2>test.err", testprog);
assert(r != 0);
assertIsSymlink("d1", "realDir", 1);
assertFileNotExists("d1/file1");
assertEmptyFile("test.out");
assertNonEmptyFile("test.err");
assertChdir("..");
/* Test 4: Intermediate dir symlink gets removed with -U */
assertMakeDir("test4", 0755);
assertChdir("test4");
assertMakeDir("realDir", 0755);
assertMakeSymlink("d1", "realDir", 1);
assertEqualInt(0,
systemf("%s -xUf ../archive.tar >test.out 2>test.err", testprog));
assertIsDir("d1", -1);
assertFileContents("d1/file1", 8, "d1/file1");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 5: Intermediate dir symlink is followed with -P */
assertMakeDir("test5", 0755);
assertChdir("test5");
assertMakeDir("realDir", 0755);
assertMakeSymlink("d1", "realDir", 1);
assertEqualInt(0,
systemf("%s -xPf ../archive.tar d1/file1 >test.out 2>test.err", testprog));
assertIsSymlink("d1", "realDir", 1);
assertFileContents("d1/file1", 8, "d1/file1");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 6: Intermediate dir symlink is followed with -PU */
assertMakeDir("test6", 0755);
assertChdir("test6");
assertMakeDir("realDir", 0755);
assertMakeSymlink("d1", "realDir", 1);
assertEqualInt(0,
systemf("%s -xPUf ../archive.tar d1/file1 >test.out 2>test.err", testprog));
assertIsSymlink("d1", "realDir", 1);
assertFileContents("d1/file1", 8, "d1/file1");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 7: Final file symlink replaced by default */
assertMakeDir("test7", 0755);
assertChdir("test7");
assertMakeDir("d1", 0755);
assertMakeFile("d1/realfile1", 0644, "realfile1");
assertMakeSymlink("d1/file1", "d1/realfile1", 0);
assertEqualInt(0,
systemf("%s -xf ../archive.tar d1/file1 >test.out 2>test.err", testprog));
assertIsReg("d1/file1", umasked(0644));
assertFileContents("d1/file1", 8, "d1/file1");
assertFileContents("realfile1", 9, "d1/realfile1");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 8: Final file symlink replaced with -PU */
assertMakeDir("test8", 0755);
assertChdir("test8");
assertMakeDir("d1", 0755);
assertMakeFile("d1/realfile1", 0644, "realfile1");
assertMakeSymlink("d1/file1", "d1/realfile1", 0);
assertEqualInt(0,
systemf("%s -xPUf ../archive.tar d1/file1 >test.out 2>test.err", testprog));
assertIsReg("d1/file1", umasked(0644));
assertFileContents("d1/file1", 8, "d1/file1");
assertFileContents("realfile1", 9, "d1/realfile1");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
}

View file

@ -0,0 +1,159 @@
/*-
* Copyright (c) 2010 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_option_X_upper)
{
int r;
/*
* Create a sample archive.
*/
assertMakeFile("file1", 0644, "file1");
assertMakeFile("file2", 0644, "file2");
assertMakeFile("file3a", 0644, "file3a");
assertMakeFile("file4a", 0644, "file4a");
assertEqualInt(0,
systemf("%s -cf archive.tar file1 file2 file3a file4a", testprog));
/*
* Now, try extracting from the test archive with various -X usage.
*/
/* Test 1: Without -X */
assertMakeDir("test1", 0755);
assertChdir("test1");
r = systemf("%s -xf ../archive.tar >test.out 2>test.err",
testprog);
if (!assertEqualInt(0, r))
return;
assertFileContents("file1", 5, "file1");
assertFileContents("file2", 5, "file2");
assertFileContents("file3a", 6, "file3a");
assertFileContents("file4a", 6, "file4a");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 2: Use -X to skip one file */
assertMakeDir("test2", 0755);
assertChdir("test2");
assertMakeFile("exclusions", 0644, "file1\n");
assertEqualInt(0,
systemf("%s -xf ../archive.tar -X exclusions >test.out 2>test.err", testprog));
assertFileNotExists("file1");
assertFileContents("file2", 5, "file2");
assertFileContents("file3a", 6, "file3a");
assertFileContents("file4a", 6, "file4a");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 3: Use -X to skip multiple files */
assertMakeDir("test3", 0755);
assertChdir("test3");
assertMakeFile("exclusions", 0644, "file1\nfile2\n");
assertEqualInt(0,
systemf("%s -xf ../archive.tar -X exclusions >test.out 2>test.err", testprog));
assertFileNotExists("file1");
assertFileNotExists("file2");
assertFileContents("file3a", 6, "file3a");
assertFileContents("file4a", 6, "file4a");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 4: Omit trailing \n */
assertMakeDir("test4", 0755);
assertChdir("test4");
assertMakeFile("exclusions", 0644, "file1\nfile2");
assertEqualInt(0,
systemf("%s -xf ../archive.tar -X exclusions >test.out 2>test.err", testprog));
assertFileNotExists("file1");
assertFileNotExists("file2");
assertFileContents("file3a", 6, "file3a");
assertFileContents("file4a", 6, "file4a");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 5: include/exclude without overlap */
assertMakeDir("test5", 0755);
assertChdir("test5");
assertMakeFile("exclusions", 0644, "file1\nfile2");
assertEqualInt(0,
systemf("%s -xf ../archive.tar -X exclusions file3a >test.out 2>test.err", testprog));
assertFileNotExists("file1");
assertFileNotExists("file2");
assertFileContents("file3a", 6, "file3a");
assertFileNotExists("file4a");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 6: Overlapping include/exclude */
assertMakeDir("test6", 0755);
assertChdir("test6");
assertMakeFile("exclusions", 0644, "file1\nfile2");
assertEqualInt(0,
systemf("%s -xf ../archive.tar -X exclusions file1 file3a >test.out 2>test.err", testprog));
assertFileNotExists("file1");
assertFileNotExists("file2");
assertFileContents("file3a", 6, "file3a");
assertFileNotExists("file4a");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 7: with pattern */
assertMakeDir("test7", 0755);
assertChdir("test7");
assertMakeFile("exclusions", 0644, "file*a\nfile1");
assertEqualInt(0,
systemf("%s -xf ../archive.tar -X exclusions >test.out 2>test.err", testprog));
assertFileNotExists("file1");
assertFileContents("file2", 5, "file2");
assertFileNotExists("file3a");
assertFileNotExists("file4a");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 8: with empty exclusions file */
assertMakeDir("test8", 0755);
assertChdir("test8");
assertMakeFile("exclusions", 0644, "");
assertEqualInt(0,
systemf("%s -xf ../archive.tar -X exclusions >test.out 2>test.err", testprog));
assertFileContents("file1", 5, "file1");
assertFileContents("file2", 5, "file2");
assertFileContents("file3a", 6, "file3a");
assertFileContents("file4a", 6, "file4a");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
}

View file

@ -0,0 +1,117 @@
/*-
* 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_a)
{
size_t s;
char *p;
/* Create a file. */
assertMakeFile("f", 0644, "a");
/* Test1: archive it with .tar.Z suffix. */
assertEqualInt(0,
systemf("%s -acf test1.tar.Z f 2>test1.err", testprog));
assertEmptyFile("test1.err");
/* Check that the archive file has a compress signature. */
p = slurpfile(&s, "test1.tar.Z");
assert(s > 2);
failure("The archive should be compressed");
assertEqualMem(p, "\x1f\x9d", 2);
free(p);
/* Test2: archive it with .taZ suffix. */
assertEqualInt(0,
systemf("%s -acf test2.taZ f 2>test2.err", testprog));
assertEmptyFile("test2.err");
/* Check that the archive file has a compress signature. */
p = slurpfile(&s, "test2.taZ");
assert(s > 2);
failure("The archive should be compressed");
assertEqualMem(p, "\x1f\x9d", 2);
free(p);
/* Test3: archive it with .tar.Z.uu suffix. */
assertEqualInt(0,
systemf("%s -acf test3.tar.Z.uu f 2>test3.err", testprog));
assertEmptyFile("test3.err");
/* Check that the archive file has a compress signature. */
p = slurpfile(&s, "test3.tar.Z.uu");
assert(s > 12);
failure("The archive should be uuencoded");
assertEqualMem(p, "begin 644 -\n", 12);
free(p);
/* Test4: archive it with .zip suffix. */
assertEqualInt(0,
systemf("%s -acf test4.zip f 2>test4.err", testprog));
assertEmptyFile("test4.err");
/* Check that the archive file has a compress signature. */
p = slurpfile(&s, "test4.zip");
assert(s > 4);
failure("The archive should be zipped");
assertEqualMem(p, "\x50\x4b\x03\x04", 4);
free(p);
/* Test5: archive it with .tar.Z suffix and --uuencode option. */
assertEqualInt(0,
systemf("%s -acf test5.tar.Z --uuencode f 2>test5.err",
testprog));
assertEmptyFile("test5.err");
/* Check that the archive file has a compress signature. */
p = slurpfile(&s, "test5.tar.Z");
assert(s > 2);
failure("The archive should be compressed, ignoring --uuencode option");
assertEqualMem(p, "\x1f\x9d", 2);
free(p);
/* Test6: archive it with .xxx suffix(unknown suffix) and
* --uuencode option. */
assertEqualInt(0,
systemf("%s -acf test6.xxx --uuencode f 2>test6.err",
testprog));
assertEmptyFile("test6.err");
/* Check that the archive file has a compress signature. */
p = slurpfile(&s, "test6.xxx");
assert(s > 12);
failure("The archive should be uuencoded");
assertEqualMem(p, "begin 644 -\n", 12);
free(p);
/* Test7: archive it with .tar.Z suffix using a long-name option. */
assertEqualInt(0,
systemf("%s --auto-compress -cf test7.tar.Z f 2>test7.err",
testprog));
assertEmptyFile("test7.err");
/* Check that the archive file has a compress signature. */
p = slurpfile(&s, "test7.tar.Z");
assert(s > 2);
failure("The archive should be compressed");
assertEqualMem(p, "\x1f\x9d", 2);
free(p);
}

View file

@ -0,0 +1,512 @@
/*-
* Copyright (c) 2017 Martin Matuska
* 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$");
#if ARCHIVE_ACL_FREEBSD || ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_LIBACL
static const acl_perm_t acl_perms[] = {
#if ARCHIVE_ACL_DARWIN
ACL_READ_DATA,
ACL_LIST_DIRECTORY,
ACL_WRITE_DATA,
ACL_ADD_FILE,
ACL_EXECUTE,
ACL_SEARCH,
ACL_DELETE,
ACL_APPEND_DATA,
ACL_ADD_SUBDIRECTORY,
ACL_DELETE_CHILD,
ACL_READ_ATTRIBUTES,
ACL_WRITE_ATTRIBUTES,
ACL_READ_EXTATTRIBUTES,
ACL_WRITE_EXTATTRIBUTES,
ACL_READ_SECURITY,
ACL_WRITE_SECURITY,
ACL_CHANGE_OWNER,
ACL_SYNCHRONIZE
#else /* !ARCHIVE_ACL_DARWIN */
ACL_EXECUTE,
ACL_WRITE,
ACL_READ,
#if ARCHIVE_ACL_FREEBSD_NFS4
ACL_READ_DATA,
ACL_LIST_DIRECTORY,
ACL_WRITE_DATA,
ACL_ADD_FILE,
ACL_APPEND_DATA,
ACL_ADD_SUBDIRECTORY,
ACL_READ_NAMED_ATTRS,
ACL_WRITE_NAMED_ATTRS,
ACL_DELETE_CHILD,
ACL_READ_ATTRIBUTES,
ACL_WRITE_ATTRIBUTES,
ACL_DELETE,
ACL_READ_ACL,
ACL_WRITE_ACL,
ACL_WRITE_OWNER,
ACL_SYNCHRONIZE
#endif /* ARCHIVE_ACL_FREEBSD_NFS4 */
#endif /* !ARCHIVE_ACL_DARWIN */
};
#if ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_FREEBSD_NFS4
static const acl_flag_t acl_flags[] = {
#if ARCHIVE_ACL_DARWIN
ACL_ENTRY_INHERITED,
ACL_ENTRY_FILE_INHERIT,
ACL_ENTRY_DIRECTORY_INHERIT,
ACL_ENTRY_LIMIT_INHERIT,
ACL_ENTRY_ONLY_INHERIT
#else /* ARCHIVE_ACL_FREEBSD_NFS4 */
ACL_ENTRY_FILE_INHERIT,
ACL_ENTRY_DIRECTORY_INHERIT,
ACL_ENTRY_NO_PROPAGATE_INHERIT,
ACL_ENTRY_INHERIT_ONLY,
ACL_ENTRY_SUCCESSFUL_ACCESS,
ACL_ENTRY_FAILED_ACCESS,
#ifdef ACL_ENTRY_INHERITED
ACL_ENTRY_INHERITED
#endif
#endif /* ARCHIVE_ACL_FREEBSD_NFS4 */
};
#endif /* ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_FREEBSD_NFS4 */
/*
* Compare two ACL entries on FreeBSD or on Mac OS X
*/
static int
compare_acl_entry(acl_entry_t ae_a, acl_entry_t ae_b, int is_nfs4)
{
acl_tag_t tag_a, tag_b;
acl_permset_t permset_a, permset_b;
int perm_a, perm_b, perm_start, perm_end;
void *qual_a, *qual_b;
#if ARCHIVE_ACL_FREEBSD_NFS4
acl_entry_type_t type_a, type_b;
#endif
#if ARCHIVE_ACL_FREEBSD_NFS4 || ARCHIVE_ACL_DARWIN
acl_flagset_t flagset_a, flagset_b;
int flag_a, flag_b;
#endif
int i, r;
/* Compare ACL tag */
r = acl_get_tag_type(ae_a, &tag_a);
failure("acl_get_tag_type() error: %s", strerror(errno));
if (assertEqualInt(r, 0) == 0)
return (-1);
r = acl_get_tag_type(ae_b, &tag_b);
failure("acl_get_tag_type() error: %s", strerror(errno));
if (assertEqualInt(r, 0) == 0)
return (-1);
if (tag_a != tag_b)
return (0);
/* Compare ACL qualifier */
#if ARCHIVE_ACL_DARWIN
if (tag_a == ACL_EXTENDED_ALLOW || tag_b == ACL_EXTENDED_DENY)
#else
if (tag_a == ACL_USER || tag_a == ACL_GROUP)
#endif
{
qual_a = acl_get_qualifier(ae_a);
failure("acl_get_qualifier() error: %s", strerror(errno));
if (assert(qual_a != NULL) == 0)
return (-1);
qual_b = acl_get_qualifier(ae_b);
failure("acl_get_qualifier() error: %s", strerror(errno));
if (assert(qual_b != NULL) == 0) {
acl_free(qual_a);
return (-1);
}
#if ARCHIVE_ACL_DARWIN
if (memcmp(((guid_t *)qual_a)->g_guid,
((guid_t *)qual_b)->g_guid, KAUTH_GUID_SIZE) != 0)
#else
if ((tag_a == ACL_USER &&
(*(uid_t *)qual_a != *(uid_t *)qual_b)) ||
(tag_a == ACL_GROUP &&
(*(gid_t *)qual_a != *(gid_t *)qual_b)))
#endif
{
acl_free(qual_a);
acl_free(qual_b);
return (0);
}
acl_free(qual_a);
acl_free(qual_b);
}
#if ARCHIVE_ACL_FREEBSD_NFS4
if (is_nfs4) {
/* Compare NFS4 ACL type */
r = acl_get_entry_type_np(ae_a, &type_a);
failure("acl_get_entry_type_np() error: %s", strerror(errno));
if (assertEqualInt(r, 0) == 0)
return (-1);
r = acl_get_entry_type_np(ae_b, &type_b);
failure("acl_get_entry_type_np() error: %s", strerror(errno));
if (assertEqualInt(r, 0) == 0)
return (-1);
if (type_a != type_b)
return (0);
}
#endif
/* Compare ACL perms */
r = acl_get_permset(ae_a, &permset_a);
failure("acl_get_permset() error: %s", strerror(errno));
if (assertEqualInt(r, 0) == 0)
return (-1);
r = acl_get_permset(ae_b, &permset_b);
failure("acl_get_permset() error: %s", strerror(errno));
if (assertEqualInt(r, 0) == 0)
return (-1);
perm_start = 0;
perm_end = (int)(sizeof(acl_perms) / sizeof(acl_perms[0]));
#if ARCHIVE_ACL_FREEBSD_NFS4
if (is_nfs4)
perm_start = 3;
else
perm_end = 3;
#endif
/* Cycle through all perms and compare their value */
for (i = perm_start; i < perm_end; i++) {
#if ARCHIVE_ACL_LIBACL
perm_a = acl_get_perm(permset_a, acl_perms[i]);
perm_b = acl_get_perm(permset_b, acl_perms[i]);
#else
perm_a = acl_get_perm_np(permset_a, acl_perms[i]);
perm_b = acl_get_perm_np(permset_b, acl_perms[i]);
#endif
if (perm_a == -1 || perm_b == -1)
return (-1);
if (perm_a != perm_b)
return (0);
}
#if ARCHIVE_ACL_FREEBSD_NFS4 || ARCHIVE_ACL_DARWIN
if (is_nfs4) {
r = acl_get_flagset_np(ae_a, &flagset_a);
failure("acl_get_flagset_np() error: %s", strerror(errno));
if (assertEqualInt(r, 0) == 0)
return (-1);
r = acl_get_flagset_np(ae_b, &flagset_b);
failure("acl_get_flagset_np() error: %s", strerror(errno));
if (assertEqualInt(r, 0) == 0)
return (-1);
/* Cycle through all flags and compare their status */
for (i = 0; i < (int)(sizeof(acl_flags) / sizeof(acl_flags[0]));
i++) {
flag_a = acl_get_flag_np(flagset_a, acl_flags[i]);
flag_b = acl_get_flag_np(flagset_b, acl_flags[i]);
if (flag_a == -1 || flag_b == -1)
return (-1);
if (flag_a != flag_b)
return (0);
}
}
#else /* ARCHIVE_ACL_FREEBSD_NFS4 || ARCHIVE_ACL_DARWIN */
(void)is_nfs4; /* UNUSED */
#endif
return (1);
}
#endif /* ARCHIVE_ACL_FREEBSD || ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_LIBACL */
#if ARCHIVE_ACL_SUPPORT
/*
* Clear default ACLs or inheritance flags
*/
static void
clear_inheritance_flags(const char *path, int type)
{
switch (type) {
case ARCHIVE_TEST_ACL_TYPE_POSIX1E:
#if ARCHIVE_ACL_POSIX1E
#if !ARCHIVE_ACL_SUNOS
acl_delete_def_file(path);
#else
/* Solaris */
setTestAcl(path);
#endif
#endif /* ARCHIVE_ACL_POSIX1E */
break;
case ARCHIVE_TEST_ACL_TYPE_NFS4:
#if ARCHIVE_ACL_NFS4
setTestAcl(path);
#endif
break;
default:
(void)path; /* UNUSED */
break;
}
}
static int
compare_acls(const char *path_a, const char *path_b)
{
int ret = 1;
int is_nfs4 = 0;
#if ARCHIVE_ACL_SUNOS
void *acl_a, *acl_b;
int aclcnt_a, aclcnt_b;
aclent_t *aclent_a, *aclent_b;
ace_t *ace_a, *ace_b;
int e;
#elif ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_FREEBSD || ARCHIVE_ACL_LIBACL
acl_t acl_a, acl_b;
acl_entry_t aclent_a, aclent_b;
int a, b, r;
#endif
#if ARCHIVE_ACL_LIBRICHACL
struct richacl *richacl_a, *richacl_b;
richacl_a = NULL;
richacl_b = NULL;
#endif
#if ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_FREEBSD || ARCHIVE_ACL_LIBACL || \
ARCHIVE_ACL_SUNOS
acl_a = NULL;
acl_b = NULL;
#endif
#if ARCHIVE_ACL_SUNOS
acl_a = sunacl_get(GETACL, &aclcnt_a, 0, path_a);
if (acl_a == NULL) {
#if ARCHIVE_ACL_SUNOS_NFS4
is_nfs4 = 1;
acl_a = sunacl_get(ACE_GETACL, &aclcnt_a, 0, path_a);
#endif
failure("acl_get() error: %s", strerror(errno));
if (assert(acl_a != NULL) == 0)
return (-1);
#if ARCHIVE_ACL_SUNOS_NFS4
acl_b = sunacl_get(ACE_GETACL, &aclcnt_b, 0, path_b);
#endif
} else
acl_b = sunacl_get(GETACL, &aclcnt_b, 0, path_b);
if (acl_b == NULL && (errno == ENOSYS || errno == ENOTSUP)) {
free(acl_a);
return (0);
}
failure("acl_get() error: %s", strerror(errno));
if (assert(acl_b != NULL) == 0) {
free(acl_a);
return (-1);
}
if (aclcnt_a != aclcnt_b) {
ret = 0;
goto exit_free;
}
for (e = 0; e < aclcnt_a; e++) {
if (!is_nfs4) {
aclent_a = &((aclent_t *)acl_a)[e];
aclent_b = &((aclent_t *)acl_b)[e];
if (aclent_a->a_type != aclent_b->a_type ||
aclent_a->a_id != aclent_b->a_id ||
aclent_a->a_perm != aclent_b->a_perm) {
ret = 0;
goto exit_free;
}
}
#if ARCHIVE_ACL_SUNOS_NFS4
else {
ace_a = &((ace_t *)acl_a)[e];
ace_b = &((ace_t *)acl_b)[e];
if (ace_a->a_who != ace_b->a_who ||
ace_a->a_access_mask != ace_b->a_access_mask ||
ace_a->a_flags != ace_b->a_flags ||
ace_a->a_type != ace_b->a_type) {
ret = 0;
goto exit_free;
}
}
#endif
}
#else /* !ARCHIVE_ACL_SUNOS */
#if ARCHIVE_ACL_LIBRICHACL
richacl_a = richacl_get_file(path_a);
#if !ARCHIVE_ACL_LIBACL
if (richacl_a == NULL &&
(errno == ENODATA || errno == ENOTSUP || errno == ENOSYS))
return (0);
failure("richacl_get_file() error: %s (%s)", path_a, strerror(errno));
if (assert(richacl_a != NULL) == 0)
return (-1);
#endif
if (richacl_a != NULL) {
richacl_b = richacl_get_file(path_b);
if (richacl_b == NULL &&
(errno == ENODATA || errno == ENOTSUP || errno == ENOSYS)) {
richacl_free(richacl_a);
return (0);
}
failure("richacl_get_file() error: %s (%s)", path_b,
strerror(errno));
if (assert(richacl_b != NULL) == 0) {
richacl_free(richacl_a);
return (-1);
}
if (richacl_compare(richacl_a, richacl_b) == 0)
ret = 0;
richacl_free(richacl_a);
richacl_free(richacl_b);
return (ret);
}
#endif /* ARCHIVE_ACL_LIBRICHACL */
#if ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_FREEBSD || ARCHIVE_ACL_LIBACL
#if ARCHIVE_ACL_DARWIN
is_nfs4 = 1;
acl_a = acl_get_file(path_a, ACL_TYPE_EXTENDED);
#elif ARCHIVE_ACL_FREEBSD_NFS4
acl_a = acl_get_file(path_a, ACL_TYPE_NFS4);
if (acl_a != NULL)
is_nfs4 = 1;
#endif
if (acl_a == NULL)
acl_a = acl_get_file(path_a, ACL_TYPE_ACCESS);
failure("acl_get_file() error: %s (%s)", path_a, strerror(errno));
if (assert(acl_a != NULL) == 0)
return (-1);
#if ARCHIVE_ACL_DARWIN
acl_b = acl_get_file(path_b, ACL_TYPE_EXTENDED);
#elif ARCHIVE_ACL_FREEBSD_NFS4
acl_b = acl_get_file(path_b, ACL_TYPE_NFS4);
#endif
#if !ARCHIVE_ACL_DARWIN
if (acl_b == NULL) {
#if ARCHIVE_ACL_FREEBSD_NFS4
if (is_nfs4) {
acl_free(acl_a);
return (0);
}
#endif
acl_b = acl_get_file(path_b, ACL_TYPE_ACCESS);
}
failure("acl_get_file() error: %s (%s)", path_b, strerror(errno));
if (assert(acl_b != NULL) == 0) {
acl_free(acl_a);
return (-1);
}
#endif
a = acl_get_entry(acl_a, ACL_FIRST_ENTRY, &aclent_a);
if (a == -1) {
ret = 0;
goto exit_free;
}
b = acl_get_entry(acl_b, ACL_FIRST_ENTRY, &aclent_b);
if (b == -1) {
ret = 0;
goto exit_free;
}
#if ARCHIVE_ACL_DARWIN
while (a == 0 && b == 0)
#else /* FreeBSD, Linux */
while (a == 1 && b == 1)
#endif
{
r = compare_acl_entry(aclent_a, aclent_b, is_nfs4);
if (r != 1) {
ret = r;
goto exit_free;
}
a = acl_get_entry(acl_a, ACL_NEXT_ENTRY, &aclent_a);
b = acl_get_entry(acl_b, ACL_NEXT_ENTRY, &aclent_b);
}
/* Entry count must match */
if (a != b)
ret = 0;
#endif /* ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_FREEBSD || ARCHIVE_ACL_LIBACL */
#endif /* !ARCHIVE_ACL_SUNOS */
exit_free:
#if ARCHIVE_ACL_SUNOS
free(acl_a);
free(acl_b);
#else
acl_free(acl_a);
acl_free(acl_b);
#endif
return (ret);
}
#endif /* ARCHIVE_ACL_SUPPORT */
DEFINE_TEST(test_option_acls)
{
#if !ARCHIVE_ACL_SUPPORT
skipping("ACLs are not supported on this platform");
#else /* ARCHIVE_ACL_SUPPORT */
int acltype, r;
assertMakeFile("f", 0644, "a");
acltype = setTestAcl("f");
if (acltype == 0) {
skipping("Can't write ACLs on the filesystem");
return;
}
/* Archive it with acls */
r = systemf("%s -c --no-mac-metadata --acls -f acls.tar f >acls.out 2>acls.err", testprog);
assertEqualInt(r, 0);
/* Archive it without acls */
r = systemf("%s -c --no-mac-metadata --no-acls -f noacls.tar f >noacls.out 2>noacls.err", testprog);
assertEqualInt(r, 0);
/* Extract acls with acls */
assertMakeDir("acls_acls", 0755);
clear_inheritance_flags("acls_acls", acltype);
r = systemf("%s -x -C acls_acls --no-same-permissions --acls -f acls.tar >acls_acls.out 2>acls_acls.err", testprog);
assertEqualInt(r, 0);
r = compare_acls("f", "acls_acls/f");
assertEqualInt(r, 1);
/* Extract acls without acls */
assertMakeDir("acls_noacls", 0755);
clear_inheritance_flags("acls_noacls", acltype);
r = systemf("%s -x -C acls_noacls -p --no-acls -f acls.tar >acls_noacls.out 2>acls_noacls.err", testprog);
assertEqualInt(r, 0);
r = compare_acls("f", "acls_noacls/f");
assertEqualInt(r, 0);
/* Extract noacls with acls flag */
assertMakeDir("noacls_acls", 0755);
clear_inheritance_flags("noacls_acls", acltype);
r = systemf("%s -x -C noacls_acls --no-same-permissions --acls -f noacls.tar >noacls_acls.out 2>noacls_acls.err", testprog);
assertEqualInt(r, 0);
r = compare_acls("f", "noacls_acls/f");
assertEqualInt(r, 0);
/* Extract noacls with noacls */
assertMakeDir("noacls_noacls", 0755);
clear_inheritance_flags("noacls_noacls", acltype);
r = systemf("%s -x -C noacls_noacls -p --no-acls -f noacls.tar >noacls_noacls.out 2>noacls_noacls.err", testprog);
assertEqualInt(r, 0);
r = compare_acls("f", "noacls_noacls/f");
assertEqualInt(r, 0);
#endif /* ARCHIVE_ACL_SUPPORT */
}

View file

@ -0,0 +1,83 @@
/*-
* Copyright (c) 2010 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 USTAR_OPT " --format=ustar"
DEFINE_TEST(test_option_b)
{
char *testprog_ustar;
assertMakeFile("file1", 0644, "file1");
if (systemf("cat file1 > test_cat.out 2> test_cat.err") != 0) {
skipping("This test requires a `cat` program");
return;
}
testprog_ustar = malloc(strlen(testprog) + sizeof(USTAR_OPT) + 1);
strcpy(testprog_ustar, testprog);
strcat(testprog_ustar, USTAR_OPT);
/*
* Bsdtar does not pad if the output is going directly to a disk file.
*/
assertEqualInt(0, systemf("%s -cf archive1.tar file1 >test1.out 2>test1.err", testprog_ustar));
failure("bsdtar does not pad archives written directly to regular files");
assertFileSize("archive1.tar", 2048);
assertEmptyFile("test1.out");
assertEmptyFile("test1.err");
/*
* Bsdtar does pad to the block size if the output is going to a socket.
*/
/* Default is -b 20 */
assertEqualInt(0, systemf("%s -cf - file1 2>test2.err | cat >archive2.tar ", testprog_ustar));
failure("bsdtar does pad archives written to pipes");
assertFileSize("archive2.tar", 10240);
assertEmptyFile("test2.err");
assertEqualInt(0, systemf("%s -cf - -b 20 file1 2>test3.err | cat >archive3.tar ", testprog_ustar));
assertFileSize("archive3.tar", 10240);
assertEmptyFile("test3.err");
assertEqualInt(0, systemf("%s -cf - -b 10 file1 2>test4.err | cat >archive4.tar ", testprog_ustar));
assertFileSize("archive4.tar", 5120);
assertEmptyFile("test4.err");
assertEqualInt(0, systemf("%s -cf - -b 1 file1 2>test5.err | cat >archive5.tar ", testprog_ustar));
assertFileSize("archive5.tar", 2048);
assertEmptyFile("test5.err");
assertEqualInt(0, systemf("%s -cf - -b 8192 file1 2>test6.err | cat >archive6.tar ", testprog_ustar));
assertFileSize("archive6.tar", 4194304);
assertEmptyFile("test6.err");
/*
* Note: It's not possible to verify at this level that blocks
* are getting written with the
*/
free(testprog_ustar);
}

View file

@ -0,0 +1,56 @@
/*-
* 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_b64encode)
{
char *p;
size_t s;
/* Create a file. */
assertMakeFile("f", 0644, "a");
/* Archive it with compress compression and uuencode. */
assertEqualInt(0,
systemf("%s -cf - -Z --b64encode f >archive.out 2>archive.err",
testprog));
/* Check that the archive file has an uuencode signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "begin-base64 644", 16);
free(p);
/* Archive it with uuencode only. */
assertEqualInt(0,
systemf("%s -cf - --b64encode f >archive.out 2>archive.err",
testprog));
/* Check that the archive file has an uuencode signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "begin-base64 644", 16);
free(p);
}

View file

@ -0,0 +1,142 @@
/*-
* Copyright (c) 2010 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_option_exclude)
{
int r;
assertMakeFile("file1", 0644, "file1");
assertMakeFile("file2", 0644, "file2");
assertEqualInt(0, systemf("%s -cf archive.tar file1 file2", testprog));
/*
* Now, try extracting from the test archive with various --exclude options.
*/
/* Test 1: Without --exclude */
assertMakeDir("test1", 0755);
assertChdir("test1");
assertEqualInt(0,
systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog));
assertFileContents("file1", 5, "file1");
assertFileContents("file2", 5, "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 2: Selecting just one file */
assertMakeDir("test2", 0755);
assertChdir("test2");
assertEqualInt(0,
systemf("%s -xf ../archive.tar file1 >test.out 2>test.err", testprog));
assertFileContents("file1", 5, "file1");
assertFileNotExists("file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 3: Use --exclude to skip one file */
assertMakeDir("test3", 0755);
assertChdir("test3");
assertEqualInt(0,
systemf("%s -xf ../archive.tar --exclude file1 >test.out 2>test.err", testprog));
assertFileNotExists("file1");
assertFileContents("file2", 5, "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 4: Selecting one valid and one invalid file */
assertMakeDir("test4", 0755);
assertChdir("test4");
r = systemf("%s -xf ../archive.tar file1 file3 >test.out 2>test.err", testprog);
assert(r != 0);
assertFileContents("file1", 5, "file1");
assertFileNotExists("file2");
assertFileNotExists("file3");
assertEmptyFile("test.out");
assertNonEmptyFile("test.err");
assertChdir("..");
/* Test 5: Selecting one valid file twice */
assertMakeDir("test5", 0755);
assertChdir("test5");
assertEqualInt(0,
systemf("%s -xf ../archive.tar file1 file1 >test.out 2>test.err", testprog));
assertFileContents("file1", 5, "file1");
assertFileNotExists("file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 6: Include and exclude the same file */
assertMakeDir("test6", 0755);
assertChdir("test6");
assertEqualInt(0,
systemf("%s -xf ../archive.tar --exclude file1 file1 >test.out 2>test.err", testprog));
assertFileNotExists("file1");
assertFileNotExists("file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 7: Exclude a non-existent file */
assertMakeDir("test7", 0755);
assertChdir("test7");
assertEqualInt(0,
systemf("%s -xf ../archive.tar --exclude file3 file1 >test.out 2>test.err", testprog));
assertFileContents("file1", 5, "file1");
assertFileNotExists("file2");
assertFileNotExists("file3");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 8: Include a non-existent file */
assertMakeDir("test8", 0755);
assertChdir("test8");
r = systemf("%s -xf ../archive.tar file3 >test.out 2>test.err", testprog);
assert(r != 0);
assertFileNotExists("file1");
assertFileNotExists("file2");
assertFileNotExists("file3");
assertEmptyFile("test.out");
assertNonEmptyFile("test.err");
assertChdir("..");
/* Test 9: Include a non-existent file plus an exclusion */
assertMakeDir("test9", 0755);
assertChdir("test9");
r = systemf("%s -xf ../archive.tar --exclude file1 file3 >test.out 2>test.err", testprog);
assert(r != 0);
assertFileNotExists("file1");
assertFileNotExists("file2");
assertFileNotExists("file3");
assertEmptyFile("test.out");
assertNonEmptyFile("test.err");
assertChdir("..");
}

View file

@ -0,0 +1,230 @@
/*-
* Copyright (c) 2019 Martin Matuska
* 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_exclude_vcs)
{
assertMakeDir("in", 0755);
assertChdir("in");
assertMakeFile("file", 0644, "");
assertMakeDir("dir", 0755);
assertMakeDir("CVS", 0755);
assertMakeFile("CVS/fileattr", 0644, "");
assertMakeFile(".cvsignore", 0644, "");
assertMakeDir("RCS", 0755);
assertMakeFile("RCS/somefile", 0655, "");
assertMakeDir("SCCS", 0755);
assertMakeFile("SCCS/somefile", 0655, "");
assertMakeDir(".svn", 0755);
assertMakeFile(".svn/format", 0655, "");
assertMakeDir(".git", 0755);
assertMakeFile(".git/config", 0655, "");
assertMakeFile(".gitignore", 0644, "");
assertMakeFile(".gitattributes", 0644, "");
assertMakeFile(".gitmodules", 0644, "");
assertMakeDir(".arch-ids", 0755);
assertMakeFile(".arch-ids/somefile", 0644, "");
assertMakeDir("{arch}", 0755);
assertMakeFile("{arch}/somefile", 0644, "");
assertMakeFile("=RELEASE-ID", 0644, "");
assertMakeFile("=meta-update", 0644, "");
assertMakeFile("=update", 0644, "");
assertMakeDir(".bzr", 0755);
assertMakeDir(".bzr/checkout", 0755);
assertMakeFile(".bzrignore", 0644, "");
assertMakeFile(".bzrtags", 0644, "");
assertMakeDir(".hg", 0755);
assertMakeFile(".hg/dirstate", 0644, "");
assertMakeFile(".hgignore", 0644, "");
assertMakeFile(".hgtags", 0644, "");
assertMakeDir("_darcs", 0755);
assertMakeFile("_darcs/format", 0644, "");
assertChdir("..");
assertEqualInt(0, systemf("%s -c -C in -f included.tar .", testprog));
assertEqualInt(0,
systemf("%s -c --exclude-vcs -C in -f excluded.tar .", testprog));
/* No flags, archive with vcs files */
assertMakeDir("vcs-noexclude", 0755);
assertEqualInt(0, systemf("%s -x -C vcs-noexclude -f included.tar",
testprog));
assertChdir("vcs-noexclude");
assertFileExists("file");
assertIsDir("dir", 0755);
assertIsDir("CVS", 0755);
assertFileExists("CVS/fileattr");
assertFileExists(".cvsignore");
assertIsDir("RCS", 0755);
assertFileExists("RCS/somefile");
assertIsDir("SCCS", 0755);
assertFileExists("SCCS/somefile");
assertIsDir(".svn", 0755);
assertFileExists(".svn/format");
assertIsDir(".git", 0755);
assertFileExists(".git/config");
assertFileExists(".gitignore");
assertFileExists(".gitattributes");
assertFileExists(".gitmodules");
assertIsDir(".arch-ids", 0755);
assertFileExists(".arch-ids/somefile");
assertIsDir("{arch}", 0755);
assertFileExists("{arch}/somefile");
assertFileExists("=RELEASE-ID");
assertFileExists("=meta-update");
assertFileExists("=update");
assertIsDir(".bzr", 0755);
assertIsDir(".bzr/checkout", 0755);
assertFileExists(".bzrignore");
assertFileExists(".bzrtags");
assertIsDir(".hg", 0755);
assertFileExists(".hg/dirstate");
assertFileExists(".hgignore");
assertFileExists(".hgtags");
assertIsDir("_darcs", 0755);
assertFileExists("_darcs/format");
assertChdir("..");
/* --exclude-vcs, archive with vcs files */
assertMakeDir("vcs-exclude", 0755);
assertEqualInt(0,
systemf("%s -x --exclude-vcs -C vcs-exclude -f included.tar", testprog));
assertChdir("vcs-exclude");
assertFileExists("file");
assertIsDir("dir", 0755);
assertFileNotExists("CVS");
assertFileNotExists("CVS/fileattr");
assertFileNotExists(".cvsignore");
assertFileNotExists("RCS");
assertFileNotExists("RCS/somefile");
assertFileNotExists("SCCS");
assertFileNotExists("SCCS/somefile");
assertFileNotExists(".svn");
assertFileNotExists(".svn/format");
assertFileNotExists(".git");
assertFileNotExists(".git/config");
assertFileNotExists(".gitignore");
assertFileNotExists(".gitattributes");
assertFileNotExists(".gitmodules");
assertFileNotExists(".arch-ids");
assertFileNotExists(".arch-ids/somefile");
assertFileNotExists("{arch}");
assertFileNotExists("{arch}/somefile");
assertFileNotExists("=RELEASE-ID");
assertFileNotExists("=meta-update");
assertFileNotExists("=update");
assertFileNotExists(".bzr");
assertFileNotExists(".bzr/checkout");
assertFileNotExists(".bzrignore");
assertFileNotExists(".bzrtags");
assertFileNotExists(".hg");
assertFileNotExists(".hg/dirstate");
assertFileNotExists(".hgignore");
assertFileNotExists(".hgtags");
assertFileNotExists("_darcs");
assertFileNotExists("_darcs/format");
assertChdir("..");
/* --exclude-vcs, archive without vcs files */
assertMakeDir("novcs-exclude", 0755);
assertEqualInt(0,
systemf("%s -x --exclude-vcs -C novcs-exclude -f excluded.tar",
testprog));
assertChdir("novcs-exclude");
assertFileExists("file");
assertIsDir("dir", 0755);
assertFileNotExists("CVS");
assertFileNotExists("CVS/fileattr");
assertFileNotExists(".cvsignore");
assertFileNotExists("RCS");
assertFileNotExists("RCS/somefile");
assertFileNotExists("SCCS");
assertFileNotExists("SCCS/somefile");
assertFileNotExists(".svn");
assertFileNotExists(".svn/format");
assertFileNotExists(".git");
assertFileNotExists(".git/config");
assertFileNotExists(".gitignore");
assertFileNotExists(".gitattributes");
assertFileNotExists(".gitmodules");
assertFileNotExists(".arch-ids");
assertFileNotExists(".arch-ids/somefile");
assertFileNotExists("{arch}");
assertFileNotExists("{arch}/somefile");
assertFileNotExists("=RELEASE-ID");
assertFileNotExists("=meta-update");
assertFileNotExists("=update");
assertFileNotExists(".bzr");
assertFileNotExists(".bzr/checkout");
assertFileNotExists(".bzrignore");
assertFileNotExists(".bzrtags");
assertFileNotExists(".hg");
assertFileNotExists(".hg/dirstate");
assertFileNotExists(".hgignore");
assertFileNotExists(".hgtags");
assertFileNotExists("_darcs");
assertFileNotExists("_darcs/format");
assertChdir("..");
/* No flags, archive without vcs files */
assertMakeDir("novcs-noexclude", 0755);
assertEqualInt(0,
systemf("%s -x -C novcs-noexclude -f excluded.tar", testprog));
assertChdir("novcs-noexclude");
assertFileExists("file");
assertIsDir("dir", 0755);
assertFileNotExists("CVS");
assertFileNotExists("CVS/fileattr");
assertFileNotExists(".cvsignore");
assertFileNotExists("RCS");
assertFileNotExists("RCS/somefile");
assertFileNotExists("SCCS");
assertFileNotExists("SCCS/somefile");
assertFileNotExists(".svn");
assertFileNotExists(".svn/format");
assertFileNotExists(".git");
assertFileNotExists(".git/config");
assertFileNotExists(".gitignore");
assertFileNotExists(".gitattributes");
assertFileNotExists(".gitmodules");
assertFileNotExists(".arch-ids");
assertFileNotExists(".arch-ids/somefile");
assertFileNotExists("{arch}");
assertFileNotExists("{arch}/somefile");
assertFileNotExists("=RELEASE-ID");
assertFileNotExists("=meta-update");
assertFileNotExists("=update");
assertFileNotExists(".bzr");
assertFileNotExists(".bzr/checkout");
assertFileNotExists(".bzrignore");
assertFileNotExists(".bzrtags");
assertFileNotExists(".hg");
assertFileNotExists(".hg/dirstate");
assertFileNotExists(".hgignore");
assertFileNotExists(".hgtags");
assertFileNotExists("_darcs");
assertFileNotExists("_darcs/format");
}

View file

@ -0,0 +1,110 @@
/*-
* Copyright (c) 2017 Martin Matuska
* 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$");
#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__BORLANDC__)
#define chmod _chmod
#endif
static void
clear_fflags(const char *pathname)
{
#if defined(HAVE_STRUCT_STAT_ST_FLAGS)
chflags(pathname, 0);
#elif (defined(FS_IOC_GETFLAGS) && defined(HAVE_WORKING_FS_IOC_GETFLAGS)) || \
(defined(EXT2_IOC_GETFLAGS) && defined(HAVE_WORKING_EXT2_IOC_GETFLAGS))
int fd;
fd = open(pathname, O_RDONLY | O_NONBLOCK);
if (fd < 0)
return;
ioctl(fd,
#ifdef FS_IOC_GETFLAGS
FS_IOC_GETFLAGS,
#else
EXT2_IOC_GETFLAGS,
#endif
0);
#else
(void)pathname; /* UNUSED */
#endif
return;
}
DEFINE_TEST(test_option_fflags)
{
int r;
if (!canNodump()) {
skipping("Can't test nodump flag on this filesystem");
return;
}
/* Create a file. */
assertMakeFile("f", 0644, "a");
/* Set nodump flag on the file */
assertSetNodump("f");
/* FreeBSD ZFS workaround: ZFS sets uarch on all touched files and dirs */
chmod("f", 0644);
/* Archive it with fflags */
r = systemf("%s -c --fflags -f fflags.tar f >fflags.out 2>fflags.err", testprog);
assertEqualInt(r, 0);
/* Archive it without fflags */
r = systemf("%s -c --no-fflags -f nofflags.tar f >nofflags.out 2>nofflags.err", testprog);
assertEqualInt(r, 0);
/* Extract fflags with fflags */
assertMakeDir("fflags_fflags", 0755);
clear_fflags("fflags_fflags");
r = systemf("%s -x -C fflags_fflags --no-same-permissions --fflags -f fflags.tar >fflags_fflags.out 2>fflags_fflags.err", testprog);
assertEqualInt(r, 0);
assertEqualFflags("f", "fflags_fflags/f");
/* Extract fflags without fflags */
assertMakeDir("fflags_nofflags", 0755);
clear_fflags("fflags_nofflags");
r = systemf("%s -x -C fflags_nofflags -p --no-fflags -f fflags.tar >fflags_nofflags.out 2>fflags_nofflags.err", testprog);
assertEqualInt(r, 0);
assertUnequalFflags("f", "fflags_nofflags/f");
/* Extract nofflags with fflags */
assertMakeDir("nofflags_fflags", 0755);
clear_fflags("nofflags_fflags");
r = systemf("%s -x -C nofflags_fflags --no-same-permissions --fflags -f nofflags.tar >nofflags_fflags.out 2>nofflags_fflags.err", testprog);
assertEqualInt(r, 0);
assertUnequalFflags("f", "nofflags_fflags/f");
/* Extract nofflags with nofflags */
assertMakeDir("nofflags_nofflags", 0755);
clear_fflags("nofflags_nofflags");
r = systemf("%s -x -C nofflags_nofflags -p --no-fflags -f nofflags.tar >nofflags_nofflags.out 2>nofflags_nofflags.err", testprog);
assertEqualInt(r, 0);
assertUnequalFflags("f", "nofflags_nofflags/f");
}

View file

@ -0,0 +1,92 @@
/*-
* Copyright (c) 2003-2010 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_option_gid_gname)
{
char *reference, *data;
size_t s;
assertUmask(0);
assertMakeFile("file", 0644, "1234567890");
/* Create archive with no special options. */
failure("Error invoking %s c", testprog);
assertEqualInt(0,
systemf("%s cf archive1 --format=ustar file >stdout1.txt 2>stderr1.txt",
testprog));
assertEmptyFile("stdout1.txt");
assertEmptyFile("stderr1.txt");
reference = slurpfile(&s, "archive1");
/* Again with both --gid and --gname */
failure("Error invoking %s c", testprog);
assertEqualInt(0,
systemf("%s cf archive2 --gid=17 --gname=foofoofoo --format=ustar file >stdout2.txt 2>stderr2.txt",
testprog));
assertEmptyFile("stdout2.txt");
assertEmptyFile("stderr2.txt");
data = slurpfile(&s, "archive2");
/* Should force gid and gname fields in ustar header. */
assertEqualMem(data + 116, "000021 \0", 8);
assertEqualMem(data + 297, "foofoofoo\0", 10);
free(data);
/* Again with just --gname */
failure("Error invoking %s c", testprog);
assertEqualInt(0,
systemf("%s cf archive4 --gname=foofoofoo --format=ustar file >stdout4.txt 2>stderr4.txt",
testprog));
assertEmptyFile("stdout4.txt");
assertEmptyFile("stderr4.txt");
data = slurpfile(&s, "archive4");
/* Gid should be unchanged from original reference. */
assertEqualMem(data + 116, reference + 116, 8);
assertEqualMem(data + 297, "foofoofoo\0", 10);
free(data);
free(reference);
/* Again with --gid and force gname to empty. */
failure("Error invoking %s c", testprog);
assertEqualInt(0,
systemf("%s cf archive3 --gid=17 --gname= --format=ustar file >stdout3.txt 2>stderr3.txt",
testprog));
assertEmptyFile("stdout3.txt");
assertEmptyFile("stderr3.txt");
data = slurpfile(&s, "archive3");
assertEqualMem(data + 116, "000021 \0", 8);
/* Gname field in ustar header should be empty. */
assertEqualMem(data + 297, "\0", 1);
free(data);
/* TODO: It would be nice to verify that --gid= by itself
* will look up the associated gname and use that, but
* that requires some system-specific code. */
/* TODO: It would be nice to verify that --gid= will
* leave the gname field blank if the specified gid
* isn't used on the local system. */
}

View file

@ -0,0 +1,55 @@
/*-
* 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_grzip)
{
char *p;
size_t s;
if (!canGrzip()) {
skipping("grzip is not supported on this platform");
return;
}
/* Create a file. */
assertMakeFile("f", 0644, "a");
/* Archive it with grzip compression. */
assertEqualInt(0,
systemf("%s -cf - --grzip f >archive.out 2>archive.err",
testprog));
p = slurpfile(&s, "archive.err");
p[s] = '\0';
free(p);
/* Check that the archive file has an grzip signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "GRZipII\x00\x02\x04:)", 12);
free(p);
}

View file

@ -0,0 +1,59 @@
/*-
* 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_j)
{
char *p;
int r;
size_t s;
/* Create a file. */
assertMakeFile("f", 0644, "a");
/* Archive it with bzip2 compression. */
r = systemf("%s -jcf archive.out f 2>archive.err", testprog);
p = slurpfile(&s, "archive.err");
p[s] = '\0';
if (r != 0) {
if (!canBzip2()) {
skipping("bzip2 is not supported on this platform");
goto done;
}
failure("-j option is broken");
assertEqualInt(r, 0);
goto done;
}
free(p);
assertEmptyFile("archive.err");
/* Check that the archive file has a bzip2 signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "BZh9", 4);
done:
free(p);
}

View file

@ -0,0 +1,107 @@
/*-
* Copyright (c) 2010 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_option_k)
{
/*
* Create an archive with a couple of different versions of the
* same file.
*/
assertMakeFile("foo", 0644, "foo1");
assertEqualInt(0, systemf("%s -cf archive.tar foo", testprog));
assertMakeFile("foo", 0644, "foo2");
assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog));
assertMakeFile("bar", 0644, "bar1");
assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog));
assertMakeFile("foo", 0644, "foo3");
assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog));
assertMakeFile("bar", 0644, "bar2");
assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog));
/*
* Now, try extracting from the test archive with various
* combinations of -k
*/
/* Test 1: No option */
assertMakeDir("test1", 0755);
assertChdir("test1");
assertEqualInt(0,
systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog));
assertFileContents("foo3", 4, "foo");
assertFileContents("bar2", 4, "bar");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 2: With -k, we should just get the first versions. */
assertMakeDir("test2", 0755);
assertChdir("test2");
assertEqualInt(0,
systemf("%s -xf ../archive.tar -k >test.out 2>test.err", testprog));
assertFileContents("foo1", 4, "foo");
assertFileContents("bar1", 4, "bar");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 3: Without -k, existing files should get overwritten */
assertMakeDir("test3", 0755);
assertChdir("test3");
assertMakeFile("bar", 0644, "bar0");
assertMakeFile("foo", 0644, "foo0");
assertEqualInt(0,
systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog));
assertFileContents("foo3", 4, "foo");
assertFileContents("bar2", 4, "bar");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 4: With -k, existing files should not get overwritten */
assertMakeDir("test4", 0755);
assertChdir("test4");
assertMakeFile("bar", 0644, "bar0");
assertMakeFile("foo", 0644, "foo0");
assertEqualInt(0,
systemf("%s -xf ../archive.tar -k >test.out 2>test.err", testprog));
assertFileContents("foo0", 4, "foo");
assertFileContents("bar0", 4, "bar");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
}

View file

@ -0,0 +1,56 @@
/*-
* Copyright (c) 2010 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_option_keep_newer_files)
{
const char *reffile = "test_option_keep_newer_files.tar.Z";
/* Reference file has one entry "file" with a very old timestamp. */
extract_reference_file(reffile);
/* Test 1: Without --keep-newer-files */
assertMakeDir("test1", 0755);
assertChdir("test1");
assertMakeFile("file", 0644, "new");
assertEqualInt(0,
systemf("%s -xf ../%s >test.out 2>test.err", testprog, reffile));
assertFileContents("old\n", 4, "file");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 2: With --keep-newer-files */
assertMakeDir("test2", 0755);
assertChdir("test2");
assertMakeFile("file", 0644, "new");
assertEqualInt(0,
systemf("%s -xf ../%s --keep-newer-files >test.out 2>test.err", testprog, reffile));
assertFileContents("new", 3, "file");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
}

View file

@ -0,0 +1,7 @@
begin 644 test_option_keep_newer_files.tar.Z
M'YV09M*P*0.@H,&#"!,J7,BPH<.'$!'"F&B#!@T0`";&N%$#!D:-'#UFG$BR
MY$48,F38F&$CY8P8)V/$F,$2``@8$7/JW,FS)X`Z<^B$D3.23IHV/AD:19I4
M8<F)'Y]B;$JUJM6K6'V^84-&0=:O8,.*'4NVK-FS:-.J7<NVK=NW<./*G4NW
.KMV[>//JW<NWK]^_/0$`
`
end

View file

@ -0,0 +1,54 @@
/*-
* 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';
free(p);
/* Check that the archive file has an lzma signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "LRZI\x00", 5);
free(p);
}

View file

@ -0,0 +1,85 @@
/*-
* Copyright (c) 2014 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_lz4)
{
char *p;
int r;
size_t s;
/* Create a file. */
assertMakeFile("f", 0644, "a");
/* Archive it with lz4 compression. */
r = systemf("%s -cf - --lz4 f >archive.out 2>archive.err",
testprog);
p = slurpfile(&s, "archive.err");
p[s] = '\0';
if (r != 0) {
if (strstr(p, "Unsupported compression") != NULL) {
skipping("This version of bsdtar was compiled "
"without lz4 support");
goto done;
}
/* POSIX permits different handling of the spawnp
* system call used to launch the subsidiary
* program: */
/* Some systems fail immediately to spawn the new process. */
if (strstr(p, "Can't launch") != NULL && !canLz4()) {
skipping("This version of bsdtar uses an external lz4 program "
"but no such program is available on this system.");
goto done;
}
/* Some systems successfully spawn the new process,
* but fail to exec a program within that process.
* This results in failure at the first attempt to
* write. */
if (strstr(p, "Can't write") != NULL && !canLz4()) {
skipping("This version of bsdtar uses an external lz4 program "
"but no such program is available on this system.");
goto done;
}
/* On some systems the error won't be detected until closing
time, by a 127 exit error returned by waitpid. */
if (strstr(p, "Error closing") != NULL && !canLz4()) {
skipping("This version of bsdcpio uses an external lz4 program "
"but no such program is available on this system.");
return;
}
failure("--lz4 option is broken: %s", p);
assertEqualInt(r, 0);
goto done;
}
free(p);
/* Check that the archive file has an lz4 signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "\x04\x22\x4d\x18", 4);
done:
free(p);
}

View file

@ -0,0 +1,60 @@
/*-
* 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_lzma)
{
char *p;
int r;
size_t s;
/* Create a file. */
assertMakeFile("f", 0644, "a");
/* Archive it with lzma compression. */
r = systemf("%s -cf - --lzma f >archive.out 2>archive.err",
testprog);
p = slurpfile(&s, "archive.err");
p[s] = '\0';
if (r != 0) {
if (strstr(p, "Unsupported compression") != NULL) {
skipping("This version of bsdtar was compiled "
"without lzma support");
return;
}
failure("--lzma option is broken");
assertEqualInt(r, 0);
goto done;
}
free(p);
/* Check that the archive file has an lzma signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "\x5d\00\00", 3);
done:
free(p);
}

View file

@ -0,0 +1,58 @@
/*-
* 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_lzop)
{
char *p;
int r;
size_t s;
/* Create a file. */
assertMakeFile("f", 0644, "a");
/* Archive it with lzop compression. */
r = systemf("%s -cf - --lzop f >archive.out 2>archive.err", testprog);
p = slurpfile(&s, "archive.err");
p[s] = '\0';
if (r != 0) {
if (!canLzop()) {
skipping("lzop is not supported on this platform");
goto done;
}
failure("--lzop option is broken");
assertEqualInt(r, 0);
goto done;
}
free(p);
/* Check that the archive file has an lzma signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "\x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a", 9);
done:
free(p);
}

View file

@ -0,0 +1,142 @@
/*-
* Copyright (c) 2010 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$");
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
DEFINE_TEST(test_option_n)
{
int status;
assertMakeDir("d1", 0755);
assertMakeFile("d1/file1", 0644, "d1/file1");
/* Test 1: -c without -n */
assertMakeDir("test1", 0755);
assertChdir("test1");
assertEqualInt(0,
systemf("%s -cf archive.tar -C .. d1 >c.out 2>c.err", testprog));
assertEmptyFile("c.out");
assertEmptyFile("c.err");
assertEqualInt(0,
systemf("%s -xf archive.tar >x.out 2>x.err", testprog));
assertEmptyFile("x.out");
assertEmptyFile("x.err");
assertFileContents("d1/file1", 8, "d1/file1");
assertChdir("..");
/* Test 2: -c with -n */
assertMakeDir("test2", 0755);
assertChdir("test2");
assertEqualInt(0,
systemf("%s -cnf archive.tar -C .. d1 >c.out 2>c.err", testprog));
assertEmptyFile("c.out");
assertEmptyFile("c.err");
assertEqualInt(0,
systemf("%s -xf archive.tar >x.out 2>x.err", testprog));
assertEmptyFile("x.out");
assertEmptyFile("x.err");
assertIsDir("d1", umasked(0755));
assertFileNotExists("d1/file1");
assertChdir("..");
/*
* Create a test archive with the following content:
* d1/
* d1/file1
* d1/file2
* file3
* d2/file4
*
* Extracting uses the same code as listing and thus does not
* get tested separately. This also covers the
* archive_match_set_inclusion_recursion()
* API.
*/
assertMakeFile("d1/file2", 0644, "d1/file2");
assertMakeFile("file3", 0644, "file3");
assertMakeDir("d2", 0755);
assertMakeFile("d2/file4", 0644, "d2/file4");
assertEqualInt(0,
systemf("%s -cnf partial-archive.tar d1 d1/file1 d1/file2 file3 "
"d2/file4 >c.out 2>c.err", testprog));
/* Test 3: -t without other options */
assertEqualInt(0,
systemf("%s -tf partial-archive.tar >test3.out 2>test3.err",
testprog));
assertEmptyFile("test3.err");
assertTextFileContents("d1/\n"
"d1/file1\n"
"d1/file2\n"
"file3\n"
"d2/file4\n",
"test3.out");
/* Test 4: -t without -n and some entries selected */
assertEqualInt(0,
systemf("%s -tf partial-archive.tar d1 file3 d2/file4 "
">test4.out 2>test4.err", testprog));
assertEmptyFile("test4.err");
assertTextFileContents("d1/\n"
"d1/file1\n"
"d1/file2\n"
"file3\n"
"d2/file4\n",
"test4.out");
/* Test 5: -t with -n and some entries selected */
assertEqualInt(0,
systemf("%s -tnf partial-archive.tar d1 file3 d2/file4 "
">test5.out 2>test5.err", testprog));
assertEmptyFile("test5.err");
assertTextFileContents("d1/\n"
"file3\n"
"d2/file4\n",
"test5.out");
/* Test 6: -t without -n and non-existent directory selected */
assertEqualInt(0,
systemf("%s -tf partial-archive.tar d2 >test6.out 2>test6.err",
testprog));
assertEmptyFile("test6.err");
assertTextFileContents("d2/file4\n",
"test6.out");
/* Test 7: -t with -n and non-existent directory selected */
status = systemf("%s -tnf partial-archive.tar d2 "
">test7.out 2>test7.err", testprog);
assert(status);
assert(status != -1);
#if !defined(_WIN32) || defined(__CYGWIN__)
assert(WIFEXITED(status));
assertEqualInt(1, WEXITSTATUS(status));
#endif
assertNonEmptyFile("test7.err");
assertEmptyFile("test7.out");
}

View file

@ -0,0 +1,78 @@
/*-
* Copyright (c) 2010 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_option_newer_than)
{
struct stat st;
/*
* Basic test of --newer-than.
* First, create three files with different mtimes.
* Create test1.tar with --newer-than, test2.tar without.
*/
assertMakeDir("test1in", 0755);
assertChdir("test1in");
assertMakeDir("a", 0755);
assertMakeDir("a/b", 0755);
assertMakeFile("old.txt", 0644, "old.txt");
assertEqualInt(0, stat("old.txt", &st));
sleepUntilAfter(st.st_mtime);
assertMakeFile("middle.txt", 0644, "middle.txt");
assertEqualInt(0, stat("middle.txt", &st));
sleepUntilAfter(st.st_mtime);
assertMakeFile("new.txt", 0644, "new");
assertMakeFile("a/b/new.txt", 0644, "new file in old directory");
/* Test --newer-than on create */
assertEqualInt(0,
systemf("%s --format pax -cf ../test1.tar "
"--newer-than middle.txt *.txt a", testprog));
assertEqualInt(0,
systemf("%s --format pax -cf ../test2.tar *.txt a", testprog));
assertChdir("..");
/* Extract test1.tar to a clean dir and verify what got archived. */
assertMakeDir("test1out", 0755);
assertChdir("test1out");
assertEqualInt(0, systemf("%s xf ../test1.tar", testprog));
assertFileExists("new.txt");
assertFileExists("a/b/new.txt");
assertFileNotExists("middle.txt");
assertFileNotExists("old.txt");
assertChdir("..");
/* Extract test2.tar to a clean dir with --newer-than and verify. */
assertMakeDir("test2out", 0755);
assertChdir("test2out");
assertEqualInt(0, systemf("%s xf ../test2.tar --newer-than ../test1in/middle.txt", testprog));
assertFileExists("new.txt");
assertFileExists("a/b/new.txt");
assertFileNotExists("middle.txt");
assertFileNotExists("old.txt");
assertChdir("..");
}

View file

@ -0,0 +1,68 @@
/*-
* 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_nodump)
{
if (!canNodump()) {
skipping("Can't test nodump on this filesystem");
return;
}
assertMakeFile("file1", 0644, "file1");
assertMakeFile("file2", 0644, "file2");
assertMakeFile("file3", 0644, "file3");
assertSetNodump("file2");
/* Test 1: Without --nodump */
assertEqualInt(0, systemf("%s -cf test1.tar file1 file2 file3",
testprog));
assertMakeDir("test1", 0755);
assertChdir("test1");
assertEqualInt(0,
systemf("%s -xf ../test1.tar >test.out 2>test.err", testprog));
assertFileContents("file1", 5, "file1");
assertFileContents("file2", 5, "file2");
assertFileContents("file3", 5, "file3");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 2: With --nodump */
assertEqualInt(0, systemf("%s -cf test2.tar --nodump file1 file2 file3",
testprog));
assertMakeDir("test2", 0755);
assertChdir("test2");
assertEqualInt(0,
systemf("%s -xf ../test2.tar >test.out 2>test.err", testprog));
assertFileContents("file1", 5, "file1");
assertFileNotExists("file2");
assertFileContents("file3", 5, "file3");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
}

View file

@ -0,0 +1,85 @@
/*-
* Copyright (c) 2010 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_older_than)
{
struct stat st;
/*
* Basic test of --older-than.
* First, create three files with different mtimes.
* Create test1.tar with --older-than, test2.tar without.
*/
assertMakeDir("test1in", 0755);
assertChdir("test1in");
assertMakeDir("a", 0755);
assertMakeDir("a/b", 0755);
assertMakeFile("old.txt", 0644, "old.txt");
assertMakeFile("a/b/old.txt", 0644, "old file in old directory");
assertEqualInt(0, stat("old.txt", &st));
sleepUntilAfter(st.st_mtime);
assertMakeFile("middle.txt", 0644, "middle.txt");
assertEqualInt(0, stat("middle.txt", &st));
sleepUntilAfter(st.st_mtime);
assertMakeFile("new.txt", 0644, "new");
assertMakeFile("a/b/new.txt", 0644, "new file in old directory");
/* Test --older-than on create */
assertEqualInt(0,
systemf("%s --format pax -cf ../test1.tar "
"--older-than middle.txt *.txt a",
testprog));
assertEqualInt(0,
systemf("%s --format pax -cf ../test2.tar *.txt a",
testprog));
assertChdir("..");
/* Extract test1.tar to a clean dir and verify what got archived. */
assertMakeDir("test1out", 0755);
assertChdir("test1out");
assertEqualInt(0, systemf("%s xf ../test1.tar", testprog));
assertFileNotExists("new.txt");
assertFileNotExists("a/b/new.txt");
assertFileNotExists("middle.txt");
assertFileExists("old.txt");
assertFileExists("a/b/old.txt");
assertChdir("..");
/* Extract test2.tar to a clean dir with --older-than and verify. */
assertMakeDir("test2out", 0755);
assertChdir("test2out");
assertEqualInt(0,
systemf("%s xf ../test2.tar --older-than ../test1in/middle.txt",
testprog));
assertFileNotExists("new.txt");
assertFileNotExists("a/b/new.txt");
assertFileNotExists("middle.txt");
assertFileExists("old.txt");
assertFileExists("a/b/old.txt");
assertChdir("..");
}

View file

@ -0,0 +1,43 @@
/*-
* Copyright (c) 2014 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_passphrase)
{
const char *reffile = "test_option_passphrase.zip";
extract_reference_file(reffile);
failure("--passphrase option is broken");
assertEqualInt(0, systemf(
"%s --passphrase pass1 -xf %s >test.out 2>test.err",
testprog, reffile));
assertFileExists("file1");
assertTextFileContents("contents of file1.\n", "file1");
assertFileExists("file2");
assertTextFileContents("contents of file2.\n", "file2");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
}

View file

@ -0,0 +1,12 @@
begin 644 test_option_passphrase.zip
M4$L#!`H`"0```#B91$7D$C4,'P```!,````%`!P`9FEL93%55`D``VS'+U0"
MQR]4=7@+``$$]0$```04````BHPD*"^*I04=XKI\_FQ*TE+#),TD7TTKSP/7
MR6R35%!+!PCD$C4,'P```!,```!02P,$"@`)````09E$1;VL<PX?````$P``
M``4`'`!F:6QE,E54"0`#><<O5`+'+U1U>`L``03U`0``!!0```!D#6Z\@CI8
MV1GIJO5TISQF^I:7.;Y3<-G3$YOCL(C_4$L'"+VL<PX?````$P```%!+`0(>
M`PH`"0```#B91$7D$C4,'P```!,````%`!@```````$```"D@0````!F:6QE
M,554!0`#;,<O5'5X"P`!!/4!```$%````%!+`0(>`PH`"0```$&91$6]K',.
M'P```!,````%`!@```````$```"D@6X```!F:6QE,E54!0`#><<O5'5X"P`!
@!/4!```$%````%!+!08``````@`"`)8```#<````````
`
end

View file

@ -0,0 +1,113 @@
/*-
* Copyright (c) 2003-2007 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: src/usr.bin/tar/test/test_option_q.c,v 1.3 2008/08/22 01:35:08 kientzle Exp $");
DEFINE_TEST(test_option_q)
{
int r;
/*
* Create an archive with several different versions of the
* same files. By default, the last version will overwrite
* any earlier versions. The -q/--fast-read option will
* stop early, so we can verify -q/--fast-read by seeing
* which version of each file actually ended up being
* extracted. This also exercises -r mode, since that's
* what we use to build up the test archive.
*/
assertMakeFile("foo", 0644, "foo1");
assertEqualInt(0, systemf("%s -cf archive.tar foo", testprog));
assertMakeFile("foo", 0644, "foo2");
assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog));
assertMakeFile("bar", 0644, "bar1");
assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog));
assertMakeFile("foo", 0644, "foo3");
assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog));
assertMakeFile("bar", 0644, "bar2");
assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog));
/*
* Now, try extracting from the test archive with various
* combinations of -q.
*/
/* Test 1: -q foo should only extract the first foo. */
assertMakeDir("test1", 0755);
assertChdir("test1");
r = systemf("%s -xf ../archive.tar -q foo >test.out 2>test.err",
testprog);
failure("Fatal error trying to use -q option");
if (!assertEqualInt(0, r))
return;
assertFileContents("foo1", 4, "foo");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 2: -q foo bar should extract up to the first bar. */
assertMakeDir("test2", 0755);
assertChdir("test2");
assertEqualInt(0,
systemf("%s -xf ../archive.tar -q foo bar >test.out 2>test.err", testprog));
assertFileContents("foo2", 4, "foo");
assertFileContents("bar1", 4, "bar");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 3: Same as test 2, but use --fast-read spelling. */
assertMakeDir("test3", 0755);
assertChdir("test3");
assertEqualInt(0,
systemf("%s -xf ../archive.tar --fast-read foo bar >test.out 2>test.err", testprog));
assertFileContents("foo2", 4, "foo");
assertFileContents("bar1", 4, "bar");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
/* Test 4: Without -q, should extract everything. */
assertMakeDir("test4", 0755);
assertChdir("test4");
assertEqualInt(0,
systemf("%s -xf ../archive.tar foo bar >test.out 2>test.err", testprog));
assertFileContents("foo3", 4, "foo");
assertFileContents("bar2", 4, "bar");
assertEmptyFile("test.out");
assertEmptyFile("test.err");
assertChdir("..");
}

View file

@ -0,0 +1,133 @@
/*-
* Copyright (c) 2003-2007 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$");
/*
* Also see test_option_q for additional validation of -r support.
*/
DEFINE_TEST(test_option_r)
{
char *buff;
char *p0, *p1;
size_t buff_size = 35000;
size_t s, buff_size_rounded;
int r, i;
buff = NULL;
p0 = NULL;
p1 = NULL;
/* Create an archive with one file. */
assertMakeFile("f1", 0644, "abc");
r = systemf("%s cf archive.tar --format=ustar f1 >step1.out 2>step1.err", testprog);
failure("Error invoking %s cf archive.tar f1", testprog);
assertEqualInt(r, 0);
assertEmptyFile("step1.out");
assertEmptyFile("step1.err");
/* Do some basic validation of the constructed archive. */
p0 = slurpfile(&s, "archive.tar");
if (!assert(p0 != NULL))
goto done;
if (!assert(s >= 2048))
goto done;
assertEqualMem(p0 + 0, "f1", 3);
assertEqualMem(p0 + 512, "abc", 3);
assertEqualMem(p0 + 1024, "\0\0\0\0\0\0\0\0", 8);
assertEqualMem(p0 + 1536, "\0\0\0\0\0\0\0\0", 8);
/* Edit that file with a lot more data and update the archive with a new copy. */
buff = malloc(buff_size);
assert(buff != NULL);
if (buff == NULL)
goto done;
for (i = 0; i < (int)buff_size; ++i)
buff[i] = "abcdefghijklmnopqrstuvwxyz"[rand() % 26];
buff[buff_size - 1] = '\0';
assertMakeFile("f1", 0644, buff);
r = systemf("%s rf archive.tar --format=ustar f1 >step2.out 2>step2.err", testprog);
failure("Error invoking %s rf archive.tar f1", testprog);
assertEqualInt(r, 0);
assertEmptyFile("step2.out");
assertEmptyFile("step2.err");
/* The constructed archive should just have the new entry appended. */
p1 = slurpfile(&s, "archive.tar");
if (!assert(p1 != NULL))
goto done;
buff_size_rounded = ((buff_size + 511) / 512) * 512;
assert(s >= 2560 + buff_size_rounded);
/* Verify first entry is unchanged. */
assertEqualMem(p0, p1, 1024);
/* Verify that second entry is correct. */
assertEqualMem(p1 + 1024, "f1", 3);
assertEqualMem(p1 + 1536, buff, buff_size);
/* Verify end-of-archive marker. */
assertEqualMem(p1 + 1536 + buff_size_rounded, "\0\0\0\0\0\0\0\0", 8);
assertEqualMem(p1 + 2048 + buff_size_rounded, "\0\0\0\0\0\0\0\0", 8);
free(p0);
p0 = p1;
/* Update the archive by adding a different file. */
assertMakeFile("f2", 0644, "f2");
r = systemf("%s rf archive.tar --format=ustar f2 >step3.out 2>step3.err", testprog);
failure("Error invoking %s rf archive.tar f2", testprog);
assertEqualInt(r, 0);
assertEmptyFile("step3.out");
assertEmptyFile("step3.err");
/* Validate the constructed archive. */
p1 = slurpfile(&s, "archive.tar");
if (!assert(p1 != NULL))
goto done;
assert(s >= 3584 + buff_size_rounded);
/* Verify first two entries are unchanged. */
assertEqualMem(p0, p1, 1536 + buff_size_rounded);
/* Verify that new entry is correct. */
assertEqualMem(p1 + 1536 + buff_size_rounded, "f2", 3);
assertEqualMem(p1 + 2048 + buff_size_rounded, "f2", 3);
/* Verify end-of-archive marker. */
assertEqualMem(p1 + 2560 + buff_size_rounded, "\0\0\0\0\0\0\0\0", 8);
assertEqualMem(p1 + 3072 + buff_size_rounded, "\0\0\0\0\0\0\0\0", 8);
free(p1);
/* Unpack everything */
assertMakeDir("extract", 0775);
assertChdir("extract");
r = systemf("%s xf ../archive.tar >extract.out 2>extract.err", testprog);
failure("Error invoking %s xf archive.tar", testprog);
assertEqualInt(r, 0);
assertEmptyFile("extract.out");
assertEmptyFile("extract.err");
/* Verify that the second copy of f1 overwrote the first. */
assertFileContents(buff, (int)strlen(buff), "f1");
done:
free(buff);
free(p0);
}

View file

@ -0,0 +1,278 @@
/*-
* Copyright (c) 2003-2008 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: src/usr.bin/tar/test/test_option_T.c,v 1.3 2008/08/15 06:12:02 kientzle Exp $");
DEFINE_TEST(test_option_s)
{
struct stat st;
/* Create a sample file hierarchy. */
assertMakeDir("in", 0755);
assertMakeDir("in/d1", 0755);
assertMakeFile("in/d1/foo", 0644, "foo");
assertMakeFile("in/d1/bar", 0644, "bar");
if (canSymlink()) {
assertMakeFile("in/d1/realfile", 0644, "realfile");
assertMakeSymlink("in/d1/symlink", "realfile", 0);
}
assertMakeFile("in/d1/hardlink1", 0644, "hardlinkedfile");
assertMakeHardlink("in/d1/hardlink2", "in/d1/hardlink1");
/* Does tar support -s option ? */
systemf("%s -cf - -s /foo/bar/ in/d1/foo > NUL 2> check.err",
testprog);
assertEqualInt(0, stat("check.err", &st));
if (st.st_size != 0) {
skipping("%s does not support -s option on this platform",
testprog);
return;
}
/*
* Test 1: Filename substitution when creating archives.
*/
assertMakeDir("test1", 0755);
systemf("%s -cf test1_1.tar -s /foo/bar/ in/d1/foo", testprog);
systemf("%s -xf test1_1.tar -C test1", testprog);
assertFileContents("foo", 3, "test1/in/d1/bar");
systemf("%s -cf test1_2.tar -s /d1/d2/ in/d1/foo", testprog);
systemf("%s -xf test1_2.tar -C test1", testprog);
assertFileContents("foo", 3, "test1/in/d2/foo");
/*
* Test 2: Basic substitution when extracting archive.
*/
assertMakeDir("test2", 0755);
systemf("%s -cf test2.tar in/d1/foo", testprog);
systemf("%s -xf test2.tar -s /foo/bar/ -C test2", testprog);
assertFileContents("foo", 3, "test2/in/d1/bar");
/*
* Test 3: Files with empty names shouldn't be archived.
*/
systemf("%s -cf test3.tar -s ,in/d1/foo,, in/d1/foo", testprog);
systemf("%s -tvf test3.tar > in.lst", testprog);
assertEmptyFile("in.lst");
/*
* Test 4: Multiple substitutions when extracting archive.
*/
assertMakeDir("test4", 0755);
systemf("%s -cf test4.tar in/d1/foo in/d1/bar",
testprog);
systemf("%s -xf test4.tar -s /foo/bar/ -s }bar}baz} -C test4",
testprog);
assertFileContents("foo", 3, "test4/in/d1/bar");
assertFileContents("bar", 3, "test4/in/d1/baz");
/*
* Test 5: Name-switching substitutions when extracting archive.
*/
assertMakeDir("test5", 0755);
systemf("%s -cf test5.tar in/d1/foo in/d1/bar", testprog);
systemf("%s -xf test5.tar -s /foo/bar/ -s }bar}foo} -C test5", testprog);
assertFileContents("foo", 3, "test5/in/d1/bar");
assertFileContents("bar", 3, "test5/in/d1/foo");
/*
* Test 6: symlinks get renamed by default
*/
if (canSymlink()) {
/* At extraction time. */
assertMakeDir("test6a", 0755);
systemf("%s -cf - in/d1 | %s -xf - -s /d1/d2/ -C test6a",
testprog, testprog);
assertFileContents("realfile", 8, "test6a/in/d2/realfile");
assertFileContents("realfile", 8, "test6a/in/d2/symlink");
assertIsSymlink("test6a/in/d2/symlink", "realfile", 0);
/* At creation time. */
assertMakeDir("test6b", 0755);
systemf("%s -cf - -s /d1/d2/ in/d1 | %s -xf - -C test6b",
testprog, testprog);
assertFileContents("realfile", 8, "test6b/in/d2/realfile");
assertFileContents("realfile", 8, "test6b/in/d2/symlink");
assertIsSymlink("test6b/in/d2/symlink", "realfile", 0);
}
/*
* Test 7: selective renaming of symlink target
*/
if (canSymlink()) {
/* At extraction. */
assertMakeDir("test7a", 0755);
systemf("%s -cf - in/d1 | %s -xf - -s /realfile/realfile-renamed/ -C test7a",
testprog, testprog);
assertFileContents("realfile", 8, "test7a/in/d1/realfile-renamed");
assertFileContents("realfile", 8, "test7a/in/d1/symlink");
assertIsSymlink("test7a/in/d1/symlink", "realfile-renamed", 0);
/* At creation. */
assertMakeDir("test7b", 0755);
systemf("%s -cf - -s /realfile/realfile-renamed/ in/d1 | %s -xf - -C test7b",
testprog, testprog);
assertFileContents("realfile", 8, "test7b/in/d1/realfile-renamed");
assertFileContents("realfile", 8, "test7b/in/d1/symlink");
assertIsSymlink("test7b/in/d1/symlink", "realfile-renamed", 0);
}
/*
* Test 8: hardlinks get renamed by default
*/
/* At extraction time. */
assertMakeDir("test8a", 0755);
systemf("%s -cf test8a.tar in/d1", testprog);
systemf("%s -xf test8a.tar -s /d1/d2/ -C test8a", testprog);
assertIsHardlink("test8a/in/d2/hardlink1", "test8a/in/d2/hardlink2");
/* At creation time. */
assertMakeDir("test8b", 0755);
systemf("%s -cf test8b.tar -s /d1/d2/ in/d1", testprog);
systemf("%s -xf test8b.tar -C test8b", testprog);
assertIsHardlink("test8b/in/d2/hardlink1", "test8b/in/d2/hardlink2");
/*
* Test 9: selective renaming of hardlink target
*/
/* At extraction. (assuming hardlink2 is the hardlink entry) */
assertMakeDir("test9a", 0755);
systemf("%s -cf test9a.tar in/d1", testprog);
systemf("%s -xf test9a.tar -s /hardlink1/hardlink1-renamed/ -C test9a",
testprog);
assertIsHardlink("test9a/in/d1/hardlink1-renamed", "test9a/in/d1/hardlink2");
/* At extraction. (assuming hardlink1 is the hardlink entry) */
assertMakeDir("test9b", 0755);
systemf("%s -cf test9b.tar in/d1", testprog);
systemf("%s -xf test9b.tar -s /hardlink2/hardlink2-renamed/ -C test9b",
testprog);
assertIsHardlink("test9b/in/d1/hardlink1", "test9b/in/d1/hardlink2-renamed");
/* At creation. (assuming hardlink2 is the hardlink entry) */
assertMakeDir("test9c", 0755);
systemf("%s -cf test9c.tar -s /hardlink1/hardlink1-renamed/ in/d1",
testprog);
systemf("%s -xf test9c.tar -C test9c", testprog);
assertIsHardlink("test9c/in/d1/hardlink1-renamed", "test9c/in/d1/hardlink2");
/* At creation. (assuming hardlink1 is the hardlink entry) */
assertMakeDir("test9d", 0755);
systemf("%s -cf test9d.tar -s /hardlink2/hardlink2-renamed/ in/d1",
testprog);
systemf("%s -xf test9d.tar -C test9d", testprog);
assertIsHardlink("test9d/in/d1/hardlink1", "test9d/in/d1/hardlink2-renamed");
/*
* Test 10: renaming symlink target without repointing symlink
*/
if (canSymlink()) {
/* At extraction. */
assertMakeDir("test10a", 0755);
systemf("%s -cf - in/d1 | %s -xf - -s /realfile/foo/S -s /foo/realfile/ -C test10a",
testprog, testprog);
assertFileContents("realfile", 8, "test10a/in/d1/foo");
assertFileContents("foo", 3, "test10a/in/d1/realfile");
assertFileContents("foo", 3, "test10a/in/d1/symlink");
assertIsSymlink("test10a/in/d1/symlink", "realfile", 0);
/* At creation. */
assertMakeDir("test10b", 0755);
systemf("%s -cf - -s /realfile/foo/S -s /foo/realfile/ in/d1 | %s -xf - -C test10b",
testprog, testprog);
assertFileContents("realfile", 8, "test10b/in/d1/foo");
assertFileContents("foo", 3, "test10b/in/d1/realfile");
assertFileContents("foo", 3, "test10b/in/d1/symlink");
assertIsSymlink("test10b/in/d1/symlink", "realfile", 0);
}
/*
* Test 11: repointing symlink without renaming file
*/
if (canSymlink()) {
/* At extraction. */
assertMakeDir("test11a", 0755);
systemf("%s -cf - in/d1 | %s -xf - -s /realfile/foo/sR -C test11a",
testprog, testprog);
assertFileContents("foo", 3, "test11a/in/d1/foo");
assertFileContents("realfile", 8, "test11a/in/d1/realfile");
assertFileContents("foo", 3, "test11a/in/d1/symlink");
assertIsSymlink("test11a/in/d1/symlink", "foo", 0);
/* At creation. */
assertMakeDir("test11b", 0755);
systemf("%s -cf - -s /realfile/foo/R in/d1 | %s -xf - -C test11b",
testprog, testprog);
assertFileContents("foo", 3, "test11b/in/d1/foo");
assertFileContents("realfile", 8, "test11b/in/d1/realfile");
assertFileContents("foo", 3, "test11b/in/d1/symlink");
assertIsSymlink("test11b/in/d1/symlink", "foo", 0);
}
/*
* Test 12: renaming hardlink target without changing hardlink.
* (Requires a pre-built archive, since we otherwise can't know
* which element will be stored as the hardlink.)
*/
extract_reference_file("test_option_s.tar.Z");
assertMakeDir("test12a", 0755);
systemf("%s -xf test_option_s.tar.Z -s /hardlink1/foo/H -s /foo/hardlink1/ %s -C test12a",
testprog, canSymlink()?"":"--exclude in/d1/symlink");
assertFileContents("foo", 3, "test12a/in/d1/hardlink1");
assertFileContents("hardlinkedfile", 14, "test12a/in/d1/foo");
assertFileContents("foo", 3, "test12a/in/d1/hardlink2");
assertIsHardlink("test12a/in/d1/hardlink1", "test12a/in/d1/hardlink2");
/* TODO: Expand this test to verify creation as well.
* Since either hardlink1 or hardlink2 might get stored as a hardlink,
* this will either requiring testing both cases and accepting either
* pass, or some very creative renames that can be tested regardless.
*/
/*
* Test 13: repoint hardlink without changing files
* (Requires a pre-built archive, since we otherwise can't know
* which element will be stored as the hardlink.)
*/
extract_reference_file("test_option_s.tar.Z");
assertMakeDir("test13a", 0755);
systemf("%s -xf test_option_s.tar.Z -s /hardlink1/foo/Rh -s /foo/hardlink1/Rh %s -C test13a",
testprog, canSymlink()?"":"--exclude in/d1/symlink");
assertFileContents("foo", 3, "test13a/in/d1/foo");
assertFileContents("hardlinkedfile", 14, "test13a/in/d1/hardlink1");
assertFileContents("foo", 3, "test13a/in/d1/hardlink2");
assertIsHardlink("test13a/in/d1/foo", "test13a/in/d1/hardlink2");
/* TODO: See above; expand this test to verify renames at creation. */
/*
* Test 14: Global substitutions when extracting archive.
*/
/* Global substitution. */
assertMakeDir("test14", 0755);
systemf("%s -cf test14.tar in/d1/foo in/d1/bar",
testprog);
systemf("%s -xf test14.tar -s /o/z/g -s /bar/baz/ -C test14",
testprog);
assertFileContents("foo", 3, "test14/in/d1/fzz");
assertFileContents("bar", 3, "test14/in/d1/baz");
/* Singular substitution. */
systemf("%s -cf test14.tar in/d1/foo in/d1/bar",
testprog);
systemf("%s -xf test14.tar -s /o/z/ -s /bar/baz/ -C test14",
testprog);
assertFileContents("foo", 3, "test14/in/d1/fzo");
assertFileContents("bar", 3, "test14/in/d1/baz");
}

View file

@ -0,0 +1,16 @@
begin 644 test_option_s.tar.Z
M'YV0:=R\(!/C!8"#"!,J7,BPH<.'$"-*1`BCXHT:-4``J`CCAHV,&SG*H*&1
MHTF3(&+$^%@C!HT8,&C(``%#Y0T9,P"`J#&QI\^?0(,"J#.'3A@Y(>FD:2/4
M8=$P9LPT77@21LF3&J=JW<JUJU>A`0<6%'/TJ]FS"3G:H$$R9,>/5RN.C%L5
MQHR4*S&ZA"F39HR1=G7"0$NX<$*B1I%65,KTZ].H7JO2K9C5L.7+F+>219JY
ML^?/H$.+'DVZM&G+80F^,//FS6G0:MG&]0C2Y%RW=>^J9+DWYLR:(V7($/SZ
M->*RBY>:?2RUJV3<E(M+GQZ1M6OJV+-KW\Z]NW?3J0NB.4J&3<`U,;YKC=V6
M(VVZM^M67(F7]TO??F?4D#&8IGK,QRD&`V/+&069<UA!9]5_#'8VGASEG5<&
M&6:DP489#6:HX88<=NAA3^&]\&"$;JPQW(<0L3<;7+C%)Q]EN^EU7U\UV2!<
M3BF%.*)Y)::'XD,!)J6<8P8VQ]5SS_VHI$\ARE%&&&Q4>.&2#JGHUGLMMB<?
M3/7)R-=O,<P@4W^#4=E4D,DUYA5SD268I)EP,N0DE%)B&.>=>.:IYYX'A3A'
M'FWPN`:?[F&T8FTB:?EBERW-"&8-=N$HPYQ16F@GGPBA.>"0:Q;9)DH*5H;I
MJ*26:NJIJ*:JZJJLMNKJJ[#&*NNLM-9JZZVXYJKKKKSVZNNOP`8K[+#$%FOL
)L<@FJ^RRS.X)
`
end

View file

@ -0,0 +1,77 @@
/*-
* Copyright (c) 2020 Martin Matuska
* 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_safe_writes)
{
/* Create files */
assertMakeDir("in", 0755);
assertEqualInt(0, chdir("in"));
assertMakeFile("f", 0644, "a");
assertMakeFile("fh", 0644, "b");
assertMakeFile("d", 0644, "c");
assertMakeFile("fs", 0644, "d");
assertMakeFile("ds", 0644, "e");
assertEqualInt(0, chdir(".."));
/* Tar files up */
assertEqualInt(0,
systemf("%s -c -C in -f t.tar f fh d fs ds "
">pack.out 2>pack.err", testprog));
/* Verify that nothing went to stdout or stderr. */
assertEmptyFile("pack.err");
assertEmptyFile("pack.out");
/* Create various objects */
assertMakeDir("out", 0755);
assertEqualInt(0, chdir("out"));
assertMakeFile("f", 0644, "a");
assertMakeHardlink("fh", "f");
assertMakeDir("d", 0755);
if (canSymlink()) {
assertMakeSymlink("fs", "f", 0);
assertMakeSymlink("ds", "d", 1);
}
assertEqualInt(0, chdir(".."));
/* Extract created archive withe safe writes */
assertEqualInt(0,
systemf("%s -x -C out --safe-writes -f t.tar "
">unpack.out 2>unpack.err", testprog));
/* Verify that nothing went to stdout or stderr. */
assertEmptyFile("unpack.err");
assertEmptyFile("unpack.out");
/* Verify that files were overwritten properly */
assertEqualInt(0, chdir("out"));
assertTextFileContents("a","f");
assertTextFileContents("b","fh");
assertTextFileContents("c","d");
assertTextFileContents("d","fs");
assertTextFileContents("e","ds");
}

View file

@ -0,0 +1,85 @@
/*-
* Copyright (c) 2003-2010 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_option_uid_uname)
{
char *reference, *data;
size_t s;
assertUmask(0);
assertMakeFile("file", 0644, "1234567890");
/* Create archive with no special options. */
failure("Error invoking %s c", testprog);
assertEqualInt(0,
systemf("%s cf archive1 --format=ustar file >stdout1.txt 2>stderr1.txt",
testprog));
assertEmptyFile("stdout1.txt");
assertEmptyFile("stderr1.txt");
reference = slurpfile(&s, "archive1");
/* Again with both --uid and --uname */
failure("Error invoking %s c", testprog);
assertEqualInt(0,
systemf("%s cf archive2 --uid=65123 --uname=foofoofoo --format=ustar file >stdout2.txt 2>stderr2.txt",
testprog));
assertEmptyFile("stdout2.txt");
assertEmptyFile("stderr2.txt");
data = slurpfile(&s, "archive2");
/* Should force uid and uname fields in ustar header. */
assertEqualMem(data + 108, "177143 \0", 8);
assertEqualMem(data + 265, "foofoofoo\0", 10);
free(data);
/* Again with just --uid */
failure("Error invoking %s c", testprog);
assertEqualInt(0,
systemf("%s cf archive3 --uid=65123 --format=ustar file >stdout3.txt 2>stderr3.txt",
testprog));
assertEmptyFile("stdout3.txt");
assertEmptyFile("stderr3.txt");
data = slurpfile(&s, "archive3");
assertEqualMem(data + 108, "177143 \0", 8);
/* Uname field in ustar header should be empty. */
assertEqualMem(data + 265, "\0", 1);
free(data);
/* Again with just --uname */
failure("Error invoking %s c", testprog);
assertEqualInt(0,
systemf("%s cf archive4 --uname=foofoofoo --format=ustar file >stdout4.txt 2>stderr4.txt",
testprog));
assertEmptyFile("stdout4.txt");
assertEmptyFile("stderr4.txt");
data = slurpfile(&s, "archive4");
/* Uid should be unchanged from original reference. */
assertEqualMem(data + 108, reference + 108, 8);
assertEqualMem(data + 265, "foofoofoo\0", 10);
free(data);
free(reference);
}

View file

@ -0,0 +1,56 @@
/*-
* 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_uuencode)
{
char *p;
size_t s;
/* Create a file. */
assertMakeFile("f", 0644, "a");
/* Archive it with compress compression and uuencode. */
assertEqualInt(0,
systemf("%s -cf - -Z --uuencode f >archive.out 2>archive.err",
testprog));
/* Check that the archive file has an uuencode signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "begin 644", 9);
free(p);
/* Archive it with uuencode only. */
assertEqualInt(0,
systemf("%s -cf - --uuencode f >archive.out 2>archive.err",
testprog));
/* Check that the archive file has an uuencode signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "begin 644", 9);
free(p);
}

View file

@ -0,0 +1,88 @@
/*-
* Copyright (c) 2017 Martin Matuska
* 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_xattrs)
{
#if !ARCHIVE_XATTR_SUPPORT
skipping("Extended attributes are not supported on this platform");
#else /* ARCHIVE_XATTR_SUPPORT */
const char *testattr = "user.libarchive.test";
const char *testval = "testval";
void *readval;
size_t size;
int r;
/* Create a file. */
assertMakeFile("f", 0644, "a");
if (!setXattr("f", "user.libarchive.test", testval,
strlen(testval) + 1)) {
skipping("Can't set user extended attributes on this "
"filesystem");
return;
}
/* Archive with xattrs */
r = systemf("%s -c --no-mac-metadata --xattrs -f xattrs.tar f >xattrs.out 2>xattrs.err", testprog);
assertEqualInt(r, 0);
/* Archive without xattrs */
r = systemf("%s -c --no-mac-metadata --no-xattrs -f noxattrs.tar f >noxattrs.out 2>noxattrs.err", testprog);
assertEqualInt(r, 0);
/* Extract xattrs with xattrs */
assertMakeDir("xattrs_xattrs", 0755);
r = systemf("%s -x -C xattrs_xattrs --no-same-permissions --xattrs -f xattrs.tar >xattrs_xattrs.out 2>xattrs_xattrs.err", testprog);
assertEqualInt(r, 0);
readval = getXattr("xattrs_xattrs/f", testattr, &size);
if(assertEqualInt(size, strlen(testval) + 1) != 0)
assertEqualMem(readval, testval, size);
free(readval);
/* Extract xattrs without xattrs */
assertMakeDir("xattrs_noxattrs", 0755);
r = systemf("%s -x -C xattrs_noxattrs -p --no-xattrs -f xattrs.tar >xattrs_noxattrs.out 2>xattrs_noxattrs.err", testprog);
assertEqualInt(r, 0);
readval = getXattr("xattrs_noxattrs/f", testattr, &size);
assert(readval == NULL);
/* Extract noxattrs with xattrs */
assertMakeDir("noxattrs_xattrs", 0755);
r = systemf("%s -x -C noxattrs_xattrs --no-same-permissions --xattrs -f noxattrs.tar >noxattrs_xattrs.out 2>noxattrs_xattrs.err", testprog);
assertEqualInt(r, 0);
readval = getXattr("noxattrs_xattrs/f", testattr, &size);
assert(readval == NULL);
/* Extract noxattrs with noxattrs */
assertMakeDir("noxattrs_noxattrs", 0755);
r = systemf("%s -x -C noxattrs_noxattrs -p --no-xattrs -f noxattrs.tar >noxattrs_noxattrs.out 2>noxattrs_noxattrs.err", testprog);
assertEqualInt(r, 0);
readval = getXattr("noxattrs_noxattrs/f", testattr, &size);
assert(readval == NULL);
#endif /* ARCHIVE_XATTR_SUPPORT */
}

View file

@ -0,0 +1,60 @@
/*-
* 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_xz)
{
char *p;
int r;
size_t s;
/* Create a file. */
assertMakeFile("f", 0644, "a");
/* Archive it with xz compression. */
r = systemf("%s -cf - --xz f >archive.out 2>archive.err",
testprog);
p = slurpfile(&s, "archive.err");
p[s] = '\0';
if (r != 0) {
if (strstr(p, "Unsupported compression") != NULL) {
skipping("This version of bsdtar was compiled "
"without xz support");
goto done;
}
failure("--xz option is broken");
assertEqualInt(r, 0);
goto done;
}
free(p);
/* Check that the archive file has an xz signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "\xFD\x37\x7A\x58\x5A\x00", 6);
done:
free(p);
}

View file

@ -0,0 +1,58 @@
/*-
* 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_z)
{
char *p;
int r;
size_t s;
/* Create a file. */
assertMakeFile("f", 0644, "a");
/* Archive it with gzip compression. */
r = systemf("%s -zcf archive.out f 2>archive.err", testprog);
p = slurpfile(&s, "archive.err");
p[s] = '\0';
if (r != 0) {
if (!canGzip()) {
skipping("gzip is not supported on this platform");
goto done;
}
failure("-z option is broken");
assertEqualInt(r, 0);
goto done;
}
free(p);
/* Check that the archive file has a gzip signature. */
p = slurpfile(&s, "archive.out");
assert(s > 4);
assertEqualMem(p, "\x1f\x8b\x08\x00", 4);
done:
free(p);
}

View file

@ -0,0 +1,85 @@
/*-
* Copyright (c) 2017 Sean Purcell
* 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_zstd)
{
char *p;
int r;
size_t s;
/* Create a file. */
assertMakeFile("f", 0644, "a");
/* Archive it with lz4 compression. */
r = systemf("%s -cf - --zstd f >archive.out 2>archive.err",
testprog);
p = slurpfile(&s, "archive.err");
p[s] = '\0';
if (r != 0) {
if (strstr(p, "Unsupported compression") != NULL) {
skipping("This version of bsdtar was compiled "
"without zstd support");
goto done;
}
/* POSIX permits different handling of the spawnp
* system call used to launch the subsidiary
* program: */
/* Some systems fail immediately to spawn the new process. */
if (strstr(p, "Can't launch") != NULL && !canZstd()) {
skipping("This version of bsdtar uses an external zstd program "
"but no such program is available on this system.");
goto done;
}
/* Some systems successfully spawn the new process,
* but fail to exec a program within that process.
* This results in failure at the first attempt to
* write. */
if (strstr(p, "Can't write") != NULL && !canZstd()) {
skipping("This version of bsdtar uses an external zstd program "
"but no such program is available on this system.");
goto done;
}
/* On some systems the error won't be detected until closing
time, by a 127 exit error returned by waitpid. */
if (strstr(p, "Error closing") != NULL && !canZstd()) {
skipping("This version of bsdcpio uses an external zstd program "
"but no such program is available on this system.");
return;
}
failure("--zstd option is broken: %s", p);
assertEqualInt(r, 0);
goto done;
}
free(p);
/* Check that the archive file has an lz4 signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "\x28\xb5\x2f\xfd", 4);
done:
free(p);
}

View file

@ -0,0 +1,190 @@
/*-
* Copyright (c) 2009 Michihiro NAKAJIMA
* Copyright (c) 2003-2007 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: src/usr.bin/tar/test/test_patterns.c,v 1.6 2008/08/21 22:28:00 kientzle Exp $");
DEFINE_TEST(test_patterns)
{
FILE *f;
int r;
const char *reffile2 = "test_patterns_2.tar";
const char *reffile3 = "test_patterns_3.tar";
const char *reffile4 = "test_patterns_4.tar";
const char *tar2aExpected[] = {
"/tmp/foo/bar/",
"/tmp/foo/bar/baz",
NULL
};
/*
* Test basic command-line pattern handling.
*/
/*
* Test 1: Files on the command line that don't get matched
* didn't produce an error.
*
* John Baldwin reported this problem in PR bin/121598
*/
f = fopen("foo", "w");
assert(f != NULL);
fclose(f);
r = systemf("%s cfv tar1.tgz foo > tar1a.out 2> tar1a.err", testprog);
assertEqualInt(r, 0);
r = systemf("%s xv --no-same-owner -f tar1.tgz foo bar > tar1b.out 2> tar1b.err", testprog);
failure("tar should return non-zero because a file was given on the command line that's not in the archive");
assert(r != 0);
/*
* Test 2: Check basic matching of full paths that start with /
*/
extract_reference_file(reffile2);
r = systemf("%s tf %s /tmp/foo/bar > tar2a.out 2> tar2a.err",
testprog, reffile2);
assertEqualInt(r, 0);
assertFileContainsLinesAnyOrder("tar2a.out", tar2aExpected);
assertEmptyFile("tar2a.err");
/*
* Test 3 archive has some entries starting with '/' and some not.
*/
extract_reference_file(reffile3);
/* Test 3a: Pattern tmp/foo/bar should not match /tmp/foo/bar */
r = systemf("%s x --no-same-owner -f %s tmp/foo/bar > tar3a.out 2> tar3a.err",
testprog, reffile3);
assert(r != 0);
assertEmptyFile("tar3a.out");
/* Test 3b: Pattern /tmp/foo/baz should not match tmp/foo/baz */
assertNonEmptyFile("tar3a.err");
/* Again, with the '/' */
r = systemf("%s x --no-same-owner -f %s /tmp/foo/baz > tar3b.out 2> tar3b.err",
testprog, reffile3);
assert(r != 0);
assertEmptyFile("tar3b.out");
assertNonEmptyFile("tar3b.err");
/* Test 3c: ./tmp/foo/bar should not match /tmp/foo/bar */
r = systemf("%s x --no-same-owner -f %s ./tmp/foo/bar > tar3c.out 2> tar3c.err",
testprog, reffile3);
assert(r != 0);
assertEmptyFile("tar3c.out");
assertNonEmptyFile("tar3c.err");
/* Test 3d: ./tmp/foo/baz should match tmp/foo/baz */
r = systemf("%s x --no-same-owner -f %s ./tmp/foo/baz > tar3d.out 2> tar3d.err",
testprog, reffile3);
assertEqualInt(r, 0);
assertEmptyFile("tar3d.out");
assertEmptyFile("tar3d.err");
assertFileExists("tmp/foo/baz/bar");
/*
* Test 4 archive has some entries starting with windows drive letters
* such as 'c:\', '//./c:/' or '//?/c:/'.
*/
extract_reference_file(reffile4);
r = systemf("%s x --no-same-owner -f %s -C tmp > tar4.out 2> tar4.err",
testprog, reffile4);
assert(r != 0);
assertEmptyFile("tar4.out");
assertNonEmptyFile("tar4.err");
for (r = 1; r <= 54; r++) {
char file_a[] = "tmp/fileXX";
char file_b1[] = "tmp/server/share/fileXX";
char file_b2[] = "tmp/server\\share\\fileXX";
char file_c[] = "tmp/../fileXX";
char file_d[] = "tmp/../../fileXX";
char *filex;
int xsize;
switch (r) {
case 15: case 18:
/*
* Including server and share names.
* //?/UNC/server/share/file15
* //?/unc/server/share/file18
*/
filex = file_b1;
xsize = sizeof(file_b1);
break;
case 35: case 38: case 52:
/*
* Including server and share names.
* \\?\UNC\server\share\file35
* \\?\unc\server\share\file38
* \/?/uNc/server\share\file52
*/
filex = file_b2;
xsize = sizeof(file_b2);
break;
default:
filex = file_a;
xsize = sizeof(file_a);
break;
}
filex[xsize-3] = '0' + r / 10;
filex[xsize-2] = '0' + r % 10;
switch (r) {
case 5: case 6: case 17: case 20: case 25:
case 26: case 37: case 40: case 43: case 54:
/*
* Not extracted patterns.
* D:../file05
* c:../../file06
* //?/UNC/../file17
* //?/unc/../file20
* z:..\file25
* c:..\..\file26
* \\?\UNC\..\file37
* \\?\unc\..\file40
* c:../..\file43
* \/?\UnC\../file54
*/
assertFileNotExists(filex);
if (r == 6 || r == 26 || r == 43) {
filex = file_d;
xsize = sizeof(file_d);
} else {
filex = file_c;
xsize = sizeof(file_c);
}
filex[xsize-3] = '0' + r / 10;
filex[xsize-2] = '0' + r % 10;
assertFileNotExists(filex);
break;
default:
/* Extracted patterns. */
assertFileExists(filex);
break;
}
}
}

View file

@ -0,0 +1,231 @@
begin 644 test_patterns_2.tar
M+W1M<"]F;V\O````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````#`P,#<U-2``,#`Q-S4P(``P,#`P,#`@`#`P,#`P,#`P,#`P
M(#$Q,#4Q,C$R-C4V(#`Q,C0T,0`@-0``````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````````!U<W1A<@`P,'1I;0``
M````````````````````````````````````=VAE96P`````````````````
M```````````````````P,#`P,#`@`#`P,#`P,"``````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M```````````````````````O=&UP+V9O;R]B87(O````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````,#`P-S4U(``P,#$W-3`@`#`P
M,#`P,"``,#`P,#`P,#`P,#`@,3$P-3$R,3(V-3,@,#$S,C`R`"`U````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````'5S=&%R`#`P=&EM``````````````````````````````````````!W
M:&5E;````````````````````````````````````#`P,#`P,"``,#`P,#`P
M(```````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````````"]T;7`O9F]O+V)A
M>@``````````````````````````````````````````````````````````
M```````````````````````````````````````````````````````````P
M,#`V-#0@`#`P,3<U,"``,#`P,#`P(``P,#`P,#`P,#`P,"`Q,3`U,3(Q,C8U
M-B`P,3,Q,C8`(#``````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````=7-T87(`,#!T:6T`````````````````
M`````````````````````'=H965L````````````````````````````````
M````,#`P,#`P(``P,#`P,#`@````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````+W1M<"]F;V\O8F%R+V)A>@``````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````#`P,#8T-"``,#`Q-S4P(``P,#`P,#`@`#`P,#`P
M,#`P,#`P(#$Q,#4Q,C$R-C4S(#`Q,S8V-P`@,```````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````````````````!U<W1A<@`P
M,'1I;0``````````````````````````````````````=VAE96P`````````
M```````````````````````````P,#`P,#`@`#`P,#`P,"``````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
9````````````````````````````````````
`
end

View file

@ -0,0 +1,231 @@
begin 644 test_patterns_3.tar
M+W1M<"]F;V\O8F%R+P``````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````#`P,#<U-2``,#`Q-S4P(``P,#`P,#`@`#`P,#`P,#`P,#`P
M(#$Q,#4S,C`W-34R(#`Q,S(P-@`@-0``````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````````!U<W1A<@`P,'1I;0``
M````````````````````````````````````=VAE96P`````````````````
M```````````````````P,#`P,#`@`#`P,#`P,"``````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M```````````````````````O=&UP+V9O;R]B87(O8F%Z+P``````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````,#`P-S4U(``P,#$W-3`@`#`P
M,#`P,"``,#`P,#`P,#`P,#`@,3$P-3,R,#<U-3(@,#$S-S8R`"`U````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````'5S=&%R`#`P=&EM``````````````````````````````````````!W
M:&5E;````````````````````````````````````#`P,#`P,"``,#`P,#`P
M(```````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````````'1M<"]F;V\O8F%Z
M+P``````````````````````````````````````````````````````````
M```````````````````````````````````````````````````````````P
M,#`W-34@`#`P,3<U,"``,#`P,#`P(``P,#`P,#`P,#`P,"`Q,3`U,S(P-S4V
M,"`P,3,Q,S8`(#4`````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````=7-T87(`,#!T:6T`````````````````
M`````````````````````'=H965L````````````````````````````````
M````,#`P,#`P(``P,#`P,#`@````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````=&UP+V9O;R]B87HO8F%R+P``````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````#`P,#<U-2``,#`Q-S4P(``P,#`P,#`@`#`P,#`P
M,#`P,#`P(#$Q,#4S,C`W-38P(#`Q,S<P,@`@-0``````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````````````````!U<W1A<@`P
M,'1I;0``````````````````````````````````````=VAE96P`````````
M```````````````````````````P,#`P,#`@`#`P,#`P,"``````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
9````````````````````````````````````
`
end

View file

@ -0,0 +1,641 @@
begin 644 test_patterns_4.tar
M+V9I;&4P,0``````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P,#`P
M(#$Q,34P-C<T-C0R(#`Q,#,S-@`@,```````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````````!U<W1A<@`P,```````
M````````````````````````````````````````````````````````````
M```````````````````P,#`P,#`@`#`P,#`P,"``````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M```````````````````````O+BXO9FEL93`R````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````,#`P-C0T(``P,#$W-3$@`#`P
M,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$P-34R`"`P````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````'5S=&%R`#`P````````````````````````````````````````````
M`````````````````````````````````````````#`P,#`P,"``,#`P,#`P
M(```````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````````"\N+B\N+B]F:6QE
M,#,`````````````````````````````````````````````````````````
M```````````````````````````````````````````````````````````P
M,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U,#8W-#8T
M,B`P,3`W-C8`(#``````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````=7-T87(`,#``````````````````````
M````````````````````````````````````````````````````````````
M````,#`P,#`P(``P,#`P,#`@````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````8SHO9FEL93`T````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P
M,#`P,#`P(#$Q,34P-C<T-C0R(#`Q,#4W-@`@,```````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````````````````!U<W1A<@`P
M,```````````````````````````````````````````````````````````
M```````````````````````````P,#`P,#`@`#`P,#`P,"``````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````!$.BXN+V9I;&4P-0``````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````,#`P-C0T(``P,#$W
M-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$P-C<T`"`P
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````'5S=&%R`#`P````````````````````````````````````
M`````````````````````````````````````````````````#`P,#`P,"``
M,#`P,#`P(```````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````````````````&,Z+BXO
M+BXO9FEL93`V````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M```````P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U
M,#8W-#8T,B`P,3$Q-#<`(#``````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````=7-T87(`,#``````````````
M````````````````````````````````````````````````````````````
M````````````,#`P,#`P(``P,#`P,#`@````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````0SHO+BXO9FEL93`W````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@
M`#`P,#`P,#`P,#`P(#$Q,34P-C<T-C0R(#`Q,#<U-``@,```````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````````````````````````!U
M<W1A<@`P,```````````````````````````````````````````````````
M```````````````````````````````````P,#`P,#`@`#`P,#`P,"``````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````!A.B\N+B\N+B]F:6QE,#@`
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````,#`P-C0T
M(``P,#$W-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$Q
M,C(V`"`P````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````'5S=&%R`#`P````````````````````````````
M`````````````````````````````````````````````````````````#`P
M,#`P,"``,#`P,#`P(```````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`"\O+B]C.B]F:6QE,#D`````````````````````````````````````````
M````````````````````````````````````````````````````````````
M```````````````P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P
M,"`Q,3$U,#8W-#8T,B`P,3$P-S8`(#``````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````=7-T87(`,#``````
M````````````````````````````````````````````````````````````
M````````````````````,#`P,#`P(``P,#`P,#`@````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````+R\N+T,Z+RXN+V9I;&4Q,```````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````#`P,#8T-"``,#`Q-S4Q(``P
M,#$W-3$@`#`P,#`P,#`P,#`P(#$Q,34P-C<T-C0R(#`Q,3(T,0`@,```````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````!U<W1A<@`P,```````````````````````````````````````````
M```````````````````````````````````````````P,#`P,#`@`#`P,#`P
M,"``````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M```````````````````````````````````````````````O+S\O8SHO9FEL
M93$Q````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M,#`P-C0T(``P,#$W-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V
M-#(@,#$Q,3$P`"`P````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````'5S=&%R`#`P````````````````````
M````````````````````````````````````````````````````````````
M`````#`P,#`P,"``,#`P,#`P(```````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````"\O/R]#.B\N+B]F:6QE,3(`````````````````````````````
M````````````````````````````````````````````````````````````
M```````````````````````P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P
M,#`P,#`P,"`Q,3$U,#8W-#8T,B`P,3$R-C0`(#``````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````=7-T87(`
M,#``````````````````````````````````````````````````````````
M````````````````````````````,#`P,#`P(``P,#`P,#`@````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````+R\O+V,Z+V9I;&4Q,P``````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````````#`P,#8T-"``,#`Q
M-S4Q(``P,#$W-3$@`#`P,#`P,#`P,#`P(#$Q,34P-C<T-C0R(#`Q,3`W,@`@
M,```````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````!U<W1A<@`P,```````````````````````````````````
M```````````````````````````````````````````````````P,#`P,#`@
M`#`P,#`P,"``````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M```````````````````````````````````````````````````````O+R\O
M0SHO+R\O+V9I;&4Q-```````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````,#`P-C0T(``P,#$W-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q
M-3`V-S0V-#(@,#$Q,S(W`"`P````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````'5S=&%R`#`P````````````
M````````````````````````````````````````````````````````````
M`````````````#`P,#`P,"``,#`P,#`P(```````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````"\O/R]53D,O<V5R=F5R+W-H87)E+V9I;&4Q-0``````
M````````````````````````````````````````````````````````````
M```````````````````````````````P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q
M(``P,#`P,#`P,#`P,"`Q,3$U,#8W-#8T,B`P,3,V,S4`(#``````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M=7-T87(`,#``````````````````````````````````````````````````
M````````````````````````````````````,#`P,#`P(``P,#`P,#`@````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````+R\_+U5.0R]F:6QE,38`
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````````````````#`P,#8T
M-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P,#`P(#$Q,34P-C<T-C0R(#`Q
M,3(R-@`@,```````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````!U<W1A<@`P,```````````````````````````
M```````````````````````````````````````````````````````````P
M,#`P,#`@`#`P,#`P,"``````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M```O+S\O54Y#+RXN+V9I;&4Q-P``````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````,#`P-C0T(``P,#$W-3$@`#`P,3<U,2``,#`P,#`P,#`P
M,#`@,3$Q-3`V-S0V-#(@,#$Q-#0R`"`P````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````````'5S=&%R`#`P````
M````````````````````````````````````````````````````````````
M`````````````````````#`P,#`P,"``,#`P,#`P(```````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````"\O/R]U;F,O<V5R=F5R+W-H87)E+V9I;&4Q
M.```````````````````````````````````````````````````````````
M```````````````````````````````````````P,#`V-#0@`#`P,3<U,2``
M,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U,#8W-#8T,B`P,30P,#``(#``````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````=7-T87(`,#``````````````````````````````````````````
M````````````````````````````````````````````,#`P,#`P(``P,#`P
M,#`@````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````+R\_+W5N8R]F
M:6QE,3D`````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P,#`P(#$Q,34P-C<T
M-C0R(#`Q,3,W,0`@,```````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````!U<W1A<@`P,```````````````````
M````````````````````````````````````````````````````````````
M```````P,#`P,#`@`#`P,#`P,"``````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M```````````O+S\O=6YC+RXN+V9I;&4R,```````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````,#`P-C0T(``P,#$W-3$@`#`P,3<U,2``,#`P
M,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$Q-3<T`"`P````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````````````````'5S=&%R
M`#`P````````````````````````````````````````````````````````
M`````````````````````````````#`P,#`P,"``,#`P,#`P(```````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````%QF:6QE,C$`````````````````
M````````````````````````````````````````````````````````````
M```````````````````````````````````````````````P,#`V-#0@`#`P
M,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U,#8W-#8T,B`P,3`T,34`
M(#``````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````=7-T87(`,#``````````````````````````````````
M````````````````````````````````````````````````````,#`P,#`P
M(``P,#`P,#`@````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````7"XN
M7&9I;&4R,@``````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P,#`P(#$Q
M,34P-C<T-C0R(#`Q,#<P-@`@,```````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````!U<W1A<@`P,```````````
M````````````````````````````````````````````````````````````
M```````````````P,#`P,#`@`#`P,#`P,"``````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````!<+BY<+BY<9FEL93(S````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````,#`P-C0T(``P,#$W-3$@`#`P,3<U
M,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$Q,3<W`"`P````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`'5S=&%R`#`P````````````````````````````````````````````````
M`````````````````````````````````````#`P,#`P,"``,#`P,#`P(```
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````$,Z7&9I;&4R-```````
M````````````````````````````````````````````````````````````
M```````````````````````````````````````````````````````P,#`V
M-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U,#8W-#8T,B`P
M,3`V,34`(#``````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````=7-T87(`,#``````````````````````````
M````````````````````````````````````````````````````````````
M,#`P,#`P(``P,#`P,#`@````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````>CHN+EQF:6QE,C4`````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P
M,#`P(#$Q,34P-C<T-C0R(#`Q,3`T,0`@,```````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````````````!U<W1A<@`P,```
M````````````````````````````````````````````````````````````
M```````````````````````P,#`P,#`@`#`P,#`P,"``````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````!C.BXN7"XN7&9I;&4R-@``````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````,#`P-C0T(``P,#$W-3$@
M`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$Q,S`S`"`P````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````'5S=&%R`#`P````````````````````````````````````````
M`````````````````````````````````````````````#`P,#`P,"``,#`P
M,#`P(```````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````````````%HZ7"XN7&9I
M;&4R-P``````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M```P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U,#8W
M-#8T,B`P,3$Q,S<`(#``````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````=7-T87(`,#``````````````````
M````````````````````````````````````````````````````````````
M````````,#`P,#`P(``P,#`P,#`@````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````0SI<+BY<+BY<9FEL93(X````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P
M,#`P,#`P,#`P(#$Q,34P-C<T-C0R(#`Q,30P,0`@,```````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````````````````````!U<W1A
M<@`P,```````````````````````````````````````````````````````
M```````````````````````````````P,#`P,#`@`#`P,#`P,"``````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````!<7"Y<8SI<9FEL93(Y````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````,#`P-C0T(``P
M,#$W-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$Q,S8T
M`"`P````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````'5S=&%R`#`P````````````````````````````````
M`````````````````````````````````````````````````````#`P,#`P
M,"``,#`P,#`P(```````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````````````````````%Q<
M+EQ#.EPN+EQF:6QE,S``````````````````````````````````````````
M````````````````````````````````````````````````````````````
M```````````P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q
M,3$U,#8W-#8T,B`P,3$V,#0`(#``````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````=7-T87(`,#``````````
M````````````````````````````````````````````````````````````
M````````````````,#`P,#`P(``P,#`P,#`@````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````7%P_7&,Z7&9I;&4S,0``````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W
M-3$@`#`P,#`P,#`P,#`P(#$Q,34P-C<T-C0R(#`Q,3,W-@`@,```````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``!U<W1A<@`P,```````````````````````````````````````````````
M```````````````````````````````````````P,#`P,#`@`#`P,#`P,"``
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````````!<7#]<1#I<+BY<9FEL
M93,R````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````,#`P
M-C0T(``P,#$W-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@
M,#$Q-C,P`"`P````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````'5S=&%R`#`P````````````````````````
M````````````````````````````````````````````````````````````
M`#`P,#`P,"``,#`P,#`P(```````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````%Q<7%QC.EQF:6QE,S,`````````````````````````````````````
M````````````````````````````````````````````````````````````
M```````````````````P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P
M,#`P,"`Q,3$U,#8W-#8T,B`P,3$T,S4`(#``````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````=7-T87(`,#``
M````````````````````````````````````````````````````````````
M````````````````````````,#`P,#`P(``P,#`P,#`@````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````7%Q<7$,Z7%Q<7%QF:6QE,S0`````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````#`P,#8T-"``,#`Q-S4Q
M(``P,#$W-3$@`#`P,#`P,#`P,#`P(#$Q,34P-C<T-C0R(#`Q,C$U-@`@,```
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````!U<W1A<@`P,```````````````````````````````````````
M```````````````````````````````````````````````P,#`P,#`@`#`P
M,#`P,"``````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````````````````!<7#]<54Y#
M7'-E<G9E<EQS:&%R95QF:6QE,S4`````````````````````````````````
M````````````````````````````````````````````````````````````
M````,#`P-C0T(``P,#$W-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V
M-S0V-#(@,#$T,C4U`"`P````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````'5S=&%R`#`P````````````````
M````````````````````````````````````````````````````````````
M`````````#`P,#`P,"``,#`P,#`P(```````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````%Q</UQ53D-<9FEL93,V````````````````````````````
M````````````````````````````````````````````````````````````
M```````````````````````````P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P
M,#`P,#`P,#`P,"`Q,3$U,#8W-#8T,B`P,3$U,30`(#``````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````=7-T
M87(`,#``````````````````````````````````````````````````````
M````````````````````````````````,#`P,#`P(``P,#`P,#`@````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````7%P_7%5.0UPN+EQF:6QE,S<`
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````````````#`P,#8T-"``
M,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P,#`P(#$Q,34P-C<T-C0R(#`Q,C`P
M-0`@,```````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````!U<W1A<@`P,```````````````````````````````
M```````````````````````````````````````````````````````P,#`P
M,#`@`#`P,#`P,"``````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````````````````````````!<
M7#]<=6YC7'-E<G9E<EQS:&%R95QF:6QE,S@`````````````````````````
M````````````````````````````````````````````````````````````
M````````````,#`P-C0T(``P,#$W-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@
M,3$Q-3`V-S0V-#(@,#$T-#(P`"`P````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````'5S=&%R`#`P````````
M````````````````````````````````````````````````````````````
M`````````````````#`P,#`P,"``,#`P,#`P(```````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````%Q</UQU;F-<9FEL93,Y````````````````````
M````````````````````````````````````````````````````````````
M```````````````````````````````````P,#`V-#0@`#`P,3<U,2``,#`Q
M-S4Q(``P,#`P,#`P,#`P,"`Q,3$U,#8W-#8T,B`P,3$V-3<`(#``````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````=7-T87(`,#``````````````````````````````````````````````
M````````````````````````````````````````,#`P,#`P(``P,#`P,#`@
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````7%P_7'5N8UPN+EQF
M:6QE-#``````````````````````````````````````````````````````
M`````````````````````````````````````````````````````````#`P
M,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P,#`P(#$Q,34P-C<T-C0R
M(#`Q,C$S-P`@,```````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````!U<W1A<@`P,```````````````````````
M````````````````````````````````````````````````````````````
M```P,#`P,#`@`#`P,#`P,"``````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````!<+BXO9FEL930Q````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````,#`P-C0T(``P,#$W-3$@`#`P,3<U,2``,#`P,#`P
M,#`P,#`@,3$Q-3`V-S0V-#(@,#$P-C,R`"`P````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````````````'5S=&%R`#`P
M````````````````````````````````````````````````````````````
M`````````````````````````#`P,#`P,"``,#`P,#`P(```````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````%PN+B\N+EQF:6QE-#(`````````````
M````````````````````````````````````````````````````````````
M```````````````````````````````````````````P,#`V-#0@`#`P,3<U
M,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U,#8W-#8T,B`P,3$Q,C,`(#``
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````=7-T87(`,#``````````````````````````````````````
M````````````````````````````````````````````````,#`P,#`P(``P
M,#`P,#`@````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````8SHN+B\N
M+EQF:6QE-#,`````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P,#`P(#$Q,34P
M-C<T-C0R(#`Q,3(R-0`@,```````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````!U<W1A<@`P,```````````````
M````````````````````````````````````````````````````````````
M```````````P,#`P,#`@`#`P,#`P,"``````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````!#.B\N+EQF:6QE-#0`````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````,#`P-C0T(``P,#$W-3$@`#`P,3<U,2``
M,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$Q,#,R`"`P````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````````````````````'5S
M=&%R`#`P````````````````````````````````````````````````````
M`````````````````````````````````#`P,#`P,"``,#`P,#`P(```````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````$0Z7"XN+RXN7&9I;&4T-0``
M````````````````````````````````````````````````````````````
M```````````````````````````````````````````````````P,#`V-#0@
M`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U,#8W-#8T,B`P,3$S
M,C0`(#``````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````=7-T87(`,#``````````````````````````````
M````````````````````````````````````````````````````````,#`P
M,#`P(``P,#`P,#`@````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M7"\N+V,Z7&9I;&4T-@``````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P,#`P
M(#$Q,34P-C<T-C0R(#`Q,3(S,0`@,```````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````````!U<W1A<@`P,```````
M````````````````````````````````````````````````````````````
M```````````````````P,#`P,#`@`#`P,#`P,"``````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````!<7"XO0SI<+BY<9FEL930W````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````,#`P-C0T(``P,#$W-3$@`#`P
M,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$Q-3,W`"`P````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````'5S=&%R`#`P````````````````````````````````````````````
M`````````````````````````````````````````#`P,#`P,"``,#`P,#`P
M(```````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````````%PO/UQC.B]F:6QE
M-#@`````````````````````````````````````````````````````````
M```````````````````````````````````````````````````````````P
M,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U,#8W-#8T
M,B`P,3$R-30`(#``````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````=7-T87(`,#``````````````````````
M````````````````````````````````````````````````````````````
M````,#`P,#`P(``P,#`P,#`@````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````7%P_+T0Z+RXN7&9I;&4T.0``````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P
M,#`P,#`P(#$Q,34P-C<T-C0R(#`Q,34P-@`@,```````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````````````````!U<W1A<@`P
M,```````````````````````````````````````````````````````````
M```````````````````````````P,#`P,#`@`#`P,#`P,"``````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````!<+R]<1#I<9FEL934P````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````,#`P-C0T(``P,#$W
M-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$Q,C0S`"`P
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````'5S=&%R`#`P````````````````````````````````````
M`````````````````````````````````````````````````#`P,#`P,"``
M,#`P,#`P(```````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````````````````%Q<+R]C
M.EPO+UQ<9FEL934Q````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M```````P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P,"`Q,3$U
M,#8W-#8T,B`P,3$W,S$`(#``````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````=7-T87(`,#``````````````
M````````````````````````````````````````````````````````````
M````````````,#`P,#`P(``P,#`P,#`@````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````7"\_+W5.8R]S97)V97)<<VAA<F5<9FEL934R````````
M````````````````````````````````````````````````````````````
M`````````````````````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@
M`#`P,#`P,#`P,#`P(#$Q,34P-C<T-C0R(#`Q-#$T-0`@,```````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````````````````````````!U
M<W1A<@`P,```````````````````````````````````````````````````
M```````````````````````````````````P,#`P,#`@`#`P,#`P,"``````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````````````!<7#\O54YC7&9I;&4U,P``
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````,#`P-C0T
M(``P,#$W-3$@`#`P,3<U,2``,#`P,#`P,#`P,#`@,3$Q-3`V-S0V-#(@,#$Q
M-#<V`"`P````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````'5S=&%R`#`P````````````````````````````
M`````````````````````````````````````````````````````````#`P
M,#`P,"``,#`P,#`P(```````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`%PO/UQ5;D-<+BXO9FEL934T````````````````````````````````````
M````````````````````````````````````````````````````````````
M```````````````P,#`V-#0@`#`P,3<U,2``,#`Q-S4Q(``P,#`P,#`P,#`P
M,"`Q,3$U,#8W-#8T,B`P,3$W,3(`(#``````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````=7-T87(`,#``````
M````````````````````````````````````````````````````````````
M````````````````````,#`P,#`P(``P,#`P,#`@````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
'````````````
`
end

View file

@ -0,0 +1,54 @@
/*-
* Copyright (c) 2011 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_print_longpath)
{
const char *reffile = "test_print_longpath.tar.Z";
char buff[2048];
int i, j, k;
/* Reference file has one entry "file" with a very old timestamp. */
extract_reference_file(reffile);
/* Build long path pattern. */
memset(buff, 0, sizeof(buff));
for (k = 0; k < 4; k++) {
for (j = 0; j < k+1; j++) {
for (i = 0; i < 10; i++)
strncat(buff, "0123456789",
sizeof(buff) - strlen(buff) -1);
strncat(buff, "/", sizeof(buff) - strlen(buff) -1);
}
strncat(buff, "\n", sizeof(buff) - strlen(buff) -1);
}
buff[sizeof(buff)-1] = '\0';
assertEqualInt(0,
systemf("%s -tf %s >test.out 2>test.err", testprog, reffile));
assertTextFileContents(buff, "test.out");
assertEmptyFile("test.err");
}

View file

@ -0,0 +1,24 @@
begin 644 test_print_longpath.tar.Z
M'YV04,+@05(F#)DR<E[`B"%C!HT:-F[@R+&PX<.($RLZA"B1(L.-&#U:Y)CQ
MX\6.&D^6'!DR)4<``&#(O%&C!HB8"VG&N"DSADZ>,H/*E$$31(P8$6_0"$H4
M!`R+-&@``($'IM6K6+-JW<JUJ]>O8+O6F4,GC!R<8^J4"<LV[5JV8(7*!"KT
M)MR[>//JW<NWK]>C.^&$H8.FA\N6)DF*!(DR,6*6C2&O9#Q9Y6++ASN^4"`#
M!H@Q=-*T*=,CQ@P9-638\%B#L^?!HDF;1JV:M8(9.$`P22(DB)0A2))8*>)B
MC)R"H=^X"3VZ].G4-B;FP*'`K_7KV+-KW\Z]N_?O5S-75BS^,GG'D2F;?ZR^
M?.87.&'0M(G39XV=]7_&EQO4*-(;2C%U@U,RH`;15#6`IZ!V8Y5UEDQN:1=A
M=OS1U=^"&&:H85@!#53000FYA]YX[&$VXGKIF2@9BC`%-1]0]N'7DW[\R125
M#/XEM91,-3DU`T0TS#!551L6"5>#9J&EEH1+4BB7A7/%=**(*U+9WI185IFE
M>D;Z)0-#(`A&F&%;JGBEEFB>J::9;"JF4)GGI=EFB7&N6>><FKGV&7.R/5<;
M##/<H"=LS<T&'44U4(>;;KSY!IQPQ!F'7!K*\>D<;:M55%V7G';J:896XDEB
MBG>62N>II$8$GXL]YG<?C#36V-]1.@;5(Z`TW&!##`A^ZJM52#X(PX38$7M=
MA?M%&:JIJ38[ZK,H0EO>KW=U2)!!"+TI)[/2PHEJMY"U.%.K,[[JJHPUVB!?
MC@#N&$-J/@(I%574^AJLDF\5VR1VR/;KK;/1!KSLMP*?6"];,Y@6YF"%#0RP
MP^#:27!YVDK\\+\1BUKPBA5K#/'&%F?,;0Z;=;9G;)<>"L-T@UIJZ)\RY'!;
M;KOU]EMPPQ5W'&R5HOQRIC%O>O#07WUL-,8@>XS>JN/25RZZ,4)9(:WM]@0O
MKC3=T"O17=X+X;[7&6M=OT]*N>W$2!]]-L!<>V7MA]FJ'7+2(SLLKGSDYF3N
MTU+/!(,-[`:X4)#QVA#5D&T;Z?6P8%LGME]DUV7VW'(KO;;((27.%0TQT+#P
MF)77G?;HEY,<.MJEGPYPQZ*G3CKE2+...NRNUSYWR9Z!YK.?F>800\N[8TJ1
M[T(3K3KF%]N.)]-X.ZTWU+'*ZAG5@G<^@X^YUJ`U"`EJKN'BC_<5/E^17W@\
:W;-;/K?W[+?O_OOPQR___/37;__]^.>OOU<`
`
end

View file

@ -0,0 +1,126 @@
/*-
* Copyright (c) 2003-2007 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: src/usr.bin/tar/test/test_stdio.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $");
DEFINE_TEST(test_stdio)
{
FILE *filelist;
char *p;
size_t s;
int r;
assertUmask(0);
/*
* Create a couple of files on disk.
*/
/* File */
assertMakeFile("f", 0755, "abc");
/* Link to above file. */
assertMakeHardlink("l", "f");
/* Create file list (text mode here) */
filelist = fopen("filelist", "w");
assert(filelist != NULL);
fprintf(filelist, "f\n");
fprintf(filelist, "l\n");
fclose(filelist);
/*
* Archive/dearchive with a variety of options, verifying
* stdio paths.
*/
/* 'cf' should generate no output unless there's an error. */
r = systemf("%s cf archive f l >cf.out 2>cf.err", testprog);
assertEqualInt(r, 0);
assertEmptyFile("cf.out");
assertEmptyFile("cf.err");
/* 'cvf' should generate file list on stderr, empty stdout. */
r = systemf("%s cvf archive f l >cvf.out 2>cvf.err", testprog);
assertEqualInt(r, 0);
failure("'cv' writes filenames to stderr, nothing to stdout (SUSv2)\n"
"Note that GNU tar writes the file list to stdout by default.");
assertEmptyFile("cvf.out");
/* TODO: Verify cvf.err has file list in SUSv2-prescribed format. */
/* 'cvf -' should generate file list on stderr, archive on stdout. */
r = systemf("%s cvf - f l >cvf-.out 2>cvf-.err", testprog);
assertEqualInt(r, 0);
failure("cvf - should write archive to stdout");
/* TODO: Verify cvf-.out has archive. */
failure("cvf - should write file list to stderr (SUSv2)");
/* TODO: Verify cvf-.err has verbose file list. */
/* 'tf' should generate file list on stdout, empty stderr. */
r = systemf("%s tf archive >tf.out 2>tf.err", testprog);
assertEqualInt(r, 0);
assertEmptyFile("tf.err");
failure("'t' mode should write results to stdout");
/* TODO: Verify tf.out has file list. */
/* 'tvf' should generate file list on stdout, empty stderr. */
r = systemf("%s tvf archive >tvf.out 2>tvf.err", testprog);
assertEqualInt(r, 0);
assertEmptyFile("tvf.err");
failure("'tv' mode should write results to stdout");
/* TODO: Verify tvf.out has file list. */
/* 'tvf -' uses stdin, file list on stdout, empty stderr. */
r = systemf("%s tvf - < archive >tvf-.out 2>tvf-.err", testprog);
assertEqualInt(r, 0);
assertEmptyFile("tvf-.err");
/* TODO: Verify tvf-.out has file list. */
/* Basic 'xf' should generate no output on stdout or stderr. */
r = systemf("%s xf archive >xf.out 2>xf.err", testprog);
assertEqualInt(r, 0);
assertEmptyFile("xf.err");
assertEmptyFile("xf.out");
/* 'xvf' should generate list on stderr, empty stdout. */
r = systemf("%s xvf archive >xvf.out 2>xvf.err", testprog);
assertEqualInt(r, 0);
assertEmptyFile("xvf.out");
/* TODO: Verify xvf.err */
/* 'xvOf' should generate list on stderr, file contents on stdout. */
r = systemf("%s xvOf archive >xvOf.out 2>xvOf.err", testprog);
assertEqualInt(r, 0);
/* Verify xvOf.out is the file contents */
p = slurpfile(&s, "xvOf.out");
assertEqualInt((int)s, 3);
assertEqualMem(p, "abc", 3);
/* TODO: Verify xvf.err */
free(p);
/* 'xvf -' should generate list on stderr, empty stdout. */
r = systemf("%s xvf - < archive >xvf-.out 2>xvf-.err", testprog);
assertEqualInt(r, 0);
assertEmptyFile("xvf-.out");
/* TODO: Verify xvf-.err */
}

View file

@ -0,0 +1,140 @@
/*-
* Copyright (c) 2003-2007 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: src/usr.bin/tar/test/test_strip_components.c,v 1.2 2008/11/10 05:24:13 kientzle Exp $");
DEFINE_TEST(test_strip_components)
{
assertMakeDir("d0", 0755);
assertChdir("d0");
assertMakeDir("d1", 0755);
assertMakeDir("d1/d2", 0755);
assertMakeDir("d1/d2/d3", 0755);
assertMakeFile("d1/d2/f1", 0644, "");
assertMakeHardlink("l1", "d1/d2/f1");
assertMakeHardlink("d1/l2", "d1/d2/f1");
if (canSymlink()) {
assertMakeSymlink("s1", "d1/d2/f1", 0);
assertMakeSymlink("d1/s2", "d2/f1", 0);
}
assertChdir("..");
/*
* Test 1: Strip components when extracting archives.
*/
if (canSymlink())
assertEqualInt(0, systemf("%s -cf test.tar d0/l1 d0/s1 d0/d1",
testprog));
else
assertEqualInt(0, systemf("%s -cf test.tar d0/l1 d0/d1",
testprog));
assertMakeDir("target", 0755);
assertEqualInt(0, systemf("%s -x -C target --strip-components 2 "
"-f test.tar", testprog));
failure("d0/ is too short and should not get restored");
assertFileNotExists("target/d0");
failure("d0/d1/ is too short and should not get restored");
assertFileNotExists("target/d1");
failure("d0/s1 is too short and should not get restored");
assertFileNotExists("target/s1");
failure("d0/d1/s2 is a symlink to something that won't be extracted");
/* If platform supports symlinks, target/s2 is a broken symlink. */
/* If platform does not support symlink, target/s2 doesn't exist. */
if (canSymlink())
assertIsSymlink("target/s2", "d2/f1", 0);
else
assertFileNotExists("target/s2");
failure("d0/d1/d2 should be extracted");
assertIsDir("target/d2", -1);
/*
* Test 1b: Strip components extracting archives involving hardlinks.
*
* This next is a complicated case. d0/l1, d0/d1/l2, and
* d0/d1/d2/f1 are all hardlinks to the same file; d0/l1 can't
* be extracted with --strip-components=2 and the other two
* can. Remember that tar normally stores the first file with
* a body and the other as hardlink entries to the first
* appearance. So the final result depends on the order in
* which these three names get archived. If d0/l1 is first,
* none of the three can be restored. If either of the longer
* names are first, then the two longer ones can both be
* restored. Note that the "tar -cf" command above explicitly
* lists d0/l1 before d0/d1.
*
* It may be worth extending this test to exercise other
* archiving orders.
*
* Of course, this is all totally different for cpio and newc
* formats because the hardlink management is different.
* TODO: Rename this to test_strip_components_tar and create
* parallel tests for cpio and newc formats.
*/
failure("d0/l1 is too short and should not get restored");
assertFileNotExists("target/l1");
failure("d0/d1/l2 is a hardlink to file whose name was too short");
assertFileNotExists("target/l2");
failure("d0/d1/d2/f1 is a hardlink to file whose name was too short");
assertFileNotExists("target/d2/f1");
/*
* Test 2: Strip components when creating archives.
*/
if (canSymlink())
assertEqualInt(0, systemf("%s --strip-components 2 -cf test2.tar "
"d0/l1 d0/s1 d0/d1", testprog));
else
assertEqualInt(0, systemf("%s --strip-components 2 -cf test2.tar "
"d0/l1 d0/d1", testprog));
assertMakeDir("target2", 0755);
assertEqualInt(0, systemf("%s -x -C target2 -f test2.tar", testprog));
failure("d0/ is too short and should not have been archived");
assertFileNotExists("target2/d0");
failure("d0/d1/ is too short and should not have been archived");
assertFileNotExists("target2/d1");
failure("d0/s1 is too short and should not get restored");
assertFileNotExists("target/s1");
/* If platform supports symlinks, target/s2 is included. */
if (canSymlink()) {
failure("d0/d1/s2 is a symlink to something included in archive");
assertIsSymlink("target2/s2", "d2/f1", 0);
}
failure("d0/d1/d2 should be archived");
assertIsDir("target2/d2", -1);
/*
* Test 2b: Strip components creating archives involving hardlinks.
*/
failure("d0/l1 is too short and should not have been archived");
assertFileNotExists("target/l1");
failure("d0/d1/l2 is a hardlink to file whose name was too short");
assertFileNotExists("target/l2");
failure("d0/d1/d2/f1 is a hardlink to file whose name was too short");
assertFileNotExists("target/d2/f1");
}

View file

@ -0,0 +1,160 @@
/*-
* Copyright (c) 2003-2007 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: src/usr.bin/tar/test/test_symlink_dir.c,v 1.1 2008/09/14 02:16:04 kientzle Exp $");
/*
* tar -x -P should follow existing symlinks for dirs, but not other
* content. Plain tar -x should remove symlinks when they're in the
* way of a dir extraction.
*/
DEFINE_TEST(test_symlink_dir)
{
assertUmask(0);
assertMakeDir("source", 0755);
assertMakeFile("source/file", 0755, "a");
assertMakeFile("source/file2", 0755, "ab");
assertMakeDir("source/dir", 0755);
assertMakeDir("source/dir/d", 0755);
assertMakeFile("source/dir/f", 0755, "abc");
assertMakeDir("source/dir2", 0755);
assertMakeDir("source/dir2/d2", 0755);
assertMakeFile("source/dir2/f2", 0755, "abcd");
assertMakeDir("source/dir3", 0755);
assertMakeDir("source/dir3/d3", 0755);
assertMakeFile("source/dir3/f3", 0755, "abcde");
assertMakeDir("source/dir4", 0755);
assertMakeFile("source/dir4/file3", 0755, "abcdef");
assertMakeHardlink("source/dir4/file4", "source/dir4/file3");
assertEqualInt(0,
systemf("%s -cf test.tar -C source dir dir2 dir3 file file2",
testprog));
/* Second archive with hardlinks */
assertEqualInt(0,
systemf("%s -cf test2.tar -C source dir4", testprog));
/*
* Extract with -x and without -P.
*/
assertMakeDir("dest1", 0755);
/* "dir" is a symlink to an existing "dest1/real_dir" */
assertMakeDir("dest1/real_dir", 0755);
if (canSymlink()) {
assertMakeSymlink("dest1/dir", "real_dir", 1);
/* "dir2" is a symlink to a non-existing "real_dir2" */
assertMakeSymlink("dest1/dir2", "real_dir2", 1);
} else {
skipping("Symlinks are not supported on this platform");
}
/* "dir3" is a symlink to an existing "non_dir3" */
assertMakeFile("dest1/non_dir3", 0755, "abcdef");
if (canSymlink())
assertMakeSymlink("dest1/dir3", "non_dir3", 1);
/* "file" is a symlink to existing "real_file" */
assertMakeFile("dest1/real_file", 0755, "abcdefg");
if (canSymlink()) {
assertMakeSymlink("dest1/file", "real_file", 0);
/* "file2" is a symlink to non-existing "real_file2" */
assertMakeSymlink("dest1/file2", "real_file2", 0);
}
assertEqualInt(0, systemf("%s -xf test.tar -C dest1", testprog));
/* dest1/dir symlink should be replaced */
failure("symlink to dir was followed when it shouldn't be");
assertIsDir("dest1/dir", -1);
/* dest1/dir2 symlink should be replaced */
failure("Broken symlink wasn't replaced with dir");
assertIsDir("dest1/dir2", -1);
/* dest1/dir3 symlink should be replaced */
failure("Symlink to non-dir wasn't replaced with dir");
assertIsDir("dest1/dir3", -1);
/* dest1/file symlink should be replaced */
failure("Symlink to existing file should be replaced");
assertIsReg("dest1/file", -1);
/* dest1/file2 symlink should be replaced */
failure("Symlink to non-existing file should be replaced");
assertIsReg("dest1/file2", -1);
/*
* Extract with both -x and -P
*/
assertMakeDir("dest2", 0755);
/* "dir" is a symlink to existing "real_dir" */
assertMakeDir("dest2/real_dir", 0755);
if (canSymlink())
assertMakeSymlink("dest2/dir", "real_dir", 1);
/* "dir2" is a symlink to a non-existing "real_dir2" */
if (canSymlink())
assertMakeSymlink("dest2/dir2", "real_dir2", 1);
/* "dir3" is a symlink to an existing "non_dir3" */
assertMakeFile("dest2/non_dir3", 0755, "abcdefgh");
if (canSymlink())
assertMakeSymlink("dest2/dir3", "non_dir3", 1);
/* "file" is a symlink to existing "real_file" */
assertMakeFile("dest2/real_file", 0755, "abcdefghi");
if (canSymlink())
assertMakeSymlink("dest2/file", "real_file", 0);
/* "file2" is a symlink to non-existing "real_file2" */
if (canSymlink())
assertMakeSymlink("dest2/file2", "real_file2", 0);
assertEqualInt(0, systemf("%s -xPf test.tar -C dest2", testprog));
/* "dir4" is a symlink to existing "real_dir" */
if (canSymlink())
assertMakeSymlink("dest2/dir4", "real_dir", 1);
assertEqualInt(0, systemf("%s -xPf test2.tar -C dest2", testprog));
/* dest2/dir and dest2/dir4 symlinks should be followed */
if (canSymlink()) {
assertIsSymlink("dest2/dir", "real_dir", 1);
assertIsSymlink("dest2/dir4", "real_dir", 1);
assertIsDir("dest2/real_dir", -1);
}
/* Contents of 'dir' should be restored */
assertIsDir("dest2/dir/d", -1);
assertIsReg("dest2/dir/f", -1);
assertFileSize("dest2/dir/f", 3);
/* dest2/dir2 symlink should be removed */
failure("Broken symlink wasn't replaced with dir");
assertIsDir("dest2/dir2", -1);
/* dest2/dir3 symlink should be removed */
failure("Symlink to non-dir wasn't replaced with dir");
assertIsDir("dest2/dir3", -1);
/* dest2/file symlink should be removed;
* even -P shouldn't follow symlinks for files */
failure("Symlink to existing file should be removed");
assertIsReg("dest2/file", -1);
/* dest2/file2 symlink should be removed */
failure("Symlink to non-existing file should be removed");
assertIsReg("dest2/file2", -1);
/* dest2/dir4/file3 and dest2/dir4/file4 should be hard links */
assertIsHardlink("dest2/dir4/file3", "dest2/dir4/file4");
}

View file

@ -0,0 +1,34 @@
/*-
* Copyright (c) 2003-2017 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"
/*
* Test that --version option works and generates reasonable output.
*/
DEFINE_TEST(test_version)
{
assertVersion(testprog, "bsdtar");
}

View file

@ -0,0 +1,324 @@
/*-
* Copyright (c) 2009 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"
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <direct.h>
#include <windows.h>
static void
mkfile(const char *name)
{
FILE *f;
f = fopen(name, "wb");
assert(f != NULL);
assertEqualInt(5, fwrite("01234", 1, 5, f));
fclose(f);
}
static void
mkfullpath(char **path1, char **path2, const char *tpath, int type)
{
char *fp1 = NULL, *fp2 = NULL, *p1 = NULL, *p2 = NULL;
size_t l;
/*
* Get full path name of "tpath"
*/
l = GetFullPathNameA(tpath, 0, NULL, NULL);
assert(0 != l);
fp1 = malloc(l);
assert(NULL != fp1);
fp2 = malloc(l*2);
assert(NULL != fp2);
l = GetFullPathNameA(tpath, (DWORD)l, fp1, NULL);
if ((type & 0x01) == 0) {
for (p1 = fp1; *p1 != '\0'; p1++)
if (*p1 == '\\')
*p1 = '/';
}
switch(type) {
case 0: /* start with "/" */
case 1: /* start with "\" */
/* strip "c:" */
memmove(fp1, fp1 + 2, l - 2);
fp1[l -2] = '\0';
p1 = fp1 + 1;
break;
case 2: /* start with "c:/" */
case 3: /* start with "c:\" */
p1 = fp1 + 3;
break;
case 4: /* start with "//./c:/" */
case 5: /* start with "\\.\c:\" */
case 6: /* start with "//?/c:/" */
case 7: /* start with "\\?\c:\" */
p1 = malloc(l + 4 + 1);
assert(NULL != p1);
if (type & 0x1)
memcpy(p1, "\\\\.\\", 4);
else
memcpy(p1, "//./", 4);
if (type == 6 || type == 7)
p1[2] = '?';
memcpy(p1 + 4, fp1, l);
p1[l + 4] = '\0';
free(fp1);
fp1 = p1;
p1 = fp1 + 7;
break;
}
/*
* Strip leading drive names and converting "\" to "\\"
*/
p2 = fp2;
while (*p1 != '\0') {
if (*p1 == '\\')
*p2 = '/';
else
*p2 = *p1;
++p1;
++p2;
}
*p2++ = '\r';
*p2++ = '\n';
*p2 = '\0';
*path1 = fp1;
*path2 = fp2;
}
static const char *list1[] = {"aaa/", "aaa/file1", "aaa/xxa/", "aaa/xxb/",
"aaa/zzc/", "aaa/zzc/file1", "aaa/xxb/file1", "aaa/xxa/file1",
"aab/", "aac/", "abb/", "abc/", "abd/", NULL};
static const char *list2[] = {"bbb/", "bbb/file1", "bbb/xxa/", "bbb/xxb/",
"bbb/zzc/", "bbb/zzc/file1", "bbb/xxb/file1", "bbb/xxa/file1", "bbc/",
"bbd/", "bcc/", "bcd/", "bce/", NULL};
static const char *list3[] = {"aac/", "abc/", "bbc/", "bcc/", "ccc/", NULL};
static const char *list4[] = {"fff/abca", "fff/acca", NULL};
static const char *list5[] = {"aaa/file1", "aaa/xxa/", "aaa/xxa/file1",
"aaa/xxb/", "aaa/xxb/file1", "aaa/zzc/", "aaa/zzc/file1", NULL};
static const char *list6[] = {"fff/abca", "fff/acca", "aaa/xxa/",
"aaa/xxa/file1", "aaa/xxb/", "aaa/xxb/file1", NULL};
#endif /* _WIN32 && !__CYGWIN__ */
DEFINE_TEST(test_windows)
{
#if defined(_WIN32) && !defined(__CYGWIN__)
char *fp1, *fp2;
/*
* Prepare tests.
* Create directories and files.
*/
assertMakeDir("tmp", 0775);
assertChdir("tmp");
assertMakeDir("aaa", 0775);
assertMakeDir("aaa/xxa", 0775);
assertMakeDir("aaa/xxb", 0775);
assertMakeDir("aaa/zzc", 0775);
mkfile("aaa/file1");
mkfile("aaa/xxa/file1");
mkfile("aaa/xxb/file1");
mkfile("aaa/zzc/file1");
assertMakeDir("aab", 0775);
assertMakeDir("aac", 0775);
assertMakeDir("abb", 0775);
assertMakeDir("abc", 0775);
assertMakeDir("abd", 0775);
assertMakeDir("bbb", 0775);
assertMakeDir("bbb/xxa", 0775);
assertMakeDir("bbb/xxb", 0775);
assertMakeDir("bbb/zzc", 0775);
mkfile("bbb/file1");
mkfile("bbb/xxa/file1");
mkfile("bbb/xxb/file1");
mkfile("bbb/zzc/file1");
assertMakeDir("bbc", 0775);
assertMakeDir("bbd", 0775);
assertMakeDir("bcc", 0775);
assertMakeDir("bcd", 0775);
assertEqualInt(0, _mkdir("bce"));
assertEqualInt(0, _mkdir("ccc"));
assertEqualInt(0, _mkdir("fff"));
mkfile("fff/aaaa");
mkfile("fff/abba");
mkfile("fff/abca");
mkfile("fff/acba");
mkfile("fff/acca");
/*
* Test1: Command line pattern matching.
*/
assertEqualInt(0,
systemf("%s -cf ../archive1.tar a*", testprog));
assertEqualInt(0,
systemf("%s -tf ../archive1.tar > ../list1", testprog));
assertFileContainsLinesAnyOrder("../list1", list1);
assertEqualInt(0,
systemf("%s -cf ../archive2.tar b*", testprog));
assertEqualInt(0,
systemf("%s -tf ../archive2.tar > ../list2", testprog));
assertFileContainsLinesAnyOrder("../list2", list2);
assertEqualInt(0,
systemf("%s -cf ../archive3.tar ??c", testprog));
assertEqualInt(0,
systemf("%s -tf ../archive3.tar > ../list3", testprog));
assertFileContainsLinesAnyOrder("../list3", list3);
assertEqualInt(0,
systemf("%s -cf ../archive3b.tar *c", testprog));
assertEqualInt(0,
systemf("%s -tf ../archive3b.tar > ../list3b", testprog));
assertFileContainsLinesAnyOrder("../list3b", list3);
assertEqualInt(0,
systemf("%s -cf ../archive4.tar fff/a?ca", testprog));
assertEqualInt(0,
systemf("%s -tf ../archive4.tar > ../list4", testprog));
assertFileContainsLinesAnyOrder("../list4", list4);
assertEqualInt(0,
systemf("%s -cf ../archive5.tar aaa\\*", testprog));
assertEqualInt(0,
systemf("%s -tf ../archive5.tar > ../list5", testprog));
assertFileContainsLinesAnyOrder("../list5", list5);
assertEqualInt(0,
systemf("%s -cf ../archive6.tar fff\\a?ca aaa\\xx*", testprog));
assertEqualInt(0,
systemf("%s -tf ../archive6.tar > ../list6", testprog));
assertFileContainsLinesAnyOrder("../list6", list6);
/*
* Test2: Archive the file start with drive letters.
*/
/* Test2a: start with "/" */
mkfullpath(&fp1, &fp2, "aaa/file1", 0);
assertEqualInt(0,
systemf("%s -cf ../archive10.tar %s > ../out10 2> ../err10",
testprog, fp1));
assertEqualInt(0,
systemf("%s -tf ../archive10.tar > ../list10", testprog));
/* Check drive letters have been stripped. */
assertFileContents(fp2, (int)strlen(fp2), "../list10");
free(fp1);
free(fp2);
/* Test2b: start with "\" */
mkfullpath(&fp1, &fp2, "aaa/file1", 1);
assertEqualInt(0,
systemf("%s -cf ../archive11.tar %s > ../out11 2> ../err11",
testprog, fp1));
assertEqualInt(0,
systemf("%s -tf ../archive11.tar > ../list11", testprog));
/* Check drive letters have been stripped. */
assertFileContents(fp2, (int)strlen(fp2), "../list11");
free(fp1);
free(fp2);
/* Test2c: start with "c:/" */
mkfullpath(&fp1, &fp2, "aaa/file1", 2);
assertEqualInt(0,
systemf("%s -cf ../archive12.tar %s > ../out12 2> ../err12",
testprog, fp1));
assertEqualInt(0,
systemf("%s -tf ../archive12.tar > ../list12", testprog));
/* Check drive letters have been stripped. */
assertFileContents(fp2, (int)strlen(fp2), "../list12");
free(fp1);
free(fp2);
/* Test2d: start with "c:\" */
mkfullpath(&fp1, &fp2, "aaa/file1", 3);
assertEqualInt(0,
systemf("%s -cf ../archive13.tar %s > ../out13 2> ../err13",
testprog, fp1));
assertEqualInt(0,
systemf("%s -tf ../archive13.tar > ../list13", testprog));
/* Check drive letters have been stripped. */
assertFileContents(fp2, (int)strlen(fp2), "../list13");
free(fp1);
free(fp2);
/* Test2e: start with "//./c:/" */
mkfullpath(&fp1, &fp2, "aaa/file1", 4);
assertEqualInt(0,
systemf("%s -cf ../archive14.tar %s > ../out14 2> ../err14",
testprog, fp1));
assertEqualInt(0,
systemf("%s -tf ../archive14.tar > ../list14", testprog));
/* Check drive letters have been stripped. */
assertFileContents(fp2, (int)strlen(fp2), "../list14");
free(fp1);
free(fp2);
/* Test2f: start with "\\.\c:\" */
mkfullpath(&fp1, &fp2, "aaa/file1", 5);
assertEqualInt(0,
systemf("%s -cf ../archive15.tar %s > ../out15 2> ../err15",
testprog, fp1));
assertEqualInt(0,
systemf("%s -tf ../archive15.tar > ../list15", testprog));
/* Check drive letters have been stripped. */
assertFileContents(fp2, (int)strlen(fp2), "../list15");
free(fp1);
free(fp2);
/* Test2g: start with "//?/c:/" */
mkfullpath(&fp1, &fp2, "aaa/file1", 6);
failure("fp1=%s, fp2=%s", fp1, fp2);
assertEqualInt(0,
systemf("%s -cf ../archive16.tar %s > ../out16 2> ../err16",
testprog, fp1));
assertEqualInt(0,
systemf("%s -tf ../archive16.tar > ../list16", testprog));
/* Check drive letters have been stripped. */
assertFileContents(fp2, (int)strlen(fp2), "../list16");
free(fp1);
free(fp2);
/* Test2h: start with "\\?\c:\" */
mkfullpath(&fp1, &fp2, "aaa/file1", 7);
failure("fp1=%s, fp2=%s", fp1, fp2);
assertEqualInt(0,
systemf("%s -cf ../archive17.tar %s > ../out17 2> ../err17",
testprog, fp1));
assertEqualInt(0,
systemf("%s -tf ../archive17.tar > ../list17", testprog));
/* Check drive letters have been stripped. */
assertFileContents(fp2, (int)strlen(fp2), "../list17");
free(fp1);
free(fp2);
#else
skipping("Windows specific test");
#endif /* _WIN32 && !__CYGWIN__ */
}