static void passthrough(const char *target) { int r; if (!assertMakeDir(target, 0775)) return; /* * Use cpio passthrough mode to copy files to another directory. */ r = systemf("%s -p %s <filelist >%s/stdout 2>%s/stderr", testprog, target, target, target); failure("Error invoking %s -p", testprog); assertEqualInt(r, 0); assertChdir(target); /* Verify stderr. */ failure("Error invoking %s -p in dir %s", testprog, target); assertTextFileContents("1 block\n", "stderr"); verify_files("passthrough"); assertChdir(".."); }
static void unpack_test(const char *from, const char *options, const char *se) { int r; /* Create a work dir named after the file we're unpacking. */ assertMakeDir(from, 0775); assertChdir(from); /* * Use cpio to unpack the sample archive */ extract_reference_file(from); r = systemf("%s -i %s < %s >unpack.out 2>unpack.err", testprog, options, from); failure("Error invoking %s -i %s < %s", testprog, options, from); assertEqualInt(r, 0); /* Verify that nothing went to stderr. */ if (canSymlink()) { failure("Error invoking %s -i %s < %s", testprog, options, from); assertTextFileContents(se, "unpack.err"); } /* * Verify unpacked files. */ /* Regular file with 2 links. */ assertIsReg("file", 0644); failure("%s", from); assertFileSize("file", 10); assertFileSize("linkfile", 10); failure("%s", from); assertFileNLinks("file", 2); /* Another name for the same file. */ failure("%s", from); assertIsHardlink("linkfile", "file"); assertFileSize("file", 10); assertFileSize("linkfile", 10); /* Symlink */ if (canSymlink()) assertIsSymlink("symlink", "file"); /* dir */ assertIsDir("dir", 0775); assertChdir(".."); }
static void basic_cpio(const char *target, const char *pack_options, const char *unpack_options, const char *se, const char *se2) { int r; if (!assertMakeDir(target, 0775)) return; /* Use the cpio program to create an archive. */ r = systemf("%s -o %s < filelist >%s/archive 2>%s/pack.err", testprog, pack_options, target, target); failure("Error invoking %s -o %s", testprog, pack_options); assertEqualInt(r, 0); assertChdir(target); /* Verify stderr. */ failure("Expected: %s, options=%s", se, pack_options); assertTextFileContents(se, "pack.err"); /* * Use cpio to unpack the archive into another directory. */ r = systemf("%s -i %s< archive >unpack.out 2>unpack.err", testprog, unpack_options); failure("Error invoking %s -i %s", testprog, unpack_options); assertEqualInt(r, 0); /* Verify stderr. */ failure("Error invoking %s -i %s in dir %s", testprog, unpack_options, target); assertTextFileContents(se2, "unpack.err"); verify_files(pack_options); assertChdir(".."); }
static void unpack_test(const char *from, const char *options, const char *se) { struct stat st, st2; #if !defined(_WIN32) || defined(__CYGWIN__) char buff[128]; #endif int r; /* Create a work dir named after the file we're unpacking. */ assertEqualInt(0, mkdir(from, 0775)); chdir(from); /* * Use cpio to unpack the sample archive */ extract_reference_file(from); r = systemf("%s -i %s < %s >unpack.out 2>unpack.err", testprog, options, from); failure("Error invoking %s -i %s < %s", testprog, options, from); assertEqualInt(r, 0); /* Verify that nothing went to stderr. */ failure("Error invoking %s -i %s < %s", testprog, options, from); assertTextFileContents(se, "unpack.err"); /* * Verify unpacked files. */ /* Regular file with 2 links. */ r = lstat("file", &st); failure("Failed to stat file %s/file, errno=%d", from, errno); assertEqualInt(r, 0); if (r == 0) { assert(S_ISREG(st.st_mode)); #if defined(_WIN32) && !defined(__CYGWIN__) assertEqualInt(0600, st.st_mode & 0700); #else assertEqualInt(0644, st.st_mode & 0777); #endif failure("file %s/file", from); assertEqualInt(10, st.st_size); failure("file %s/file", from); assertEqualInt(2, st.st_nlink); } /* Another name for the same file. */ r = lstat("linkfile", &st2); failure("Failed to stat file %s/linkfile, errno=%d", from, errno); assertEqualInt(r, 0); if (r == 0) { assert(S_ISREG(st2.st_mode)); #if defined(_WIN32) && !defined(__CYGWIN__) assertEqualInt(0600, st2.st_mode & 0700); #else assertEqualInt(0644, st2.st_mode & 0777); #endif failure("file %s/file", from); assertEqualInt(10, st2.st_size); failure("file %s/file", from); assertEqualInt(2, st2.st_nlink); failure("file and linkfile should be hardlinked"); assertEqualInt(st.st_dev, st2.st_dev); failure("file %s/file", from); assertEqualInt(st.st_ino, st2.st_ino); } /* Symlink */ r = lstat("symlink", &st); failure("Failed to stat file %s/symlink, errno=%d", from, errno); assertEqualInt(r, 0); #if !defined(_WIN32) || defined(__CYGWIN__) if (r == 0) { failure("symlink should be a symlink; actual mode is %o", st.st_mode); assert(S_ISLNK(st.st_mode)); if (S_ISLNK(st.st_mode)) { r = readlink("symlink", buff, sizeof(buff)); assertEqualInt(r, 4); buff[r] = '\0'; assertEqualString(buff, "file"); } } #endif /* dir */ r = lstat("dir", &st); if (r == 0) { assertEqualInt(r, 0); assert(S_ISDIR(st.st_mode)); #if defined(_WIN32) && !defined(__CYGWIN__) assertEqualInt(0700, st.st_mode & 0700); #else assertEqualInt(0775, st.st_mode & 0777); #endif } chdir(".."); }