Blame cpio/test/test_passthrough_reverse.c

Packit 08bd4c
/*-
Packit 08bd4c
 * Copyright (c) 2003-2007 Tim Kientzle
Packit 08bd4c
 * All rights reserved.
Packit 08bd4c
 *
Packit 08bd4c
 * Redistribution and use in source and binary forms, with or without
Packit 08bd4c
 * modification, are permitted provided that the following conditions
Packit 08bd4c
 * are met:
Packit 08bd4c
 * 1. Redistributions of source code must retain the above copyright
Packit 08bd4c
 *    notice, this list of conditions and the following disclaimer.
Packit 08bd4c
 * 2. Redistributions in binary form must reproduce the above copyright
Packit 08bd4c
 *    notice, this list of conditions and the following disclaimer in the
Packit 08bd4c
 *    documentation and/or other materials provided with the distribution.
Packit 08bd4c
 *
Packit 08bd4c
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
Packit 08bd4c
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Packit 08bd4c
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Packit 08bd4c
 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
Packit 08bd4c
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
Packit 08bd4c
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit 08bd4c
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit 08bd4c
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit 08bd4c
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
Packit 08bd4c
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 08bd4c
 */
Packit 08bd4c
#include "test.h"
Packit 08bd4c
__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_passthrough_reverse.c,v 1.2 2008/08/24 06:21:00 kientzle Exp $");
Packit 08bd4c
Packit 08bd4c
/*
Packit 08bd4c
 * As reported by Bernd Walter:  Some people are in the habit of
Packit 08bd4c
 * using "find -d" to generate a list for cpio -p because that
Packit 08bd4c
 * copies the top-level dir last, which preserves owner and mode
Packit 08bd4c
 * information.  That's not necessary for bsdcpio (libarchive defers
Packit 08bd4c
 * restoring directory information), but bsdcpio should still generate
Packit 08bd4c
 * the correct results with this usage.
Packit 08bd4c
 */
Packit 08bd4c
Packit 08bd4c
DEFINE_TEST(test_passthrough_reverse)
Packit 08bd4c
{
Packit 08bd4c
	int r;
Packit 08bd4c
	FILE *filelist;
Packit 08bd4c
Packit 08bd4c
	assertUmask(0);
Packit 08bd4c
Packit 08bd4c
	/*
Packit 08bd4c
	 * Create an assortment of files on disk.
Packit 08bd4c
	 */
Packit 08bd4c
	filelist = fopen("filelist", "w");
Packit 08bd4c
Packit 08bd4c
	/* Directory. */
Packit 08bd4c
	assertMakeDir("dir", 0743);
Packit 08bd4c
Packit 08bd4c
	/* File with 10 bytes content. */
Packit 08bd4c
	assertMakeFile("dir/file", 0644, "1234567890");
Packit 08bd4c
	fprintf(filelist, "dir/file\n");
Packit 08bd4c
Packit 08bd4c
	/* Write dir last. */
Packit 08bd4c
	fprintf(filelist, "dir\n");
Packit 08bd4c
Packit 08bd4c
	/* All done. */
Packit 08bd4c
	fclose(filelist);
Packit 08bd4c
Packit 08bd4c
Packit 08bd4c
	/*
Packit 08bd4c
	 * Use cpio passthrough mode to copy files to another directory.
Packit 08bd4c
	 */
Packit 08bd4c
	r = systemf("%s -pdvm out <filelist >stdout 2>stderr", testprog);
Packit 08bd4c
	failure("Error invoking %s -pd out", testprog);
Packit 08bd4c
	assertEqualInt(r, 0);
Packit 08bd4c
Packit 08bd4c
	assertChdir("out");
Packit 08bd4c
Packit 08bd4c
	/* Verify stderr and stdout. */
Packit 08bd4c
	assertTextFileContents("out/dir/file\nout/dir\n1 block\n",
Packit 08bd4c
	    "../stderr");
Packit 08bd4c
	assertEmptyFile("../stdout");
Packit 08bd4c
Packit 08bd4c
	/* dir */
Packit 08bd4c
	assertIsDir("dir", 0743);
Packit 08bd4c
Packit 08bd4c
Packit 08bd4c
	/* Regular file. */
Packit 08bd4c
	assertIsReg("dir/file", 0644);
Packit 08bd4c
	assertFileSize("dir/file", 10);
Packit 08bd4c
	assertFileNLinks("dir/file", 1);
Packit 08bd4c
}