1 /*- 2 * Copyright (c) 2018 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Arshan Khanifar <arshankhanifar@gmail.com> 6 * under sponsorship from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 #include "test.h" 29 30 DEFINE_TEST(test_option_C_mtree) 31 { 32 char *p0; 33 size_t s; 34 int r; 35 p0 = NULL; 36 char *content = "./foo type=file uname=root gname=root mode=0755\n"; 37 char *filename = "output.tar"; 38 #if defined(_WIN32) && !defined(CYGWIN) 39 char *p; 40 #endif 41 42 /* an absolute path to mtree file */ 43 char *mtree_file = "/METALOG.mtree"; 44 char *absolute_path = malloc(strlen(testworkdir) + strlen(mtree_file) + 1); 45 strcpy(absolute_path, testworkdir); 46 strcat(absolute_path, mtree_file ); 47 48 /* Create an archive using an mtree file. */ 49 assertMakeFile(absolute_path, 0777, content); 50 assertMakeDir("bar", 0775); 51 assertMakeFile("bar/foo", 0777, "abc"); 52 53 #if defined(_WIN32) && !defined(CYGWIN) 54 p = absolute_path; 55 while(*p != '\0') { 56 if (*p == '/') 57 *p = '\\'; 58 p++; 59 } 60 61 r = systemf("%s -cf %s -C bar @%s >step1.out 2>step1.err", testprog, filename, absolute_path); 62 failure("Error invoking %s -cf %s -C bar @%s", testprog, filename, absolute_path); 63 #else 64 r = systemf("%s -cf %s -C bar \"@%s\" >step1.out 2>step1.err", testprog, filename, absolute_path); 65 failure("Error invoking %s -cf %s -C bar \"@%s\"", testprog, filename, absolute_path); 66 #endif 67 68 assertEqualInt(r, 0); 69 assertEmptyFile("step1.out"); 70 assertEmptyFile("step1.err"); 71 72 /* Do validation of the constructed archive. */ 73 74 p0 = slurpfile(&s, "output.tar"); 75 if (!assert(p0 != NULL)) 76 goto done; 77 if (!assert(s >= 2048)) 78 goto done; 79 assertEqualMem(p0 + 0, "./foo", 5); 80 assertEqualMem(p0 + 512, "abc", 3); 81 assertEqualMem(p0 + 1024, "\0\0\0\0\0\0\0\0", 8); 82 assertEqualMem(p0 + 1536, "\0\0\0\0\0\0\0\0", 8); 83 done: 84 free(p0); 85 free(absolute_path); 86 } 87 88 89