Path: blob/main/contrib/libarchive/cpio/test/test_option_d.c
39507 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2003-2007 Tim Kientzle4* All rights reserved.5*/6#include "test.h"78DEFINE_TEST(test_option_d)9{10int r;1112/*13* Create a file in a directory.14*/15assertMakeDir("dir", 0755);16assertMakeFile("dir/file", 0644, NULL);1718/* Create an archive. */19r = systemf("echo dir/file | %s -o > archive.cpio 2>archive.err", testprog);20assertEqualInt(r, 0);21assertTextFileContents("1 block\n", "archive.err");22assertFileSize("archive.cpio", 512);2324/* Dearchive without -d, this should fail. */25assertMakeDir("without-d", 0755);26assertChdir("without-d");27r = systemf("%s -i < ../archive.cpio >out 2>err", testprog);28assert(r != 0);29assertEmptyFile("out");30/* And the file should not be restored. */31assertFileNotExists("dir/file");3233/* Dearchive with -d, this should succeed. */34assertChdir("..");35assertMakeDir("with-d", 0755);36assertChdir("with-d");37r = systemf("%s -id < ../archive.cpio >out 2>err", testprog);38assertEqualInt(r, 0);39assertEmptyFile("out");40assertTextFileContents("1 block\n", "err");41/* And the file should be restored. */42assertFileExists("dir/file");43}444546