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 verify_files(const char *msg) { /* * Verify unpacked files. */ /* Regular file with 2 links. */ failure(msg); assertIsReg("file", 0644); failure(msg); assertFileSize("file", 10); failure(msg); assertFileNLinks("file", 2); /* Another name for the same file. */ failure(msg); assertIsHardlink("linkfile", "file"); /* Symlink */ if (canSymlink()) assertIsSymlink("symlink", "file"); /* Another file with 1 link and different permissions. */ failure(msg); assertIsReg("file2", 0777); failure(msg); assertFileSize("file2", 10); failure(msg); assertFileNLinks("file2", 1); /* dir */ assertIsDir("dir", 0775); }
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_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 -", 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"); /* * Verify unpacked files. */ /* Regular file with 2 links. */ assertIsReg("file", -1); assertFileSize("file", 10); failure("%s", target); assertFileNLinks("file", 2); /* Another name for the same file. */ assertIsReg("linkfile", -1); assertFileSize("linkfile", 10); assertFileNLinks("linkfile", 2); assertIsHardlink("file", "linkfile"); /* Symlink */ if (canSymlink()) assertIsSymlink("symlink", "file"); /* dir */ assertIsDir("dir", 0775); assertChdir(".."); }
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); } /* 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)=%d", strlen(p)); assert(strlen(p) < limit); assertEqualString(p, filenames[strlen(p)]); break; case 'f': case 's': failure("strlen(p)=%d", 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 }