diff options
Diffstat (limited to 'contrib/libarchive/tar/test')
29 files changed, 2496 insertions, 435 deletions
diff --git a/contrib/libarchive/tar/test/main.c b/contrib/libarchive/tar/test/main.c index bd1db1d..798b4e0 100644 --- a/contrib/libarchive/tar/test/main.c +++ b/contrib/libarchive/tar/test/main.c @@ -24,8 +24,18 @@ */ #include "test.h" +#ifdef HAVE_SYS_TIME_H +#include <sys/time.h> +#endif #include <errno.h> +#ifdef HAVE_ICONV_H +#include <iconv.h> +#endif +#include <limits.h> #include <locale.h> +#ifdef HAVE_SIGNAL_H +#include <signal.h> +#endif #include <stdarg.h> #include <time.h> @@ -40,8 +50,10 @@ __FBSDID("$FreeBSD$"); #define KNOWNREF "test_patterns_2.tar.uu" #define ENVBASE "BSDTAR" /* Prefix for environment variables. */ #define PROGRAM "bsdtar" /* Name of program being tested. */ -#undef LIBRARY /* Not testing a library. */ -#undef EXTRA_DUMP /* How to dump extra data */ +#define PROGRAM_ALIAS "tar" /* Generic alias for program */ +#undef LIBRARY /* Not testing a library. */ +#undef EXTRA_DUMP /* How to dump extra data */ +#undef EXTRA_ERRNO /* How to dump errno */ /* How to generate extra version info. */ #define EXTRA_VERSION (systemf("%s --version", testprog) ? "" : "") @@ -151,7 +163,7 @@ my_GetFileInformationByName(const char *path, BY_HANDLE_FILE_INFORMATION *bhfi) memset(bhfi, 0, sizeof(*bhfi)); h = CreateFile(path, FILE_READ_ATTRIBUTES, 0, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (h == INVALID_HANDLE_VALUE) return (0); r = GetFileInformationByHandle(h, bhfi); @@ -180,6 +192,8 @@ invalid_parameter_handler(const wchar_t * expression, static int dump_on_failure = 0; /* Default is to remove temp dirs and log data for successful tests. */ static int keep_temp_files = 0; +/* Default is to run the specified tests once and report errors. */ +static int until_failure = 0; /* Default is to just report pass/fail for each test. */ static int verbosity = 0; #define VERBOSITY_SUMMARY_ONLY -1 /* -q */ @@ -237,10 +251,14 @@ void failure(const char *fmt, ...) { va_list ap; - va_start(ap, fmt); - vsprintf(msgbuff, fmt, ap); - va_end(ap); - nextmsg = msgbuff; + if (fmt == NULL) { + nextmsg = NULL; + } else { + va_start(ap, fmt); + vsprintf(msgbuff, fmt, ap); + va_end(ap); + nextmsg = msgbuff; + } } /* @@ -252,15 +270,14 @@ failure(const char *fmt, ...) * pass __FILE__, __LINE__ directly into the function instead of using * this hook. I suspect this machinery is used so rarely that we * would be better off just removing it entirely. That would simplify - * the code here noticably. + * the code here noticeably. */ -static const char *test_filename; -static int test_line; -static void *test_extra; -void assertion_setup(const char *filename, int line) +static const char *skipping_filename; +static int skipping_line; +void skipping_setup(const char *filename, int line) { - test_filename = filename; - test_line = line; + skipping_filename = filename; + skipping_line = line; } /* Called at the beginning of each assert() function. */ @@ -287,6 +304,7 @@ static struct line { int count; int skip; } failed_lines[10000]; +const char *failed_filename; /* Count this failure, setup up log destination and handle initial report. */ static void @@ -296,19 +314,16 @@ failure_start(const char *filename, int line, const char *fmt, ...) /* Record another failure for this line. */ ++failures; - /* test_filename = filename; */ + failed_filename = filename; failed_lines[line].count++; /* Determine whether to log header to console. */ switch (verbosity) { - case VERBOSITY_FULL: - log_console = 1; - break; case VERBOSITY_LIGHT_REPORT: log_console = (failed_lines[line].count < 2); break; default: - log_console = 0; + log_console = (verbosity >= VERBOSITY_FULL); } /* Log file:line header for this failure */ @@ -344,14 +359,16 @@ failure_finish(void *extra) { (void)extra; /* UNUSED (maybe) */ #ifdef EXTRA_DUMP - if (extra != NULL) + if (extra != NULL) { + logprintf(" errno: %d\n", EXTRA_ERRNO(extra)); logprintf(" detail: %s\n", EXTRA_DUMP(extra)); + } #endif if (dump_on_failure) { fprintf(stderr, " *** forcing core dump so failure can be debugged ***\n"); - *(char *)(NULL) = 0; + abort(); exit(1); } } @@ -366,12 +383,15 @@ test_skipping(const char *fmt, ...) va_start(ap, fmt); vsprintf(buff, fmt, ap); va_end(ap); + /* Use failure() message if set. */ + msg = nextmsg; + nextmsg = NULL; /* failure_start() isn't quite right, but is awfully convenient. */ - failure_start(test_filename, test_line, "SKIPPING: %s", buff); + failure_start(skipping_filename, skipping_line, "SKIPPING: %s", buff); --failures; /* Undo failures++ in failure_start() */ /* Don't failure_finish() here. */ /* Mark as skip, so doesn't count as failed test. */ - failed_lines[test_line].skip = 1; + failed_lines[skipping_line].skip = 1; ++skips; } @@ -422,13 +442,102 @@ assertion_equal_int(const char *file, int line, return (0); } -static void strdump(const char *e, const char *p) +/* + * Utility to convert a single UTF-8 sequence. + */ +static int +_utf8_to_unicode(uint32_t *pwc, const char *s, size_t n) +{ + static const char utf8_count[256] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 00 - 0F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 10 - 1F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 20 - 2F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 30 - 3F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 40 - 4F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 50 - 5F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 60 - 6F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 70 - 7F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 80 - 8F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 90 - 9F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* A0 - AF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* B0 - BF */ + 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,/* C0 - CF */ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,/* D0 - DF */ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,/* E0 - EF */ + 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* F0 - FF */ + }; + int ch; + int cnt; + uint32_t wc; + + *pwc = 0; + + /* Sanity check. */ + if (n == 0) + return (0); + /* + * Decode 1-4 bytes depending on the value of the first byte. + */ + ch = (unsigned char)*s; + if (ch == 0) + return (0); /* Standard: return 0 for end-of-string. */ + cnt = utf8_count[ch]; + + /* Invalide sequence or there are not plenty bytes. */ + if (n < (size_t)cnt) + return (-1); + + /* Make a Unicode code point from a single UTF-8 sequence. */ + switch (cnt) { + case 1: /* 1 byte sequence. */ + *pwc = ch & 0x7f; + return (cnt); + case 2: /* 2 bytes sequence. */ + if ((s[1] & 0xc0) != 0x80) return (-1); + *pwc = ((ch & 0x1f) << 6) | (s[1] & 0x3f); + return (cnt); + case 3: /* 3 bytes sequence. */ + if ((s[1] & 0xc0) != 0x80) return (-1); + if ((s[2] & 0xc0) != 0x80) return (-1); + wc = ((ch & 0x0f) << 12) + | ((s[1] & 0x3f) << 6) + | (s[2] & 0x3f); + if (wc < 0x800) + return (-1);/* Overlong sequence. */ + break; + case 4: /* 4 bytes sequence. */ + if (n < 4) + return (-1); + if ((s[1] & 0xc0) != 0x80) return (-1); + if ((s[2] & 0xc0) != 0x80) return (-1); + if ((s[3] & 0xc0) != 0x80) return (-1); + wc = ((ch & 0x07) << 18) + | ((s[1] & 0x3f) << 12) + | ((s[2] & 0x3f) << 6) + | (s[3] & 0x3f); + if (wc < 0x10000) + return (-1);/* Overlong sequence. */ + break; + default: + return (-1); + } + + /* The code point larger than 0x10FFFF is not leagal + * Unicode values. */ + if (wc > 0x10FFFF) + return (-1); + /* Correctly gets a Unicode, returns used bytes. */ + *pwc = wc; + return (cnt); +} + +static void strdump(const char *e, const char *p, int ewidth, int utf8) { const char *q = p; - logprintf(" %s = ", e); + logprintf(" %*s = ", ewidth, e); if (p == NULL) { - logprintf("NULL"); + logprintf("NULL\n"); return; } logprintf("\""); @@ -447,7 +556,37 @@ static void strdump(const char *e, const char *p) } } logprintf("\""); - logprintf(" (length %d)\n", q == NULL ? -1 : (int)strlen(q)); + logprintf(" (length %d)", q == NULL ? -1 : (int)strlen(q)); + + /* + * If the current string is UTF-8, dump its code points. + */ + if (utf8) { + size_t len; + uint32_t uc; + int n; + int cnt = 0; + + p = q; + len = strlen(p); + logprintf(" ["); + while ((n = _utf8_to_unicode(&uc, p, len)) > 0) { + if (p != q) + logprintf(" "); + logprintf("%04X", uc); + p += n; + len -= n; + cnt++; + } + logprintf("]"); + logprintf(" (count %d", cnt); + if (n < 0) { + logprintf(",unknown %d bytes", len); + } + logprintf(")"); + + } + logprintf("\n"); } /* Verify two strings are equal, dump them if not. */ @@ -455,14 +594,20 @@ int assertion_equal_string(const char *file, int line, const char *v1, const char *e1, const char *v2, const char *e2, - void *extra) + void *extra, int utf8) { + int l1, l2; + assertion_count(file, line); if (v1 == v2 || (v1 != NULL && v2 != NULL && strcmp(v1, v2) == 0)) return (1); failure_start(file, line, "%s != %s", e1, e2); - strdump(e1, v1); - strdump(e2, v2); + l1 = strlen(e1); + l2 = strlen(e2); + if (l1 < l2) + l1 = l2; + strdump(e1, v1, l1, utf8); + strdump(e2, v2, l1, utf8); failure_finish(extra); return (0); } @@ -514,7 +659,9 @@ assertion_equal_wstring(const char *file, int line, void *extra) { assertion_count(file, line); - if (v1 == v2 || wcscmp(v1, v2) == 0) + if (v1 == v2) + return (1); + if (v1 != NULL && v2 != NULL && wcscmp(v1, v2) == 0) return (1); failure_start(file, line, "%s != %s", e1, e2); wcsdump(e1, v1); @@ -593,9 +740,9 @@ assertion_equal_mem(const char *file, int line, offset += 16; } logprintf(" Dump of %s\n", e1); - hexdump(v1, v2, l < 64 ? l : 64, offset); + hexdump(v1, v2, l < 128 ? l : 128, offset); logprintf(" Dump of %s\n", e2); - hexdump(v2, v1, l < 64 ? l : 64, offset); + hexdump(v2, v1, l < 128 ? l : 128, offset); logprintf("\n"); failure_finish(extra); return (0); @@ -603,29 +750,24 @@ assertion_equal_mem(const char *file, int line, /* Verify that the named file exists and is empty. */ int -assertion_empty_file(const char *f1fmt, ...) +assertion_empty_file(const char *filename, int line, const char *f1) { char buff[1024]; - char f1[1024]; struct stat st; - va_list ap; ssize_t s; FILE *f; - assertion_count(test_filename, test_line); - va_start(ap, f1fmt); - vsprintf(f1, f1fmt, ap); - va_end(ap); + assertion_count(filename, line); if (stat(f1, &st) != 0) { - failure_start(test_filename, test_line, "Stat failed: %s", f1); + failure_start(filename, line, "Stat failed: %s", f1); failure_finish(NULL); return (0); } if (st.st_size == 0) return (1); - failure_start(test_filename, test_line, "File should be empty: %s", f1); + failure_start(filename, line, "File should be empty: %s", f1); logprintf(" File size: %d\n", (int)st.st_size); logprintf(" Contents:\n"); f = fopen(f1, "rb"); @@ -644,24 +786,19 @@ assertion_empty_file(const char *f1fmt, ...) /* Verify that the named file exists and is not empty. */ int -assertion_non_empty_file(const char *f1fmt, ...) +assertion_non_empty_file(const char *filename, int line, const char *f1) { - char f1[1024]; struct stat st; - va_list ap; - assertion_count(test_filename, test_line); - va_start(ap, f1fmt); - vsprintf(f1, f1fmt, ap); - va_end(ap); + assertion_count(filename, line); if (stat(f1, &st) != 0) { - failure_start(test_filename, test_line, "Stat failed: %s", f1); + failure_start(filename, line, "Stat failed: %s", f1); failure_finish(NULL); return (0); } if (st.st_size == 0) { - failure_start(test_filename, test_line, "File empty: %s", f1); + failure_start(filename, line, "File empty: %s", f1); failure_finish(NULL); return (0); } @@ -671,19 +808,14 @@ assertion_non_empty_file(const char *f1fmt, ...) /* Verify that two files have the same contents. */ /* TODO: hexdump the first bytes that actually differ. */ int -assertion_equal_file(const char *fn1, const char *f2pattern, ...) +assertion_equal_file(const char *filename, int line, const char *fn1, const char *fn2) { - char fn2[1024]; - va_list ap; char buff1[1024]; char buff2[1024]; FILE *f1, *f2; int n1, n2; - assertion_count(test_filename, test_line); - va_start(ap, f2pattern); - vsprintf(fn2, f2pattern, ap); - va_end(ap); + assertion_count(filename, line); f1 = fopen(fn1, "rb"); f2 = fopen(fn2, "rb"); @@ -702,24 +834,18 @@ assertion_equal_file(const char *fn1, const char *f2pattern, ...) } fclose(f1); fclose(f2); - failure_start(test_filename, test_line, "Files not identical"); + failure_start(filename, line, "Files not identical"); logprintf(" file1=\"%s\"\n", fn1); logprintf(" file2=\"%s\"\n", fn2); - failure_finish(test_extra); + failure_finish(NULL); return (0); } /* Verify that the named file does exist. */ int -assertion_file_exists(const char *fpattern, ...) +assertion_file_exists(const char *filename, int line, const char *f) { - char f[1024]; - va_list ap; - - assertion_count(test_filename, test_line); - va_start(ap, fpattern); - vsprintf(f, fpattern, ap); - va_end(ap); + assertion_count(filename, line); #if defined(_WIN32) && !defined(__CYGWIN__) if (!_access(f, 0)) @@ -728,22 +854,16 @@ assertion_file_exists(const char *fpattern, ...) if (!access(f, F_OK)) return (1); #endif - failure_start(test_filename, test_line, "File should exist: %s", f); - failure_finish(test_extra); + failure_start(filename, line, "File should exist: %s", f); + failure_finish(NULL); return (0); } /* Verify that the named file doesn't exist. */ int -assertion_file_not_exists(const char *fpattern, ...) +assertion_file_not_exists(const char *filename, int line, const char *f) { - char f[1024]; - va_list ap; - - assertion_count(test_filename, test_line); - va_start(ap, fpattern); - vsprintf(f, fpattern, ap); - va_end(ap); + assertion_count(filename, line); #if defined(_WIN32) && !defined(__CYGWIN__) if (_access(f, 0)) @@ -752,31 +872,26 @@ assertion_file_not_exists(const char *fpattern, ...) if (access(f, F_OK)) return (1); #endif - failure_start(test_filename, test_line, "File should not exist: %s", f); - failure_finish(test_extra); + failure_start(filename, line, "File should not exist: %s", f); + failure_finish(NULL); return (0); } /* Compare the contents of a file to a block of memory. */ int -assertion_file_contents(const void *buff, int s, const char *fpattern, ...) +assertion_file_contents(const char *filename, int line, const void *buff, int s, const char *fn) { - char fn[1024]; - va_list ap; char *contents; FILE *f; int n; - assertion_count(test_filename, test_line); - va_start(ap, fpattern); - vsprintf(fn, fpattern, ap); - va_end(ap); + assertion_count(filename, line); f = fopen(fn, "rb"); if (f == NULL) { - failure_start(test_filename, test_line, + failure_start(filename, line, "File should exist: %s", fn); - failure_finish(test_extra); + failure_finish(NULL); return (0); } contents = malloc(s * 2); @@ -786,7 +901,7 @@ assertion_file_contents(const void *buff, int s, const char *fpattern, ...) free(contents); return (1); } - failure_start(test_filename, test_line, "File contents don't match"); + failure_start(filename, line, "File contents don't match"); logprintf(" file=\"%s\"\n", fn); if (n > 0) hexdump(contents, buff, n > 512 ? 512 : n, 0); @@ -794,22 +909,28 @@ assertion_file_contents(const void *buff, int s, const char *fpattern, ...) logprintf(" File empty, contents should be:\n"); hexdump(buff, NULL, s > 512 ? 512 : s, 0); } - failure_finish(test_extra); + failure_finish(NULL); free(contents); return (0); } /* Check the contents of a text file, being tolerant of line endings. */ int -assertion_text_file_contents(const char *buff, const char *fn) +assertion_text_file_contents(const char *filename, int line, const char *buff, const char *fn) { char *contents; const char *btxt, *ftxt; FILE *f; int n, s; - assertion_count(test_filename, test_line); + assertion_count(filename, line); f = fopen(fn, "r"); + if (f == NULL) { + failure_start(filename, line, + "File doesn't exist: %s", fn); + failure_finish(NULL); + return (0); + } s = strlen(buff); contents = malloc(s * 2 + 128); n = fread(contents, 1, s * 2 + 128 - 1, f); @@ -837,15 +958,17 @@ assertion_text_file_contents(const char *buff, const char *fn) free(contents); return (1); } - failure_start(test_filename, test_line, "Contents don't match"); + failure_start(filename, line, "Contents don't match"); logprintf(" file=\"%s\"\n", fn); - if (n > 0) + if (n > 0) { hexdump(contents, buff, n, 0); - else { + logprintf(" expected\n", fn); + hexdump(buff, contents, s, 0); + } else { logprintf(" File empty, contents should be:\n"); hexdump(buff, NULL, s, 0); } - failure_finish(test_extra); + failure_finish(NULL); free(contents); return (0); } @@ -875,7 +998,7 @@ assertion_file_contains_lines_any_order(const char *file, int line, return (0); } - // Make a copy of the provided lines and count up the expected file size. + /* Make a copy of the provided lines and count up the expected file size. */ expected_count = 0; for (i = 0; lines[i] != NULL; ++i) { } @@ -885,7 +1008,7 @@ assertion_file_contains_lines_any_order(const char *file, int line, expected[i] = strdup(lines[i]); } - // Break the file into lines + /* Break the file into lines */ actual_count = 0; for (c = '\0', p = buff; p < buff + buff_size; ++p) { if (*p == '\x0d' || *p == '\x0a') @@ -902,7 +1025,7 @@ assertion_file_contains_lines_any_order(const char *file, int line, } } - // Erase matching lines from both lists + /* Erase matching lines from both lists */ for (i = 0; i < expected_count; ++i) { if (expected[i] == NULL) continue; @@ -918,7 +1041,7 @@ assertion_file_contains_lines_any_order(const char *file, int line, } } - // If there's anything left, it's a failure + /* If there's anything left, it's a failure */ for (i = 0; i < expected_count; ++i) { if (expected[i] != NULL) ++expected_failure; @@ -1040,8 +1163,11 @@ assertion_file_time(const char *file, int line, ftime.dwHighDateTime = 0; assertion_count(file, line); + /* Note: FILE_FLAG_BACKUP_SEMANTICS applies to open + * a directory file. If not, CreateFile() will fail when + * the pathname is a directory. */ h = CreateFile(pathname, FILE_READ_ATTRIBUTES, 0, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (h == INVALID_HANDLE_VALUE) { failure_start(file, line, "Can't access %s\n", pathname); failure_finish(NULL); @@ -1106,14 +1232,14 @@ assertion_file_time(const char *file, int line, time_t now = time(NULL); if (filet < now - 10 || filet > now + 1) { failure_start(file, line, - "File %s has %ctime %ld, %ld seconds ago\n", + "File %s has %ctime %lld, %lld seconds ago\n", pathname, type, filet, now - filet); failure_finish(NULL); return (0); } } else if (filet != t || filet_nsec != nsec) { failure_start(file, line, - "File %s has %ctime %ld.%09ld, expected %ld.%09ld", + "File %s has %ctime %lld.%09lld, expected %lld.%09lld", pathname, type, filet, filet_nsec, t, nsec); failure_finish(NULL); return (0); @@ -1190,7 +1316,7 @@ assertion_file_nlinks(const char *file, int line, assertion_count(file, line); r = lstat(pathname, &st); - if (r == 0 && st.st_nlink == nlinks) + if (r == 0 && (int)st.st_nlink == nlinks) return (1); failure_start(file, line, "File %s has %d links, expected %d", pathname, st.st_nlink, nlinks); @@ -1254,7 +1380,7 @@ assertion_is_dir(const char *file, int line, const char *pathname, int mode) /* Windows doesn't handle permissions the same way as POSIX, * so just ignore the mode tests. */ /* TODO: Can we do better here? */ - if (mode >= 0 && mode != (st.st_mode & 07777)) { + if (mode >= 0 && (mode_t)mode != (st.st_mode & 07777)) { failure_start(file, line, "Dir %s has wrong mode", pathname); logprintf(" Expected: 0%3o\n", mode); logprintf(" Found: 0%3o\n", st.st_mode & 07777); @@ -1287,7 +1413,7 @@ assertion_is_reg(const char *file, int line, const char *pathname, int mode) /* Windows doesn't handle permissions the same way as POSIX, * so just ignore the mode tests. */ /* TODO: Can we do better here? */ - if (mode >= 0 && mode != (st.st_mode & 07777)) { + if (mode >= 0 && (mode_t)mode != (st.st_mode & 07777)) { failure_start(file, line, "File %s has wrong mode", pathname); logprintf(" Expected: 0%3o\n", mode); logprintf(" Found: 0%3o\n", st.st_mode & 07777); @@ -1486,6 +1612,110 @@ assertion_umask(const char *file, int line, int mask) return (1); } +/* Set times, report failures. */ +int +assertion_utimes(const char *file, int line, + const char *pathname, long at, long at_nsec, long mt, long mt_nsec) +{ + int r; + +#if defined(_WIN32) && !defined(__CYGWIN__) +#define WINTIME(sec, nsec) ((Int32x32To64(sec, 10000000) + EPOC_TIME)\ + + (((nsec)/1000)*10)) + HANDLE h; + ULARGE_INTEGER wintm; + FILETIME fatime, fmtime; + FILETIME *pat, *pmt; + + assertion_count(file, line); + h = CreateFileA(pathname,GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, NULL); + if (h == INVALID_HANDLE_VALUE) { + failure_start(file, line, "Can't access %s\n", pathname); + failure_finish(NULL); + return (0); + } + + if (at > 0 || at_nsec > 0) { + wintm.QuadPart = WINTIME(at, at_nsec); + fatime.dwLowDateTime = wintm.LowPart; + fatime.dwHighDateTime = wintm.HighPart; + pat = &fatime; + } else + pat = NULL; + if (mt > 0 || mt_nsec > 0) { + wintm.QuadPart = WINTIME(mt, mt_nsec); + fmtime.dwLowDateTime = wintm.LowPart; + fmtime.dwHighDateTime = wintm.HighPart; + pmt = &fmtime; + } else + pmt = NULL; + if (pat != NULL || pmt != NULL) + r = SetFileTime(h, NULL, pat, pmt); + else + r = 1; + CloseHandle(h); + if (r == 0) { + failure_start(file, line, "Can't SetFileTime %s\n", pathname); + failure_finish(NULL); + return (0); + } + return (1); +#else /* defined(_WIN32) && !defined(__CYGWIN__) */ + struct stat st; + struct timeval times[2]; + +#if !defined(__FreeBSD__) + mt_nsec = at_nsec = 0; /* Generic POSIX only has whole seconds. */ +#endif + if (mt == 0 && mt_nsec == 0 && at == 0 && at_nsec == 0) + return (1); + + r = lstat(pathname, &st); + if (r < 0) { + failure_start(file, line, "Can't stat %s\n", pathname); + failure_finish(NULL); + return (0); + } + + if (mt == 0 && mt_nsec == 0) { + mt = st.st_mtime; +#if defined(__FreeBSD__) + mt_nsec = st.st_mtimespec.tv_nsec; + /* FreeBSD generally only stores to microsecond res, so round. */ + mt_nsec = (mt_nsec / 1000) * 1000; +#endif + } + if (at == 0 && at_nsec == 0) { + at = st.st_atime; +#if defined(__FreeBSD__) + at_nsec = st.st_atimespec.tv_nsec; + /* FreeBSD generally only stores to microsecond res, so round. */ + at_nsec = (at_nsec / 1000) * 1000; +#endif + } + + times[1].tv_sec = mt; + times[1].tv_usec = mt_nsec / 1000; + + times[0].tv_sec = at; + times[0].tv_usec = at_nsec / 1000; + +#ifdef HAVE_LUTIMES + r = lutimes(pathname, times); +#else + r = utimes(pathname, times); +#endif + if (r < 0) { + failure_start(file, line, "Can't utimes %s\n", pathname); + failure_finish(NULL); + return (0); + } + return (1); +#endif /* defined(_WIN32) && !defined(__CYGWIN__) */ +} + /* * * UTILITIES for use by tests. @@ -1711,6 +1941,27 @@ extract_reference_file(const char *name) fclose(in); } +int +is_LargeInode(const char *file) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + BY_HANDLE_FILE_INFORMATION bhfi; + int r; + + r = my_GetFileInformationByName(file, &bhfi); + if (r != 0) + return (0); + return (bhfi.nFileIndexHigh & 0x0000FFFFUL); +#else + struct stat st; + int64_t ino; + + if (stat(file, &st) < 0) + return (0); + ino = (int64_t)st.st_ino; + return (ino > 0xffffffff); +#endif +} /* * * TEST management @@ -1740,7 +1991,7 @@ struct { void (*func)(void); const char *name; int failures; } tests[] = { * Summarize repeated failures in the just-completed test. */ static void -test_summarize(const char *filename, int failed) +test_summarize(int failed) { unsigned int i; @@ -1759,9 +2010,10 @@ test_summarize(const char *filename, int failed) for (i = 0; i < sizeof(failed_lines)/sizeof(failed_lines[0]); i++) { if (failed_lines[i].count > 1 && !failed_lines[i].skip) logprintf("%s:%d: Summary: Failed %d times\n", - filename, i, failed_lines[i].count); + failed_filename, i, failed_lines[i].count); } /* Clear the failure history for the next file. */ + failed_filename = NULL; memset(failed_lines, 0, sizeof(failed_lines)); } @@ -1771,6 +2023,7 @@ test_summarize(const char *filename, int failed) static int test_run(int i, const char *tmpdir) { + char workdir[1024]; char logfilename[64]; int failures_before = failures; int oldumask; @@ -1797,11 +2050,12 @@ test_run(int i, const char *tmpdir) logfile = fopen(logfilename, "w"); fprintf(logfile, "%s\n\n", tests[i].name); /* Chdir() to a work dir for this specific test. */ - if (!assertMakeDir(tests[i].name, 0755) - || !assertChdir(tests[i].name)) { + snprintf(workdir, sizeof(workdir), "%s/%s", tmpdir, tests[i].name); + testworkdir = workdir; + if (!assertMakeDir(testworkdir, 0755) + || !assertChdir(testworkdir)) { fprintf(stderr, - "ERROR: Can't chdir to work dir %s/%s\n", - tmpdir, tests[i].name); + "ERROR: Can't chdir to work dir %s\n", testworkdir); exit(1); } /* Explicitly reset the locale before each test. */ @@ -1815,6 +2069,7 @@ test_run(int i, const char *tmpdir) /* * Clean up and report afterwards. */ + testworkdir = NULL; /* Restore umask */ umask(oldumask); /* Reset locale. */ @@ -1827,7 +2082,7 @@ test_run(int i, const char *tmpdir) } /* Report per-test summaries. */ tests[i].failures = failures - failures_before; - test_summarize(test_filename, tests[i].failures); + test_summarize(tests[i].failures); /* Close the per-test log file. */ fclose(logfile); logfile = NULL; @@ -1887,6 +2142,7 @@ usage(const char *program) printf(" -q Quiet.\n"); printf(" -r <dir> Path to dir containing reference files.\n"); printf(" Default: Current directory.\n"); + printf(" -u Keep running specifies tests until one fails.\n"); printf(" -v Verbose.\n"); printf("Available tests:\n"); for (i = 0; i < limit; i++) @@ -1913,7 +2169,11 @@ get_refdir(const char *d) } /* Get the current dir. */ +#ifdef PATH_MAX + pwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */ +#else pwd = getcwd(NULL, 0); +#endif while (pwd[strlen(pwd) - 1] == '\n') pwd[strlen(pwd) - 1] = '\0'; @@ -1940,6 +2200,14 @@ get_refdir(const char *d) strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); +#if defined(PROGRAM_ALIAS) + snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM_ALIAS); + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); +#endif + if (memcmp(pwd, "/usr/obj", 8) == 0) { snprintf(buff, sizeof(buff), "%s", pwd + 8); p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); @@ -1972,16 +2240,26 @@ int main(int argc, char **argv) { static const int limit = sizeof(tests) / sizeof(tests[0]); - int i, tests_run = 0, tests_failed = 0, option; + int i = 0, j = 0, start, end, tests_run = 0, tests_failed = 0, option; time_t now; char *refdir_alloc = NULL; const char *progname; + char **saved_argv; const char *tmp, *option_arg, *p; - char tmpdir[256]; + char tmpdir[256], *pwd, *testprogdir, *tmp2 = NULL; char tmpdir_timestamp[256]; (void)argc; /* UNUSED */ + /* Get the current dir. */ +#ifdef PATH_MAX + pwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */ +#else + pwd = getcwd(NULL, 0); +#endif + while (pwd[strlen(pwd) - 1] == '\n') + pwd[strlen(pwd) - 1] = '\0'; + #if defined(HAVE__CrtSetReportMode) /* To stop to run the default invalid parameter handler. */ _set_invalid_parameter_handler(invalid_parameter_handler); @@ -1994,11 +2272,44 @@ main(int argc, char **argv) * tree. */ progname = p = argv[0]; + if ((testprogdir = (char *)malloc(strlen(progname) + 1)) == NULL) + { + fprintf(stderr, "ERROR: Out of memory."); + exit(1); + } + strcpy(testprogdir, progname); while (*p != '\0') { /* Support \ or / dir separators for Windows compat. */ if (*p == '/' || *p == '\\') + { progname = p + 1; + i = j; + } ++p; + j++; + } + testprogdir[i] = '\0'; +#if defined(_WIN32) && !defined(__CYGWIN__) + if (testprogdir[0] != '/' && testprogdir[0] != '\\' && + !(((testprogdir[0] >= 'a' && testprogdir[0] <= 'z') || + (testprogdir[0] >= 'A' && testprogdir[0] <= 'Z')) && + testprogdir[1] == ':' && + (testprogdir[2] == '/' || testprogdir[2] == '\\'))) +#else + if (testprogdir[0] != '/') +#endif + { + /* Fixup path for relative directories. */ + if ((testprogdir = (char *)realloc(testprogdir, + strlen(pwd) + 1 + strlen(testprogdir) + 1)) == NULL) + { + fprintf(stderr, "ERROR: Out of memory."); + exit(1); + } + memmove(testprogdir + strlen(pwd) + 1, testprogdir, + strlen(testprogdir)); + memcpy(testprogdir, pwd, strlen(pwd)); + testprogdir[strlen(pwd)] = '/'; } #ifdef PROGRAM @@ -2073,6 +2384,9 @@ main(int argc, char **argv) case 'r': refdir = option_arg; break; + case 'u': + until_failure++; + break; case 'v': verbosity++; break; @@ -2088,9 +2402,18 @@ main(int argc, char **argv) * Sanity-check that our options make sense. */ #ifdef PROGRAM - if (testprogfile == NULL) { - fprintf(stderr, "Program executable required\n"); - usage(progname); + if (testprogfile == NULL) + { + if ((tmp2 = (char *)malloc(strlen(testprogdir) + 1 + + strlen(PROGRAM) + 1)) == NULL) + { + fprintf(stderr, "ERROR: Out of memory."); + exit(1); + } + strcpy(tmp2, testprogdir); + strcat(tmp2, "/"); + strcat(tmp2, PROGRAM); + testprogfile = tmp2; } { @@ -2113,6 +2436,16 @@ main(int argc, char **argv) } #endif +#if !defined(_WIN32) && defined(SIGPIPE) + { /* Ignore SIGPIPE signals */ + struct sigaction sa; + sa.sa_handler = SIG_IGN; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sigaction(SIGPIPE, &sa, NULL); + } +#endif + /* * Create a temp directory for the following tests. * Include the time the tests started as part of the name, @@ -2165,42 +2498,88 @@ main(int argc, char **argv) /* * Run some or all of the individual tests. */ - if (*argv == NULL) { - /* Default: Run all tests. */ - for (i = 0; i < limit; i++) { - if (test_run(i, tmpdir)) - tests_failed++; - tests_run++; - } - } else { - while (*(argv) != NULL) { - if (**argv >= '0' && **argv <= '9') { - i = atoi(*argv); - if (i < 0 || i >= limit) { - printf("*** INVALID Test %s\n", *argv); - free(refdir_alloc); - usage(progname); - /* usage() never returns */ + saved_argv = argv; + do { + argv = saved_argv; + if (*argv == NULL) { + /* Default: Run all tests. */ + for (i = 0; i < limit; i++) { + tests_run++; + if (test_run(i, tmpdir)) { + tests_failed++; + if (until_failure) + goto finish; } - } else { - for (i = 0; i < limit; ++i) { - if (strcmp(*argv, tests[i].name) == 0) - break; + } + } else { + while (*(argv) != NULL) { + if (**argv >= '0' && **argv <= '9') { + char *vp = *argv; + start = 0; + while (*vp >= '0' && *vp <= '9') { + start *= 10; + start += *vp - '0'; + ++vp; + } + if (*vp == '\0') { + end = start; + } else if (*vp == '-') { + ++vp; + if (*vp == '\0') { + end = limit - 1; + } else { + end = 0; + while (*vp >= '0' && *vp <= '9') { + end *= 10; + end += *vp - '0'; + ++vp; + } + } + } else { + printf("*** INVALID Test %s\n", *argv); + free(refdir_alloc); + usage(progname); + return (1); + } + if (start < 0 || end >= limit || start > end) { + printf("*** INVALID Test %s\n", *argv); + free(refdir_alloc); + usage(progname); + return (1); + } + } else { + for (start = 0; start < limit; ++start) { + if (strcmp(*argv, tests[start].name) == 0) + break; + } + end = start; + if (start >= limit) { + printf("*** INVALID Test ``%s''\n", + *argv); + free(refdir_alloc); + usage(progname); + /* usage() never returns */ + } } - if (i >= limit) { - printf("*** INVALID Test ``%s''\n", - *argv); - free(refdir_alloc); - usage(progname); - /* usage() never returns */ + while (start <= end) { + tests_run++; + if (test_run(start, tmpdir)) { + tests_failed++; + if (until_failure) + goto finish; + } + ++start; } + argv++; } - if (test_run(i, tmpdir)) - tests_failed++; - tests_run++; - argv++; } - } + } while (until_failure); + +finish: + /* Must be freed after all tests run */ + free(tmp2); + free(testprogdir); + free(pwd); /* * Report summary statistics. diff --git a/contrib/libarchive/tar/test/test.h b/contrib/libarchive/tar/test/test.h index a4a2461..43462cc 100644 --- a/contrib/libarchive/tar/test/test.h +++ b/contrib/libarchive/tar/test/test.h @@ -48,9 +48,6 @@ #include <sys/types.h> /* Windows requires this before sys/stat.h */ #include <sys/stat.h> -#ifdef USE_DMALLOC -#include <dmalloc.h> -#endif #if HAVE_DIRENT_H #include <dirent.h> #endif @@ -63,6 +60,9 @@ #ifdef HAVE_IO_H #include <io.h> #endif +#ifdef HAVE_STDINT_H +#include <stdint.h> +#endif #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -83,13 +83,11 @@ /* Windows (including Visual Studio and MinGW but not Cygwin) */ #if defined(_WIN32) && !defined(__CYGWIN__) -#include "../bsdtar_windows.h" #if !defined(__BORLANDC__) +#undef chdir +#define chdir _chdir #define strdup _strdup #endif -#define LOCALE_DE "deu" -#else -#define LOCALE_DE "de_DE.UTF-8" #endif /* Visual Studio */ @@ -97,13 +95,11 @@ #define snprintf sprintf_s #endif -/* Cygwin */ -#if defined(__CYGWIN__) -/* Cygwin-1.7.x is lazy about populating nlinks, so don't - * expect it to be accurate. */ -# define NLINKS_INACCURATE_FOR_DIRS +#if defined(__BORLANDC__) +#pragma warn -8068 /* Constant out of range in comparison. */ #endif +/* Haiku OS and QNX */ #if defined(__HAIKU__) || defined(__QNXNTO__) /* Haiku and QNX have typedefs in stdint.h (needed for int64_t) */ #include <stdint.h> @@ -139,24 +135,24 @@ assertion_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) /* Assert two strings are the same. Reports value of each one if not. */ #define assertEqualString(v1,v2) \ - assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) + assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL, 0) +#define assertEqualUTF8String(v1,v2) \ + assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL, 1) /* As above, but v1 and v2 are wchar_t * */ #define assertEqualWString(v1,v2) \ assertion_equal_wstring(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) /* As above, but raw blocks of bytes. */ #define assertEqualMem(v1, v2, l) \ assertion_equal_mem(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (l), #l, NULL) -/* Assert two files are the same; allow printf-style expansion of second name. - * See below for comments about variable arguments here... - */ -#define assertEqualFile \ - assertion_setup(__FILE__, __LINE__);assertion_equal_file -/* Assert that a file is empty; supports printf-style arguments. */ -#define assertEmptyFile \ - assertion_setup(__FILE__, __LINE__);assertion_empty_file -/* Assert that a file is not empty; supports printf-style arguments. */ -#define assertNonEmptyFile \ - assertion_setup(__FILE__, __LINE__);assertion_non_empty_file +/* Assert two files are the same. */ +#define assertEqualFile(f1, f2) \ + assertion_equal_file(__FILE__, __LINE__, (f1), (f2)) +/* Assert that a file is empty. */ +#define assertEmptyFile(pathname) \ + assertion_empty_file(__FILE__, __LINE__, (pathname)) +/* Assert that a file is not empty. */ +#define assertNonEmptyFile(pathname) \ + assertion_non_empty_file(__FILE__, __LINE__, (pathname)) #define assertFileAtime(pathname, sec, nsec) \ assertion_file_atime(__FILE__, __LINE__, pathname, sec, nsec) #define assertFileAtimeRecent(pathname) \ @@ -166,14 +162,14 @@ #define assertFileBirthtimeRecent(pathname) \ assertion_file_birthtime_recent(__FILE__, __LINE__, pathname) /* Assert that a file exists; supports printf-style arguments. */ -#define assertFileExists \ - assertion_setup(__FILE__, __LINE__);assertion_file_exists -/* Assert that a file exists; supports printf-style arguments. */ -#define assertFileNotExists \ - assertion_setup(__FILE__, __LINE__);assertion_file_not_exists -/* Assert that file contents match a string; supports printf-style arguments. */ -#define assertFileContents \ - assertion_setup(__FILE__, __LINE__);assertion_file_contents +#define assertFileExists(pathname) \ + assertion_file_exists(__FILE__, __LINE__, pathname) +/* Assert that a file exists. */ +#define assertFileNotExists(pathname) \ + assertion_file_not_exists(__FILE__, __LINE__, pathname) +/* Assert that file contents match a string. */ +#define assertFileContents(data, data_size, pathname) \ + assertion_file_contents(__FILE__, __LINE__, data, data_size, pathname) #define assertFileMtime(pathname, sec, nsec) \ assertion_file_mtime(__FILE__, __LINE__, pathname, sec, nsec) #define assertFileMtimeRecent(pathname) \ @@ -182,10 +178,10 @@ assertion_file_nlinks(__FILE__, __LINE__, pathname, nlinks) #define assertFileSize(pathname, size) \ assertion_file_size(__FILE__, __LINE__, pathname, size) -#define assertTextFileContents \ - assertion_setup(__FILE__, __LINE__);assertion_text_file_contents +#define assertTextFileContents(text, pathname) \ + assertion_text_file_contents(__FILE__, __LINE__, text, pathname) #define assertFileContainsLinesAnyOrder(pathname, lines) \ - assertion_file_contains_lines_any_order(__FILE__, __LINE__, pathname, lines) + assertion_file_contains_lines_any_order(__FILE__, __LINE__, pathname, lines) #define assertIsDir(pathname, mode) \ assertion_is_dir(__FILE__, __LINE__, pathname, mode) #define assertIsHardlink(path1, path2) \ @@ -207,6 +203,8 @@ assertion_make_symlink(__FILE__, __LINE__, newfile, linkto) #define assertUmask(mask) \ assertion_umask(__FILE__, __LINE__, mask) +#define assertUtimes(pathname, atime, atime_nsec, mtime, mtime_nsec) \ + assertion_utimes(__FILE__, __LINE__, pathname, atime, atime_nsec, mtime, mtime_nsec) /* * This would be simple with C99 variadic macros, but I don't want to @@ -215,29 +213,29 @@ * but effective. */ #define skipping \ - assertion_setup(__FILE__, __LINE__);test_skipping + skipping_setup(__FILE__, __LINE__);test_skipping /* Function declarations. These are defined in test_utility.c. */ void failure(const char *fmt, ...); int assertion_assert(const char *, int, int, const char *, void *); int assertion_chdir(const char *, int, const char *); -int assertion_empty_file(const char *, ...); -int assertion_equal_file(const char *, const char *, ...); +int assertion_empty_file(const char *, int, const char *); +int assertion_equal_file(const char *, int, const char *, const char *); int assertion_equal_int(const char *, int, long long, const char *, long long, const char *, void *); int assertion_equal_mem(const char *, int, const void *, const char *, const void *, const char *, size_t, const char *, void *); -int assertion_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *); +int assertion_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *, int); int assertion_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *); int assertion_file_atime(const char *, int, const char *, long, long); int assertion_file_atime_recent(const char *, int, const char *); int assertion_file_birthtime(const char *, int, const char *, long, long); int assertion_file_birthtime_recent(const char *, int, const char *); int assertion_file_contains_lines_any_order(const char *, int, const char *, const char **); -int assertion_file_contents(const void *, int, const char *, ...); -int assertion_file_exists(const char *, ...); +int assertion_file_contents(const char *, int, const void *, int, const char *); +int assertion_file_exists(const char *, int, const char *); int assertion_file_mtime(const char *, int, const char *, long, long); int assertion_file_mtime_recent(const char *, int, const char *); int assertion_file_nlinks(const char *, int, const char *, int); -int assertion_file_not_exists(const char *, ...); +int assertion_file_not_exists(const char *, int, const char *); int assertion_file_size(const char *, int, const char *, long); int assertion_is_dir(const char *, int, const char *, int); int assertion_is_hardlink(const char *, int, const char *, const char *); @@ -248,11 +246,12 @@ int assertion_make_dir(const char *, int, const char *, int); int assertion_make_file(const char *, int, const char *, int, const char *); int assertion_make_hardlink(const char *, int, const char *newpath, const char *); int assertion_make_symlink(const char *, int, const char *newpath, const char *); -int assertion_non_empty_file(const char *, ...); -int assertion_text_file_contents(const char *buff, const char *f); +int assertion_non_empty_file(const char *, int, const char *); +int assertion_text_file_contents(const char *, int, const char *buff, const char *f); int assertion_umask(const char *, int, int); -void assertion_setup(const char *, int); +int assertion_utimes(const char *, int, const char *, long, long, long, long ); +void skipping_setup(const char *, int); void test_skipping(const char *fmt, ...); /* Like sprintf, then system() */ @@ -270,6 +269,9 @@ int canGzip(void); /* Return true if this platform can run the "gunzip" program. */ int canGunzip(void); +/* Return true if the file has large i-node number(>0xffffffff). */ +int is_LargeInode(const char *); + /* Suck file into string allocated via malloc(). Call free() when done. */ /* Supports printf-style args: slurpfile(NULL, "%s/myfile", refdir); */ char *slurpfile(size_t *, const char *fmt, ...); @@ -277,6 +279,9 @@ char *slurpfile(size_t *, const char *fmt, ...); /* Extracts named reference file to the current directory. */ void extract_reference_file(const char *); +/* Path to working directory for current test */ +const char *testworkdir; + /* * Special interfaces for program test harness. */ @@ -286,3 +291,7 @@ const char *testprogfile; /* Name of exe to use in printf-formatted command strings. */ /* On Windows, this includes leading/trailing quotes. */ const char *testprog; + +#ifdef USE_DMALLOC +#include <dmalloc.h> +#endif diff --git a/contrib/libarchive/tar/test/test_0.c b/contrib/libarchive/tar/test/test_0.c index b97bd37..30d8d93 100644 --- a/contrib/libarchive/tar/test/test_0.c +++ b/contrib/libarchive/tar/test/test_0.c @@ -40,15 +40,23 @@ DEFINE_TEST(test_0) struct stat st; failure("File %s does not exist?!", testprog); - if (!assertEqualInt(0, stat(testprogfile, &st))) + if (!assertEqualInt(0, stat(testprogfile, &st))) { + fprintf(stderr, + "\nFile %s does not exist; aborting test.\n\n", + testprog); exit(1); + } failure("%s is not executable?!", testprog); - if (!assert((st.st_mode & 0111) != 0)) + if (!assert((st.st_mode & 0111) != 0)) { + fprintf(stderr, + "\nFile %s not executable; aborting test.\n\n", + testprog); exit(1); + } /* - * Try to succesfully run the program; this requires that + * Try to successfully run the program; this requires that * we know some option that will succeed. */ if (0 == systemf("%s --version >" DEV_NULL, testprog)) { diff --git a/contrib/libarchive/tar/test/test_basic.c b/contrib/libarchive/tar/test/test_basic.c index 1fa3341..689e116 100644 --- a/contrib/libarchive/tar/test/test_basic.c +++ b/contrib/libarchive/tar/test/test_basic.c @@ -25,48 +25,49 @@ #include "test.h" __FBSDID("$FreeBSD$"); - -static void -basic_tar(const char *target, const char *pack_options, - const char *unpack_options, const char *flist) +static const char * +make_files(void) { - int r; - - assertMakeDir(target, 0775); + FILE *f; - /* 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); + /* File with 10 bytes content. */ + f = fopen("file", "wb"); + assert(f != NULL); + assertEqualInt(10, fwrite("123456789", 1, 10, f)); + fclose(f); - assertChdir(target); + /* hardlink to above file. */ + assertMakeHardlink("linkfile", "file"); + assertIsHardlink("file", "linkfile"); - /* Verify that nothing went to stderr. */ - assertEmptyFile("pack.err"); + /* Symlink to above file. */ + if (canSymlink()) + assertMakeSymlink("symlink", "file"); - /* - * 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); + /* Directory. */ + assertMakeDir("dir", 0775); - /* Verify that nothing went to stderr. */ - assertEmptyFile("unpack.err"); + return canSymlink() + ? "file linkfile symlink dir" + : "file linkfile dir"; +} - /* - * Verify unpacked files. - */ +static void +verify_files(const char *target) +{ + assertChdir(target); /* Regular file with 2 links. */ assertIsReg("file", -1); assertFileSize("file", 10); + assertFileContents("123456789", 10, "file"); failure("%s", target); assertFileNLinks("file", 2); /* Another name for the same file. */ assertIsReg("linkfile", -1); assertFileSize("linkfile", 10); + assertFileContents("123456789", 10, "linkfile"); assertFileNLinks("linkfile", 2); assertIsHardlink("file", "linkfile"); @@ -79,37 +80,50 @@ basic_tar(const char *target, const char *pack_options, assertChdir(".."); } -DEFINE_TEST(test_basic) +static void +run_tar(const char *target, const char *pack_options, + const char *unpack_options, const char *flist) { - FILE *f; - const char *flist; + int r; - assertUmask(0); + assertMakeDir(target, 0775); - /* File with 10 bytes content. */ - f = fopen("file", "wb"); - assert(f != NULL); - assertEqualInt(10, fwrite("123456789", 1, 10, f)); - fclose(f); + /* 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); - /* hardlink to above file. */ - assertMakeHardlink("linkfile", "file"); - assertIsHardlink("file", "linkfile"); + assertChdir(target); - /* Symlink to above file. */ - if (canSymlink()) - assertMakeSymlink("symlink", "file"); + /* Verify that nothing went to stderr. */ + assertEmptyFile("pack.err"); - /* Directory. */ - assertMakeDir("dir", 0775); + /* + * 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); - if (canSymlink()) - flist = "file linkfile symlink dir"; - else - flist = "file linkfile dir"; + /* Verify that nothing went to stderr. */ + assertEmptyFile("unpack.err"); + assertChdir(".."); +} + +DEFINE_TEST(test_basic) +{ + const char *flist; + + assertUmask(0); + flist = make_files(); /* Archive/dearchive with a variety of options. */ - basic_tar("copy", "", "", flist); + run_tar("copy", "", "", flist); + verify_files("copy"); + + run_tar("copy_ustar", "--format=ustar", "", flist); + verify_files("copy_ustar"); + /* tar doesn't handle cpio symlinks correctly */ - /* basic_tar("copy_odc", "--format=odc", ""); */ - basic_tar("copy_ustar", "--format=ustar", "", flist); + /* run_tar("copy_odc", "--format=odc", ""); */ } diff --git a/contrib/libarchive/tar/test/test_option_C_upper.c b/contrib/libarchive/tar/test/test_option_C_upper.c new file mode 100644 index 0000000..dae9854 --- /dev/null +++ b/contrib/libarchive/tar/test/test_option_C_upper.c @@ -0,0 +1,149 @@ +/*- + * Copyright (c) 2010 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_C_upper) +{ + int r; + + assertMakeDir("d1", 0755); + assertMakeDir("d2", 0755); + assertMakeFile("d1/file1", 0644, "d1/file1"); + assertMakeFile("d1/file2", 0644, "d1/file2"); + assertMakeFile("d2/file1", 0644, "d2/file1"); + assertMakeFile("d2/file2", 0644, "d2/file2"); + + /* + * Test 1: Basic use of -C + */ + assertMakeDir("test1", 0755); + assertChdir("test1"); + assertEqualInt(0, systemf("%s -cf archive.tar -C ../d1 file1 -C ../d2 file2", testprog)); + assertEqualInt(0, + systemf("%s -xf archive.tar >test.out 2>test.err", testprog)); + assertFileContents("d1/file1", 8, "file1"); + assertFileContents("d2/file2", 8, "file2"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + + /* + * Test 2: Multiple -C + */ + assertMakeDir("test2", 0755); + assertChdir("test2"); + assertEqualInt(0, systemf("%s -cf archive.tar -C .. -C d1 file1 -C .. -C d2 file2", testprog)); + assertEqualInt(0, + systemf("%s -xf archive.tar >test.out 2>test.err", testprog)); + assertFileContents("d1/file1", 8, "file1"); + assertFileContents("d2/file2", 8, "file2"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* + * Test 3: -C fail + */ + assertMakeDir("test3", 0755); + assertChdir("test3"); + r = systemf("%s -cf archive.tar -C ../XXX file1 -C ../d2 file2 2>write.err", testprog); + assert(r != 0); + assertNonEmptyFile("write.err"); + assertEqualInt(0, + systemf("%s -xf archive.tar >test.out 2>test.err", testprog)); + assertFileNotExists("file1"); + assertFileNotExists("file2"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* + * Test 4: Absolute -C + */ + assertMakeDir("test4", 0755); + assertChdir("test4"); + assertEqualInt(0, + systemf("%s -cf archive.tar -C %s/d1 file1", + testprog, testworkdir)); + assertEqualInt(0, + systemf("%s -xf archive.tar >test.out 2>test.err", testprog)); + assertFileContents("d1/file1", 8, "file1"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* + * Test 5: Unnecessary -C ignored even if directory named doesn't exist + */ + assertMakeDir("test5", 0755); + assertChdir("test5"); + assertEqualInt(0, + systemf("%s -cf archive.tar -C XXX -C %s/d1 file1", + testprog, testworkdir)); + assertEqualInt(0, + systemf("%s -xf archive.tar >test.out 2>test.err", testprog)); + assertFileContents("d1/file1", 8, "file1"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* + * Test 6: Necessary -C not ignored if directory doesn't exist + */ + assertMakeDir("test6", 0755); + assertChdir("test6"); + r = systemf("%s -cf archive.tar -C XXX -C ../d1 file1 2>write.err", + testprog, testworkdir); + assert(r != 0); + assertNonEmptyFile("write.err"); + assertEqualInt(0, + systemf("%s -xf archive.tar >test.out 2>test.err", testprog)); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* + * Test 7: -C used without specifying directory + */ + assertMakeDir("test7", 0755); + assertChdir("test7"); + r = systemf("%s -cf archive.tar ../d1/file1 -C 2>write.err", testprog); + assert(r != 0); + assertNonEmptyFile("write.err"); + assertChdir(".."); + + /* + * Test 8: -C used with meaningless option '' + */ + assertMakeDir("test8", 0755); + assertChdir("test8"); + r = systemf("%s -cf archive.tar ../d1/file1 -C \"\" 2>write.err", + testprog); + assert(r != 0); + assertNonEmptyFile("write.err"); + assertChdir(".."); +} diff --git a/contrib/libarchive/tar/test/test_option_H_upper.c b/contrib/libarchive/tar/test/test_option_H_upper.c new file mode 100644 index 0000000..7ddd917 --- /dev/null +++ b/contrib/libarchive/tar/test/test_option_H_upper.c @@ -0,0 +1,92 @@ +/*- + * Copyright (c) 2010 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_H_upper) +{ + + if (!canSymlink()) { + skipping("Can't test symlinks on this filesystem"); + return; + } + + /* + * Create a sample archive. + */ + assertMakeDir("in", 0755); + assertChdir("in"); + assertMakeDir("d1", 0755); + assertMakeSymlink("ld1", "d1"); + assertMakeFile("d1/file1", 0644, "d1/file1"); + assertMakeFile("d1/file2", 0644, "d1/file2"); + assertMakeSymlink("d1/link1", "file1"); + assertMakeSymlink("d1/linkX", "fileX"); + assertMakeSymlink("link2", "d1/file2"); + assertMakeSymlink("linkY", "d1/fileY"); + assertChdir(".."); + + /* Test 1: Without -H */ + assertMakeDir("test1", 0755); + assertEqualInt(0, + systemf("%s -cf test1/archive.tar -C in . >test1/c.out 2>test1/c.err", testprog)); + assertChdir("test1"); + assertEqualInt(0, + systemf("%s -xf archive.tar >c.out 2>c.err", testprog)); + assertIsSymlink("ld1", "d1"); + assertIsSymlink("d1/link1", "file1"); + assertIsSymlink("d1/linkX", "fileX"); + assertIsSymlink("link2", "d1/file2"); + assertIsSymlink("linkY", "d1/fileY"); + assertChdir(".."); + + /* Test 2: With -H, no symlink on command line. */ + assertMakeDir("test2", 0755); + assertEqualInt(0, + systemf("%s -cf test2/archive.tar -H -C in . >test2/c.out 2>test2/c.err", testprog)); + assertChdir("test2"); + assertEqualInt(0, + systemf("%s -xf archive.tar >c.out 2>c.err", testprog)); + assertIsSymlink("ld1", "d1"); + assertIsSymlink("d1/link1", "file1"); + assertIsSymlink("d1/linkX", "fileX"); + assertIsSymlink("link2", "d1/file2"); + assertIsSymlink("linkY", "d1/fileY"); + assertChdir(".."); + + /* Test 3: With -H, some symlinks on command line. */ + assertMakeDir("test3", 0755); + assertEqualInt(0, + systemf("%s -cf test3/archive.tar -H -C in ld1 d1 link2 linkY >test2/c.out 2>test2/c.err", testprog)); + assertChdir("test3"); + assertEqualInt(0, + systemf("%s -xf archive.tar >c.out 2>c.err", testprog)); + assertIsDir("ld1", 0755); + assertIsSymlink("d1/linkX", "fileX"); + assertIsSymlink("d1/link1", "file1"); + assertIsReg("link2", 0644); + assertIsSymlink("linkY", "d1/fileY"); + assertChdir(".."); +} diff --git a/contrib/libarchive/tar/test/test_option_L_upper.c b/contrib/libarchive/tar/test/test_option_L_upper.c new file mode 100644 index 0000000..57abe41 --- /dev/null +++ b/contrib/libarchive/tar/test/test_option_L_upper.c @@ -0,0 +1,92 @@ +/*- + * Copyright (c) 2010 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_L_upper) +{ + + if (!canSymlink()) { + skipping("Can't test symlinks on this filesystem"); + return; + } + + /* + * Create a sample archive. + */ + assertMakeDir("in", 0755); + assertChdir("in"); + assertMakeDir("d1", 0755); + assertMakeSymlink("ld1", "d1"); + assertMakeFile("d1/file1", 0644, "d1/file1"); + assertMakeFile("d1/file2", 0644, "d1/file2"); + assertMakeSymlink("d1/link1", "file1"); + assertMakeSymlink("d1/linkX", "fileX"); + assertMakeSymlink("link2", "d1/file2"); + assertMakeSymlink("linkY", "d1/fileY"); + assertChdir(".."); + + /* Test 1: Without -L */ + assertMakeDir("test1", 0755); + assertEqualInt(0, + systemf("%s -cf test1/archive.tar -C in . >test1/c.out 2>test1/c.err", testprog)); + assertChdir("test1"); + assertEqualInt(0, + systemf("%s -xf archive.tar >c.out 2>c.err", testprog)); + assertIsSymlink("ld1", "d1"); + assertIsSymlink("d1/link1", "file1"); + assertIsSymlink("d1/linkX", "fileX"); + assertIsSymlink("link2", "d1/file2"); + assertIsSymlink("linkY", "d1/fileY"); + assertChdir(".."); + + /* Test 2: With -L, no symlink on command line. */ + assertMakeDir("test2", 0755); + assertEqualInt(0, + systemf("%s -cf test2/archive.tar -L -C in . >test2/c.out 2>test2/c.err", testprog)); + assertChdir("test2"); + assertEqualInt(0, + systemf("%s -xf archive.tar >c.out 2>c.err", testprog)); + assertIsDir("ld1", 0755); + assertIsReg("d1/link1", 0644); + assertIsSymlink("d1/linkX", "fileX"); + assertIsReg("link2", 0644); + assertIsSymlink("linkY", "d1/fileY"); + assertChdir(".."); + + /* Test 3: With -L, some symlinks on command line. */ + assertMakeDir("test3", 0755); + assertEqualInt(0, + systemf("%s -cf test3/archive.tar -L -C in ld1 d1 link2 linkY >test2/c.out 2>test2/c.err", testprog)); + assertChdir("test3"); + assertEqualInt(0, + systemf("%s -xf archive.tar >c.out 2>c.err", testprog)); + assertIsDir("ld1", 0755); + assertIsReg("d1/link1", 0644); + assertIsSymlink("d1/linkX", "fileX"); + assertIsReg("link2", 0644); + assertIsSymlink("linkY", "d1/fileY"); + assertChdir(".."); +} diff --git a/contrib/libarchive/tar/test/test_option_O_upper.c b/contrib/libarchive/tar/test/test_option_O_upper.c new file mode 100644 index 0000000..b9c8c0c --- /dev/null +++ b/contrib/libarchive/tar/test/test_option_O_upper.c @@ -0,0 +1,87 @@ +/*- + * Copyright (c) 2010 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +static const char *test4out[] = {"file1", "file2", NULL}; +static const char *test5err[] = {"file1", "file2", NULL}; + +DEFINE_TEST(test_option_O_upper) +{ + assertMakeFile("file1", 0644, "file1"); + assertMakeFile("file2", 0644, "file2"); + assertEqualInt(0, systemf("%s -cf archive.tar file1 file2", testprog)); + + /* Test 1: -x without -O */ + assertMakeDir("test1", 0755); + assertChdir("test1"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog)); + assertFileContents("file1", 5, "file1"); + assertFileContents("file2", 5, "file2"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 2: -x with -O */ + assertMakeDir("test2", 0755); + assertChdir("test2"); + assertEqualInt(0, + systemf("%s -xOf ../archive.tar file1 >test.out 2>test.err", testprog)); + assertFileNotExists("file1"); + assertFileNotExists("file2"); + assertFileContents("file1", 5, "test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 3: -x with -O and multiple files */ + assertMakeDir("test3", 0755); + assertChdir("test3"); + assertEqualInt(0, + systemf("%s -xOf ../archive.tar >test.out 2>test.err", testprog)); + assertFileNotExists("file1"); + assertFileNotExists("file2"); + assertFileContents("file1file2", 10, "test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 4: -t without -O */ + assertMakeDir("test4", 0755); + assertChdir("test4"); + assertEqualInt(0, + systemf("%s -tf ../archive.tar >test.out 2>test.err", testprog)); + assertFileContainsLinesAnyOrder("test.out", test4out); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 5: -t with -O */ + assertMakeDir("test5", 0755); + assertChdir("test5"); + assertEqualInt(0, + systemf("%s -tOf ../archive.tar >test.out 2>test.err", testprog)); + assertEmptyFile("test.out"); + assertFileContainsLinesAnyOrder("test.err", test5err); + assertChdir(".."); +} diff --git a/contrib/libarchive/tar/test/test_option_T_upper.c b/contrib/libarchive/tar/test/test_option_T_upper.c index 87127cc..bc54bd2 100644 --- a/contrib/libarchive/tar/test/test_option_T_upper.c +++ b/contrib/libarchive/tar/test/test_option_T_upper.c @@ -26,41 +26,33 @@ __FBSDID("$FreeBSD$"); static int -touch(const char *fn, int fail) +tryMakeFile(const char *fn) { FILE *f = fopen(fn, "w"); - if (fail) { - failure("Couldn't create file '%s', errno=%d (%s)\n", - fn, errno, strerror(errno)); - if (!assert(f != NULL)) - return (0); /* Failure. */ - } else { - if (f == NULL) - return (0); /* Soft failure. */ - } + if (f == NULL) + return (0); fclose(f); - return (1); /* Success */ + return (1); } DEFINE_TEST(test_option_T_upper) { FILE *f; int r; - struct stat st; int gnarlyFilesSupported; - /* Create a simple dir heirarchy; bail if anything fails. */ + /* Create a simple dir hierarchy; bail if anything fails. */ if (!assertMakeDir("d1", 0755)) return; if (!assertMakeDir("d1/d2", 0755)) return; - if (!touch("f", 1)) return; - if (!touch("d1/f1", 1)) return; - if (!touch("d1/f2", 1)) return; - if (!touch("d1/d2/f3", 1)) return; - if (!touch("d1/d2/f4", 1)) return; - if (!touch("d1/d2/f5", 1)) return; - if (!touch("d1/d2/f6", 1)) return; + if (!assertMakeFile("f", 0644, "")) return; + if (!assertMakeFile("d1/f1", 0644, "")) return; + if (!assertMakeFile("d1/f2", 0644, "")) return; + if (!assertMakeFile("d1/d2/f3", 0644, "")) return; + if (!assertMakeFile("d1/d2/f4", 0644, "")) return; + if (!assertMakeFile("d1/d2/f5", 0644, "")) return; + if (!assertMakeFile("d1/d2/f6", 0644, "")) return; /* Some platforms don't permit such things; just skip it. */ - gnarlyFilesSupported = touch("d1/d2/f\x0a", 0); + gnarlyFilesSupported = tryMakeFile("d1/d2/f\x0a"); /* Populate a file list */ f = fopen("filelist", "w+"); @@ -79,12 +71,12 @@ DEFINE_TEST(test_option_T_upper) return; /* Use null-terminated names. */ fprintf(f, "d1/d2/f3"); - fwrite("\0", 1, 1, f); + assertEqualInt(1, fwrite("\0", 1, 1, f)); fprintf(f, "d1/d2/f5"); - fwrite("\0", 1, 1, f); + assertEqualInt(1, fwrite("\0", 1, 1, f)); if (gnarlyFilesSupported) { fprintf(f, "d1/d2/f\x0a"); - fwrite("\0", 1, 1, f); + assertEqualInt(1, fwrite("\0", 1, 1, f)); } fclose(f); @@ -160,28 +152,8 @@ DEFINE_TEST(test_option_T_upper) assertMakeDir("test4_out", 0755); assertMakeDir("test4_out2", 0755); assertMakeDir("test4/d1", 0755); - assertEqualInt(1, touch("test4/d1/foo", 0)); + assertMakeFile("test4/d1/foo", 0644, ""); - /* Does bsdtar support -s option ? */ - systemf("%s -cf - -s /foo/bar/ test4/d1/foo > check.out 2> check.err", - testprog); - assertEqualInt(0, stat("check.err", &st)); - if (st.st_size == 0) { - systemf("%s -cf - -s /foo/bar/ test4/d1/foo | %s -xf - -C test4_out", - testprog, testprog); - assertEmptyFile("test4_out/test4/d1/bar"); - systemf("%s -cf - -s /d1/d2/ test4/d1/foo | %s -xf - -C test4_out", - testprog, testprog); - assertEmptyFile("test4_out/test4/d2/foo"); - systemf("%s -cf - -s ,test4/d1/foo,, test4/d1/foo | %s -tvf - > test4.lst", - testprog, testprog); - assertEmptyFile("test4.lst"); - systemf("%s -cf - test4/d1/foo | %s -xf - -s /foo/bar/ -C test4_out2", - testprog, testprog); - assertEmptyFile("test4_out2/test4/d1/bar"); - } else { - skipping("bsdtar does not support -s option on this platform"); - } /* TODO: Include some use of -C directory-changing within the filelist. */ /* I'm pretty sure -C within the filelist is broken on extract. */ diff --git a/contrib/libarchive/tar/test/test_option_U_upper.c b/contrib/libarchive/tar/test/test_option_U_upper.c new file mode 100644 index 0000000..4d77cb0 --- /dev/null +++ b/contrib/libarchive/tar/test/test_option_U_upper.c @@ -0,0 +1,159 @@ +/*- + * Copyright (c) 2010 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_U_upper) +{ + int r; + + assertMakeFile("file1", 0644, "file1"); + assertMakeDir("d1", 0755); + assertMakeFile("d1/file1", 0644, "d1/file1"); + assertEqualInt(0, systemf("%s -cf archive.tar file1 d1/file1", testprog)); + + /* + * bsdtar's man page used to claim that -x without -U would + * not break hard links. This was and is nonsense. The first + * two tests here simply verify that existing hard links get + * broken regardless. + */ + + /* Test 1: -x without -U */ + assertMakeDir("test1", 0755); + assertChdir("test1"); + assertMakeFile("file1", 0644, "file1new"); + assertMakeHardlink("file2", "file1"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog)); + assertFileContents("file1", 5, "file1"); + assertFileContents("file1new", 8, "file2"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + + /* Test 2: -x with -U */ + assertMakeDir("test2", 0755); + assertChdir("test2"); + assertMakeFile("file1", 0644, "file1new"); + assertMakeHardlink("file2", "file1"); + assertEqualInt(0, + systemf("%s -xUf ../archive.tar >test.out 2>test.err", testprog)); + assertFileContents("file1", 5, "file1"); + assertFileContents("file1new", 8, "file2"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* + * -U does make a difference in how bsdtar handles unwanted symlinks, + * though. It interacts with -P. + */ + if (!canSymlink()) + return; + + /* Test 3: Intermediate dir symlink causes error by default */ + assertMakeDir("test3", 0755); + assertChdir("test3"); + assertMakeDir("realDir", 0755); + assertMakeSymlink("d1", "realDir"); + r = systemf("%s -xf ../archive.tar d1/file1 >test.out 2>test.err", testprog); + assert(r != 0); + assertIsSymlink("d1", "realDir"); + assertFileNotExists("d1/file1"); + assertEmptyFile("test.out"); + assertNonEmptyFile("test.err"); + assertChdir(".."); + + /* Test 4: Intermediate dir symlink gets removed with -U */ + assertMakeDir("test4", 0755); + assertChdir("test4"); + assertMakeDir("realDir", 0755); + assertMakeSymlink("d1", "realDir"); + assertEqualInt(0, + systemf("%s -xUf ../archive.tar >test.out 2>test.err", testprog)); + assertIsDir("d1", -1); + assertFileContents("d1/file1", 8, "d1/file1"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 5: Intermediate dir symlink is followed with -P */ + assertMakeDir("test5", 0755); + assertChdir("test5"); + assertMakeDir("realDir", 0755); + assertMakeSymlink("d1", "realDir"); + assertEqualInt(0, + systemf("%s -xPf ../archive.tar d1/file1 >test.out 2>test.err", testprog)); + assertIsSymlink("d1", "realDir"); + assertFileContents("d1/file1", 8, "d1/file1"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 6: Intermediate dir symlink is followed with -PU */ + assertMakeDir("test6", 0755); + assertChdir("test6"); + assertMakeDir("realDir", 0755); + assertMakeSymlink("d1", "realDir"); + assertEqualInt(0, + systemf("%s -xPUf ../archive.tar d1/file1 >test.out 2>test.err", testprog)); + assertIsSymlink("d1", "realDir"); + assertFileContents("d1/file1", 8, "d1/file1"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 7: Final file symlink replaced by default */ + assertMakeDir("test7", 0755); + assertChdir("test7"); + assertMakeDir("d1", 0755); + assertMakeFile("d1/realfile1", 0644, "realfile1"); + assertMakeSymlink("d1/file1", "d1/realfile1"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar d1/file1 >test.out 2>test.err", testprog)); + assertIsReg("d1/file1", 0644); + assertFileContents("d1/file1", 8, "d1/file1"); + assertFileContents("realfile1", 9, "d1/realfile1"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 8: Final file symlink replaced with -PU */ + assertMakeDir("test8", 0755); + assertChdir("test8"); + assertMakeDir("d1", 0755); + assertMakeFile("d1/realfile1", 0644, "realfile1"); + assertMakeSymlink("d1/file1", "d1/realfile1"); + assertEqualInt(0, + systemf("%s -xPUf ../archive.tar d1/file1 >test.out 2>test.err", testprog)); + assertIsReg("d1/file1", 0644); + assertFileContents("d1/file1", 8, "d1/file1"); + assertFileContents("realfile1", 9, "d1/realfile1"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); +} diff --git a/contrib/libarchive/tar/test/test_option_X_upper.c b/contrib/libarchive/tar/test/test_option_X_upper.c new file mode 100644 index 0000000..1aa21fc --- /dev/null +++ b/contrib/libarchive/tar/test/test_option_X_upper.c @@ -0,0 +1,145 @@ +/*- + * Copyright (c) 2010 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_X_upper) +{ + int r; + + /* + * Create a sample archive. + */ + assertMakeFile("file1", 0644, "file1"); + assertMakeFile("file2", 0644, "file2"); + assertMakeFile("file3a", 0644, "file3a"); + assertMakeFile("file4a", 0644, "file4a"); + assertEqualInt(0, + systemf("%s -cf archive.tar file1 file2 file3a file4a", testprog)); + + /* + * Now, try extracting from the test archive with various -X usage. + */ + + /* Test 1: Without -X */ + assertMakeDir("test1", 0755); + assertChdir("test1"); + r = systemf("%s -xf ../archive.tar >test.out 2>test.err", + testprog); + if (!assertEqualInt(0, r)) + return; + + assertFileContents("file1", 5, "file1"); + assertFileContents("file2", 5, "file2"); + assertFileContents("file3a", 6, "file3a"); + assertFileContents("file4a", 6, "file4a"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 2: Use -X to skip one file */ + assertMakeDir("test2", 0755); + assertChdir("test2"); + assertMakeFile("exclusions", 0644, "file1\n"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar -X exclusions >test.out 2>test.err", testprog)); + assertFileNotExists("file1"); + assertFileContents("file2", 5, "file2"); + assertFileContents("file3a", 6, "file3a"); + assertFileContents("file4a", 6, "file4a"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 3: Use -X to skip multiple files */ + assertMakeDir("test3", 0755); + assertChdir("test3"); + assertMakeFile("exclusions", 0644, "file1\nfile2\n"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar -X exclusions >test.out 2>test.err", testprog)); + assertFileNotExists("file1"); + assertFileNotExists("file2"); + assertFileContents("file3a", 6, "file3a"); + assertFileContents("file4a", 6, "file4a"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 4: Omit trailing \n */ + assertMakeDir("test4", 0755); + assertChdir("test4"); + assertMakeFile("exclusions", 0644, "file1\nfile2"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar -X exclusions >test.out 2>test.err", testprog)); + assertFileNotExists("file1"); + assertFileNotExists("file2"); + assertFileContents("file3a", 6, "file3a"); + assertFileContents("file4a", 6, "file4a"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 5: include/exclude without overlap */ + assertMakeDir("test5", 0755); + assertChdir("test5"); + assertMakeFile("exclusions", 0644, "file1\nfile2"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar -X exclusions file3a >test.out 2>test.err", testprog)); + assertFileNotExists("file1"); + assertFileNotExists("file2"); + assertFileContents("file3a", 6, "file3a"); + assertFileNotExists("file4a"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 6: Overlapping include/exclude */ + assertMakeDir("test6", 0755); + assertChdir("test6"); + assertMakeFile("exclusions", 0644, "file1\nfile2"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar -X exclusions file1 file3a >test.out 2>test.err", testprog)); + assertFileNotExists("file1"); + assertFileNotExists("file2"); + assertFileContents("file3a", 6, "file3a"); + assertFileNotExists("file4a"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 7: with pattern */ + assertMakeDir("test7", 0755); + assertChdir("test7"); + assertMakeFile("exclusions", 0644, "file*a\nfile1"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar -X exclusions >test.out 2>test.err", testprog)); + assertFileNotExists("file1"); + assertFileContents("file2", 5, "file2"); + assertFileNotExists("file3a"); + assertFileNotExists("file4a"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); +} diff --git a/contrib/libarchive/tar/test/test_option_b.c b/contrib/libarchive/tar/test/test_option_b.c new file mode 100644 index 0000000..be2ae65 --- /dev/null +++ b/contrib/libarchive/tar/test/test_option_b.c @@ -0,0 +1,74 @@ +/*- + * Copyright (c) 2010 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_b) +{ + assertMakeFile("file1", 0644, "file1"); + if (systemf("cat file1 > test_cat.out 2> test_cat.err") != 0) { + skipping("Platform doesn't have cat"); + return; + } + + /* + * Bsdtar does not pad if the output is going directly to a disk file. + */ + assertEqualInt(0, systemf("%s -cf archive1.tar file1 >test1.out 2>test1.err", testprog)); + failure("bsdtar does not pad archives written directly to regular files"); + assertFileSize("archive1.tar", 2048); + assertEmptyFile("test1.out"); + assertEmptyFile("test1.err"); + + /* + * Bsdtar does pad to the block size if the output is going to a socket. + */ + /* Default is -b 20 */ + assertEqualInt(0, systemf("%s -cf - file1 2>test2.err | cat >archive2.tar ", testprog)); + failure("bsdtar does pad archives written to pipes"); + assertFileSize("archive2.tar", 10240); + assertEmptyFile("test2.err"); + + assertEqualInt(0, systemf("%s -cf - -b 20 file1 2>test3.err | cat >archive3.tar ", testprog)); + assertFileSize("archive3.tar", 10240); + assertEmptyFile("test3.err"); + + assertEqualInt(0, systemf("%s -cf - -b 10 file1 2>test4.err | cat >archive4.tar ", testprog)); + assertFileSize("archive4.tar", 5120); + assertEmptyFile("test4.err"); + + assertEqualInt(0, systemf("%s -cf - -b 1 file1 2>test5.err | cat >archive5.tar ", testprog)); + assertFileSize("archive5.tar", 2048); + assertEmptyFile("test5.err"); + + assertEqualInt(0, systemf("%s -cf - -b 8192 file1 2>test6.err | cat >archive6.tar ", testprog)); + assertFileSize("archive6.tar", 4194304); + assertEmptyFile("test6.err"); + + /* + * Note: It's not possible to verify at this level that blocks + * are getting written with the + */ +} diff --git a/contrib/libarchive/tar/test/test_option_exclude.c b/contrib/libarchive/tar/test/test_option_exclude.c new file mode 100644 index 0000000..1345f70 --- /dev/null +++ b/contrib/libarchive/tar/test/test_option_exclude.c @@ -0,0 +1,142 @@ +/*- + * Copyright (c) 2010 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_exclude) +{ + int r; + + assertMakeFile("file1", 0644, "file1"); + assertMakeFile("file2", 0644, "file2"); + assertEqualInt(0, systemf("%s -cf archive.tar file1 file2", testprog)); + + /* + * Now, try extracting from the test archive with various --exclude options. + */ + + /* Test 1: Without --exclude */ + assertMakeDir("test1", 0755); + assertChdir("test1"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog)); + assertFileContents("file1", 5, "file1"); + assertFileContents("file2", 5, "file2"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 2: Selecting just one file */ + assertMakeDir("test2", 0755); + assertChdir("test2"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar file1 >test.out 2>test.err", testprog)); + assertFileContents("file1", 5, "file1"); + assertFileNotExists("file2"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 3: Use --exclude to skip one file */ + assertMakeDir("test3", 0755); + assertChdir("test3"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar --exclude file1 >test.out 2>test.err", testprog)); + assertFileNotExists("file1"); + assertFileContents("file2", 5, "file2"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 4: Selecting one valid and one invalid file */ + assertMakeDir("test4", 0755); + assertChdir("test4"); + r = systemf("%s -xf ../archive.tar file1 file3 >test.out 2>test.err", testprog); + assert(r != 0); + assertFileContents("file1", 5, "file1"); + assertFileNotExists("file2"); + assertFileNotExists("file3"); + assertEmptyFile("test.out"); + assertNonEmptyFile("test.err"); + assertChdir(".."); + + /* Test 5: Selecting one valid file twice */ + assertMakeDir("test5", 0755); + assertChdir("test5"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar file1 file1 >test.out 2>test.err", testprog)); + assertFileContents("file1", 5, "file1"); + assertFileNotExists("file2"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 6: Include and exclude the same file */ + assertMakeDir("test6", 0755); + assertChdir("test6"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar --exclude file1 file1 >test.out 2>test.err", testprog)); + assertFileNotExists("file1"); + assertFileNotExists("file2"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 7: Exclude a non-existent file */ + assertMakeDir("test7", 0755); + assertChdir("test7"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar --exclude file3 file1 >test.out 2>test.err", testprog)); + assertFileContents("file1", 5, "file1"); + assertFileNotExists("file2"); + assertFileNotExists("file3"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 8: Include a non-existent file */ + assertMakeDir("test8", 0755); + assertChdir("test8"); + r = systemf("%s -xf ../archive.tar file3 >test.out 2>test.err", testprog); + assert(r != 0); + assertFileNotExists("file1"); + assertFileNotExists("file2"); + assertFileNotExists("file3"); + assertEmptyFile("test.out"); + assertNonEmptyFile("test.err"); + assertChdir(".."); + + /* Test 9: Include a non-existent file plus an exclusion */ + assertMakeDir("test9", 0755); + assertChdir("test9"); + r = systemf("%s -xf ../archive.tar --exclude file1 file3 >test.out 2>test.err", testprog); + assert(r != 0); + assertFileNotExists("file1"); + assertFileNotExists("file2"); + assertFileNotExists("file3"); + assertEmptyFile("test.out"); + assertNonEmptyFile("test.err"); + assertChdir(".."); +} diff --git a/contrib/libarchive/tar/test/test_option_gid_gname.c b/contrib/libarchive/tar/test/test_option_gid_gname.c new file mode 100644 index 0000000..e45da5b --- /dev/null +++ b/contrib/libarchive/tar/test/test_option_gid_gname.c @@ -0,0 +1,88 @@ +/*- + * Copyright (c) 2003-2010 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_gid_gname) +{ + char *reference, *data; + size_t s; + + assertUmask(0); + assertMakeFile("file", 0644, "1234567890"); + + /* Create archive with no special options. */ + failure("Error invoking %s c", testprog); + assertEqualInt(0, + systemf("%s cf archive1 --format=ustar file >stdout1.txt 2>stderr1.txt", + testprog)); + assertEmptyFile("stdout1.txt"); + assertEmptyFile("stderr1.txt"); + reference = slurpfile(&s, "archive1"); + + /* Again with both --gid and --gname */ + failure("Error invoking %s c", testprog); + assertEqualInt(0, + systemf("%s cf archive2 --gid=17 --gname=foofoofoo --format=ustar file >stdout2.txt 2>stderr2.txt", + testprog)); + assertEmptyFile("stdout2.txt"); + assertEmptyFile("stderr2.txt"); + data = slurpfile(&s, "archive2"); + /* Should force gid and gname fields in ustar header. */ + assertEqualMem(data + 116, "000021 \0", 8); + assertEqualMem(data + 297, "foofoofoo\0", 10); + + /* Again with just --gname */ + failure("Error invoking %s c", testprog); + assertEqualInt(0, + systemf("%s cf archive4 --gname=foofoofoo --format=ustar file >stdout4.txt 2>stderr4.txt", + testprog)); + assertEmptyFile("stdout4.txt"); + assertEmptyFile("stderr4.txt"); + data = slurpfile(&s, "archive4"); + /* Gid should be unchanged from original reference. */ + assertEqualMem(data + 116, reference + 116, 8); + assertEqualMem(data + 297, "foofoofoo\0", 10); + + /* Again with --gid and force gname to empty. */ + failure("Error invoking %s c", testprog); + assertEqualInt(0, + systemf("%s cf archive3 --gid=17 --gname= --format=ustar file >stdout3.txt 2>stderr3.txt", + testprog)); + assertEmptyFile("stdout3.txt"); + assertEmptyFile("stderr3.txt"); + data = slurpfile(&s, "archive3"); + assertEqualMem(data + 116, "000021 \0", 8); + /* Gname field in ustar header should be empty. */ + assertEqualMem(data + 297, "\0", 1); + + /* TODO: It would be nice to verify that --gid= by itself + * will look up the associated gname and use that, but + * that requires some system-specific code. */ + + /* TODO: It would be nice to verify that --gid= will + * leave the gname field blank if the specified gid + * isn't used on the local system. */ +} diff --git a/contrib/libarchive/tar/test/test_option_k.c b/contrib/libarchive/tar/test/test_option_k.c new file mode 100644 index 0000000..e57cc27 --- /dev/null +++ b/contrib/libarchive/tar/test/test_option_k.c @@ -0,0 +1,107 @@ +/*- + * Copyright (c) 2010 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_k) +{ + /* + * Create an archive with a couple of different versions of the + * same file. + */ + + assertMakeFile("foo", 0644, "foo1"); + + assertEqualInt(0, systemf("%s -cf archive.tar foo", testprog)); + + assertMakeFile("foo", 0644, "foo2"); + + assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog)); + + assertMakeFile("bar", 0644, "bar1"); + + assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog)); + + assertMakeFile("foo", 0644, "foo3"); + + assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog)); + + assertMakeFile("bar", 0644, "bar2"); + + assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog)); + + /* + * Now, try extracting from the test archive with various + * combinations of -k + */ + + /* Test 1: No option */ + assertMakeDir("test1", 0755); + assertChdir("test1"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog)); + assertFileContents("foo3", 4, "foo"); + assertFileContents("bar2", 4, "bar"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 2: With -k, we should just get the first versions. */ + assertMakeDir("test2", 0755); + assertChdir("test2"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar -k >test.out 2>test.err", testprog)); + assertFileContents("foo1", 4, "foo"); + assertFileContents("bar1", 4, "bar"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 3: Without -k, existing files should get overwritten */ + assertMakeDir("test3", 0755); + assertChdir("test3"); + assertMakeFile("bar", 0644, "bar0"); + assertMakeFile("foo", 0644, "foo0"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog)); + assertFileContents("foo3", 4, "foo"); + assertFileContents("bar2", 4, "bar"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 4: With -k, existing files should not get overwritten */ + assertMakeDir("test4", 0755); + assertChdir("test4"); + assertMakeFile("bar", 0644, "bar0"); + assertMakeFile("foo", 0644, "foo0"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar -k >test.out 2>test.err", testprog)); + assertFileContents("foo0", 4, "foo"); + assertFileContents("bar0", 4, "bar"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); +} diff --git a/contrib/libarchive/tar/test/test_option_keep_newer_files.c b/contrib/libarchive/tar/test/test_option_keep_newer_files.c new file mode 100644 index 0000000..089898c --- /dev/null +++ b/contrib/libarchive/tar/test/test_option_keep_newer_files.c @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 2010 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_keep_newer_files) +{ + const char *reffile = "test_option_keep_newer_files.tar.Z"; + + /* Reference file has one entry "file" with a very old timestamp. */ + extract_reference_file(reffile); + + /* Test 1: Without --keep-newer-files */ + assertMakeDir("test1", 0755); + assertChdir("test1"); + assertMakeFile("file", 0644, "new"); + assertEqualInt(0, + systemf("%s -xf ../%s >test.out 2>test.err", testprog, reffile)); + assertFileContents("old\n", 4, "file"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 2: With --keep-newer-files */ + assertMakeDir("test2", 0755); + assertChdir("test2"); + assertMakeFile("file", 0644, "new"); + assertEqualInt(0, + systemf("%s -xf ../%s --keep-newer-files >test.out 2>test.err", testprog, reffile)); + assertFileContents("new", 3, "file"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); +} diff --git a/contrib/libarchive/tar/test/test_option_keep_newer_files.tar.Z.uu b/contrib/libarchive/tar/test/test_option_keep_newer_files.tar.Z.uu new file mode 100644 index 0000000..74a0f1e --- /dev/null +++ b/contrib/libarchive/tar/test/test_option_keep_newer_files.tar.Z.uu @@ -0,0 +1,7 @@ +begin 644 test_option_keep_newer_files.tar.Z +M'YV09M*P*0.@H,&#"!,J7,BPH<.'$!'"F&B#!@T0`";&N%$#!D:-'#UFG$BR +MY$48,F38F&$CY8P8)V/$F,$2``@8$7/JW,FS)X`Z<^B$D3.23IHV/AD:19I4 +M8<F)'Y]B;$JUJM6K6'V^84-&0=:O8,.*'4NVK-FS:-.J7<NVK=NW<./*G4NW +.KMV[>//JW<NWK]^_/0$` +` +end diff --git a/contrib/libarchive/tar/test/test_option_n.c b/contrib/libarchive/tar/test/test_option_n.c new file mode 100644 index 0000000..4017dd9 --- /dev/null +++ b/contrib/libarchive/tar/test/test_option_n.c @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 2010 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_n) +{ + assertMakeDir("d1", 0755); + assertMakeFile("d1/file1", 0644, "d1/file1"); + + /* Test 1: -c without -n */ + assertMakeDir("test1", 0755); + assertChdir("test1"); + assertEqualInt(0, + systemf("%s -cf archive.tar -C .. d1 >c.out 2>c.err", testprog)); + assertEmptyFile("c.out"); + assertEmptyFile("c.err"); + assertEqualInt(0, + systemf("%s -xf archive.tar >x.out 2>x.err", testprog)); + assertEmptyFile("x.out"); + assertEmptyFile("x.err"); + assertFileContents("d1/file1", 8, "d1/file1"); + assertChdir(".."); + + /* Test 2: -c with -n */ + assertMakeDir("test2", 0755); + assertChdir("test2"); + assertEqualInt(0, + systemf("%s -cnf archive.tar -C .. d1 >c.out 2>c.err", testprog)); + assertEmptyFile("c.out"); + assertEmptyFile("c.err"); + assertEqualInt(0, + systemf("%s -xf archive.tar >x.out 2>x.err", testprog)); + assertEmptyFile("x.out"); + assertEmptyFile("x.err"); + assertIsDir("d1", 0755); + assertFileNotExists("d1/file1"); + assertChdir(".."); +} diff --git a/contrib/libarchive/tar/test/test_option_newer_than.c b/contrib/libarchive/tar/test/test_option_newer_than.c new file mode 100644 index 0000000..c9432dc --- /dev/null +++ b/contrib/libarchive/tar/test/test_option_newer_than.c @@ -0,0 +1,75 @@ +/*- + * Copyright (c) 2010 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_newer_than) +{ + struct stat st; + + /* + * Basic test of --newer-than. + * First, create three files with different mtimes. + * Create test1.tar with --newer-than, test2.tar without. + */ + assertMakeDir("test1in", 0755); + assertChdir("test1in"); + assertMakeDir("a", 0755); + assertMakeDir("a/b", 0755); + assertMakeFile("old.txt", 0644, "old.txt"); + assertEqualInt(0, stat("old.txt", &st)); + sleepUntilAfter(st.st_mtime); + assertMakeFile("middle.txt", 0644, "middle.txt"); + assertEqualInt(0, stat("middle.txt", &st)); + sleepUntilAfter(st.st_mtime); + assertMakeFile("new.txt", 0644, "new"); + assertMakeFile("a/b/new.txt", 0644, "new file in old directory"); + + /* Test --newer-than on create */ + assertEqualInt(0, systemf("%s -cf ../test1.tar --newer-than middle.txt *.txt a", testprog)); + assertEqualInt(0, systemf("%s -cf ../test2.tar *.txt a", testprog)); + assertChdir(".."); + + /* Extract test1.tar to a clean dir and verify what got archived. */ + assertMakeDir("test1out", 0755); + assertChdir("test1out"); + assertEqualInt(0, systemf("%s xf ../test1.tar", testprog)); + assertFileExists("new.txt"); + assertFileExists("a/b/new.txt"); + assertFileNotExists("middle.txt"); + assertFileNotExists("old.txt"); + assertChdir(".."); + + /* Extract test2.tar to a clean dir with --newer-than and verify. */ + assertMakeDir("test2out", 0755); + assertChdir("test2out"); + assertEqualInt(0, systemf("%s xf ../test2.tar --newer-than ../test1in/middle.txt", testprog)); + assertFileExists("new.txt"); + assertFileExists("a/b/new.txt"); + assertFileNotExists("middle.txt"); + assertFileNotExists("old.txt"); + assertChdir(".."); + +} diff --git a/contrib/libarchive/tar/test/test_option_q.c b/contrib/libarchive/tar/test/test_option_q.c index c8e9540..d954f89 100644 --- a/contrib/libarchive/tar/test/test_option_q.c +++ b/contrib/libarchive/tar/test/test_option_q.c @@ -27,7 +27,6 @@ __FBSDID("$FreeBSD$"); DEFINE_TEST(test_option_q) { - FILE *f; int r; /* @@ -40,38 +39,23 @@ DEFINE_TEST(test_option_q) * what we use to build up the test archive. */ - f = fopen("foo", "w"); - assert(f != NULL); - fprintf(f, "foo1"); - fclose(f); + assertMakeFile("foo", 0644, "foo1"); assertEqualInt(0, systemf("%s -cf archive.tar foo", testprog)); - f = fopen("foo", "w"); - assert(f != NULL); - fprintf(f, "foo2"); - fclose(f); + assertMakeFile("foo", 0644, "foo2"); assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog)); - f = fopen("bar", "w"); - assert(f != NULL); - fprintf(f, "bar1"); - fclose(f); + assertMakeFile("bar", 0644, "bar1"); assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog)); - f = fopen("foo", "w"); - assert(f != NULL); - fprintf(f, "foo3"); - fclose(f); + assertMakeFile("foo", 0644, "foo3"); assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog)); - f = fopen("bar", "w"); - assert(f != NULL); - fprintf(f, "bar2"); - fclose(f); + assertMakeFile("bar", 0644, "bar2"); assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog)); diff --git a/contrib/libarchive/tar/test/test_option_r.c b/contrib/libarchive/tar/test/test_option_r.c index 516a830..70c2087 100644 --- a/contrib/libarchive/tar/test/test_option_r.c +++ b/contrib/libarchive/tar/test/test_option_r.c @@ -30,29 +30,20 @@ __FBSDID("$FreeBSD$"); */ DEFINE_TEST(test_option_r) { - char buff[15]; + char *buff; char *p0, *p1; - size_t s; - FILE *f; - int r; + size_t buff_size = 35000; + size_t s, buff_size_rounded; + int r, i; - /* Create a file */ - f = fopen("f1", "w"); - if (!assert(f != NULL)) - return; - assertEqualInt(3, fwrite("abc", 1, 3, f)); - fclose(f); - - /* Archive that one file. */ + /* Create an archive with one file. */ + assertMakeFile("f1", 0644, "abc"); r = systemf("%s cf archive.tar --format=ustar f1 >step1.out 2>step1.err", testprog); failure("Error invoking %s cf archive.tar f1", testprog); assertEqualInt(r, 0); - - /* Verify that nothing went to stdout or stderr. */ assertEmptyFile("step1.out"); assertEmptyFile("step1.err"); - /* Do some basic validation of the constructed archive. */ p0 = slurpfile(&s, "archive.tar"); if (!assert(p0 != NULL)) @@ -66,52 +57,74 @@ DEFINE_TEST(test_option_r) assertEqualMem(p0 + 1024, "\0\0\0\0\0\0\0\0", 8); assertEqualMem(p0 + 1536, "\0\0\0\0\0\0\0\0", 8); - /* Edit that file */ - f = fopen("f1", "w"); - if (!assert(f != NULL)) - return; - assertEqualInt(3, fwrite("123", 1, 3, f)); - fclose(f); - - /* Update the archive. */ + /* Edit that file with a lot more data and update the archive with a new copy. */ + buff = malloc(buff_size); + assert(buff != NULL); + for (i = 0; i < (int)buff_size; ++i) + buff[i] = "abcdefghijklmnopqrstuvwxyz"[rand() % 26]; + buff[buff_size - 1] = '\0'; + assertMakeFile("f1", 0644, buff); r = systemf("%s rf archive.tar --format=ustar f1 >step2.out 2>step2.err", testprog); failure("Error invoking %s rf archive.tar f1", testprog); assertEqualInt(r, 0); - - /* Verify that nothing went to stdout or stderr. */ assertEmptyFile("step2.out"); assertEmptyFile("step2.err"); - /* Do some basic validation of the constructed archive. */ + /* The constructed archive should just have the new entry appended. */ p1 = slurpfile(&s, "archive.tar"); if (!assert(p1 != NULL)) { free(p0); return; } - assert(s >= 3072); + buff_size_rounded = ((buff_size + 511) / 512) * 512; + assert(s >= 2560 + buff_size_rounded); /* Verify first entry is unchanged. */ assertEqualMem(p0, p1, 1024); /* Verify that second entry is correct. */ assertEqualMem(p1 + 1024, "f1", 3); - assertEqualMem(p1 + 1536, "123", 3); + assertEqualMem(p1 + 1536, buff, buff_size); + /* Verify end-of-archive marker. */ + assertEqualMem(p1 + 1536 + buff_size_rounded, "\0\0\0\0\0\0\0\0", 8); + assertEqualMem(p1 + 2048 + buff_size_rounded, "\0\0\0\0\0\0\0\0", 8); + + free(p0); + p0 = p1; + + /* Update the archive by adding a different file. */ + assertMakeFile("f2", 0644, "f2"); + r = systemf("%s rf archive.tar --format=ustar f2 >step3.out 2>step3.err", testprog); + failure("Error invoking %s rf archive.tar f2", testprog); + assertEqualInt(r, 0); + assertEmptyFile("step3.out"); + assertEmptyFile("step3.err"); + + /* Validate the constructed archive. */ + p1 = slurpfile(&s, "archive.tar"); + if (!assert(p1 != NULL)) { + free(p0); + return; + } + assert(s >= 3584 + buff_size_rounded); + /* Verify first two entries are unchanged. */ + assertEqualMem(p0, p1, 1536 + buff_size_rounded); + /* Verify that new entry is correct. */ + assertEqualMem(p1 + 1536 + buff_size_rounded, "f2", 3); + assertEqualMem(p1 + 2048 + buff_size_rounded, "f2", 3); /* Verify end-of-archive marker. */ - assertEqualMem(p1 + 2048, "\0\0\0\0\0\0\0\0", 8); - assertEqualMem(p1 + 2560, "\0\0\0\0\0\0\0\0", 8); + assertEqualMem(p1 + 2560 + buff_size_rounded, "\0\0\0\0\0\0\0\0", 8); + assertEqualMem(p1 + 3072 + buff_size_rounded, "\0\0\0\0\0\0\0\0", 8); free(p0); free(p1); - /* Unpack both items */ - assertMakeDir("step3", 0775); - assertChdir("step3"); - r = systemf("%s xf ../archive.tar", testprog); + /* Unpack everything */ + assertMakeDir("extract", 0775); + assertChdir("extract"); + r = systemf("%s xf ../archive.tar >extract.out 2>extract.err", testprog); failure("Error invoking %s xf archive.tar", testprog); assertEqualInt(r, 0); + assertEmptyFile("extract.out"); + assertEmptyFile("extract.err"); - /* Verify that the second one overwrote the first. */ - f = fopen("f1", "r"); - if (assert(f != NULL)) { - assertEqualInt(3, fread(buff, 1, 3, f)); - assertEqualMem(buff, "123", 3); - fclose(f); - } + /* Verify that the second copy of f1 overwrote the first. */ + assertFileContents(buff, strlen(buff), "f1"); } diff --git a/contrib/libarchive/tar/test/test_option_s.c b/contrib/libarchive/tar/test/test_option_s.c index a2525a0..e4d617b 100644 --- a/contrib/libarchive/tar/test/test_option_s.c +++ b/contrib/libarchive/tar/test/test_option_s.c @@ -25,21 +25,6 @@ #include "test.h" __FBSDID("$FreeBSD$"); -static int -mkfile(const char *fn, const char *contents) -{ - FILE *f = fopen(fn, "w"); - failure("Couldn't create file '%s', errno=%d (%s)\n", - fn, errno, strerror(errno)); - if (!assert(f != NULL)) - return (1); /* Failure. */ - if (contents != NULL) - assertEqualInt(strlen(contents), - fwrite(contents, 1, strlen(contents), f)); - assertEqualInt(0, fclose(f)); - return (0); /* Success */ -} - DEFINE_TEST(test_option_s) { struct stat st; @@ -47,10 +32,16 @@ DEFINE_TEST(test_option_s) /* Create a sample file hierarchy. */ assertMakeDir("in", 0755); assertMakeDir("in/d1", 0755); - assertEqualInt(0, mkfile("in/d1/foo", "foo")); - assertEqualInt(0, mkfile("in/d1/bar", "bar")); + assertMakeFile("in/d1/foo", 0644, "foo"); + assertMakeFile("in/d1/bar", 0644, "bar"); + if (canSymlink()) { + assertMakeFile("in/d1/realfile", 0644, "realfile"); + assertMakeSymlink("in/d1/symlink", "realfile"); + } + assertMakeFile("in/d1/hardlink1", 0644, "hardlinkedfile"); + assertMakeHardlink("in/d1/hardlink2", "in/d1/hardlink1"); - /* Does bsdtar support -s option ? */ + /* Does tar support -s option ? */ systemf("%s -cf - -s /foo/bar/ in/d1/foo > NUL 2> check.err", testprog); assertEqualInt(0, stat("check.err", &st)); @@ -64,34 +55,35 @@ DEFINE_TEST(test_option_s) * Test 1: Filename substitution when creating archives. */ assertMakeDir("test1", 0755); - systemf("%s -cf - -s /foo/bar/ in/d1/foo | %s -xf - -C test1", - testprog, testprog); + systemf("%s -cf test1_1.tar -s /foo/bar/ in/d1/foo", testprog); + systemf("%s -xf test1_1.tar -C test1", testprog); assertFileContents("foo", 3, "test1/in/d1/bar"); - systemf("%s -cf - -s /d1/d2/ in/d1/foo | %s -xf - -C test1", - testprog, testprog); + systemf("%s -cf test1_2.tar -s /d1/d2/ in/d1/foo", testprog); + systemf("%s -xf test1_2.tar -C test1", testprog); assertFileContents("foo", 3, "test1/in/d2/foo"); - /* * Test 2: Basic substitution when extracting archive. */ assertMakeDir("test2", 0755); - systemf("%s -cf - in/d1/foo | %s -xf - -s /foo/bar/ -C test2", - testprog, testprog); + systemf("%s -cf test2.tar in/d1/foo", testprog); + systemf("%s -xf test2.tar -s /foo/bar/ -C test2", testprog); assertFileContents("foo", 3, "test2/in/d1/bar"); /* * Test 3: Files with empty names shouldn't be archived. */ - systemf("%s -cf - -s ,in/d1/foo,, in/d1/foo | %s -tvf - > in.lst", - testprog, testprog); + systemf("%s -cf test3.tar -s ,in/d1/foo,, in/d1/foo", testprog); + systemf("%s -tvf test3.tar > in.lst", testprog); assertEmptyFile("in.lst"); /* * Test 4: Multiple substitutions when extracting archive. */ assertMakeDir("test4", 0755); - systemf("%s -cf - in/d1/foo in/d1/bar | %s -xf - -s /foo/bar/ -s }bar}baz} -C test4", + systemf("%s -cf test4.tar in/d1/foo in/d1/bar", + testprog, testprog); + systemf("%s -xf test4.tar -s /foo/bar/ -s }bar}baz} -C test4", testprog, testprog); assertFileContents("foo", 3, "test4/in/d1/bar"); assertFileContents("bar", 3, "test4/in/d1/baz"); @@ -100,8 +92,170 @@ DEFINE_TEST(test_option_s) * Test 5: Name-switching substitutions when extracting archive. */ assertMakeDir("test5", 0755); - systemf("%s -cf - in/d1/foo in/d1/bar | %s -xf - -s /foo/bar/ -s }bar}foo} -C test5", + systemf("%s -cf test5.tar in/d1/foo in/d1/bar", + testprog, testprog); + systemf("%s -xf test5.tar -s /foo/bar/ -s }bar}foo} -C test5", testprog, testprog); assertFileContents("foo", 3, "test5/in/d1/bar"); assertFileContents("bar", 3, "test5/in/d1/foo"); + + /* + * Test 6: symlinks get renamed by default + */ + if (canSymlink()) { + /* At extraction time. */ + assertMakeDir("test6a", 0755); + systemf("%s -cf - in/d1 | %s -xf - -s /d1/d2/ -C test6a", + testprog, testprog); + assertFileContents("realfile", 8, "test6a/in/d2/realfile"); + assertFileContents("realfile", 8, "test6a/in/d2/symlink"); + assertIsSymlink("test6a/in/d2/symlink", "realfile"); + /* At creation time. */ + assertMakeDir("test6b", 0755); + systemf("%s -cf - -s /d1/d2/ in/d1 | %s -xf - -C test6b", + testprog, testprog); + assertFileContents("realfile", 8, "test6b/in/d2/realfile"); + assertFileContents("realfile", 8, "test6b/in/d2/symlink"); + assertIsSymlink("test6b/in/d2/symlink", "realfile"); + } + + /* + * Test 7: selective renaming of symlink target + */ + if (canSymlink()) { + /* At extraction. */ + assertMakeDir("test7a", 0755); + systemf("%s -cf - in/d1 | %s -xf - -s /realfile/realfile-renamed/ -C test7a", + testprog, testprog); + assertFileContents("realfile", 8, "test7a/in/d1/realfile-renamed"); + assertFileContents("realfile", 8, "test7a/in/d1/symlink"); + assertIsSymlink("test7a/in/d1/symlink", "realfile-renamed"); + /* At creation. */ + assertMakeDir("test7b", 0755); + systemf("%s -cf - -s /realfile/realfile-renamed/ in/d1 | %s -xf - -C test7b", + testprog, testprog); + assertFileContents("realfile", 8, "test7b/in/d1/realfile-renamed"); + assertFileContents("realfile", 8, "test7b/in/d1/symlink"); + assertIsSymlink("test7b/in/d1/symlink", "realfile-renamed"); + } + + /* + * Test 8: hardlinks get renamed by default + */ + /* At extraction time. */ + assertMakeDir("test8a", 0755); + systemf("%s -cf test8a.tar in/d1", testprog); + systemf("%s -xf test8a.tar -s /d1/d2/ -C test8a", testprog); + assertIsHardlink("test8a/in/d2/hardlink1", "test8a/in/d2/hardlink2"); + /* At creation time. */ + assertMakeDir("test8b", 0755); + systemf("%s -cf test8b.tar -s /d1/d2/ in/d1", testprog); + systemf("%s -xf test8b.tar -C test8b", testprog); + assertIsHardlink("test8b/in/d2/hardlink1", "test8b/in/d2/hardlink2"); + + /* + * Test 9: selective renaming of hardlink target + */ + /* At extraction. (assuming hardlink2 is the hardlink entry) */ + assertMakeDir("test9a", 0755); + systemf("%s -cf test9a.tar in/d1", testprog); + systemf("%s -xf test9a.tar -s /hardlink1/hardlink1-renamed/ -C test9a", + testprog); + assertIsHardlink("test9a/in/d1/hardlink1-renamed", "test9a/in/d1/hardlink2"); + /* At extraction. (assuming hardlink1 is the hardlink entry) */ + assertMakeDir("test9b", 0755); + systemf("%s -cf test9b.tar in/d1", testprog); + systemf("%s -xf test9b.tar -s /hardlink2/hardlink2-renamed/ -C test9b", + testprog); + assertIsHardlink("test9b/in/d1/hardlink1", "test9b/in/d1/hardlink2-renamed"); + /* At creation. (assuming hardlink2 is the hardlink entry) */ + assertMakeDir("test9c", 0755); + systemf("%s -cf test9c.tar -s /hardlink1/hardlink1-renamed/ in/d1", + testprog); + systemf("%s -xf test9c.tar -C test9c", testprog); + assertIsHardlink("test9c/in/d1/hardlink1-renamed", "test9c/in/d1/hardlink2"); + /* At creation. (assuming hardlink1 is the hardlink entry) */ + assertMakeDir("test9d", 0755); + systemf("%s -cf test9d.tar -s /hardlink2/hardlink2-renamed/ in/d1", + testprog); + systemf("%s -xf test9d.tar -C test9d", testprog); + assertIsHardlink("test9d/in/d1/hardlink1", "test9d/in/d1/hardlink2-renamed"); + + /* + * Test 10: renaming symlink target without repointing symlink + */ + if (canSymlink()) { + /* At extraction. */ + assertMakeDir("test10a", 0755); + systemf("%s -cf - in/d1 | %s -xf - -s /realfile/foo/S -s /foo/realfile/ -C test10a", + testprog, testprog); + assertFileContents("realfile", 8, "test10a/in/d1/foo"); + assertFileContents("foo", 3, "test10a/in/d1/realfile"); + assertFileContents("foo", 3, "test10a/in/d1/symlink"); + assertIsSymlink("test10a/in/d1/symlink", "realfile"); + /* At creation. */ + assertMakeDir("test10b", 0755); + systemf("%s -cf - -s /realfile/foo/S -s /foo/realfile/ in/d1 | %s -xf - -C test10b", + testprog, testprog); + assertFileContents("realfile", 8, "test10b/in/d1/foo"); + assertFileContents("foo", 3, "test10b/in/d1/realfile"); + assertFileContents("foo", 3, "test10b/in/d1/symlink"); + assertIsSymlink("test10b/in/d1/symlink", "realfile"); + } + + /* + * Test 11: repointing symlink without renaming file + */ + if (canSymlink()) { + /* At extraction. */ + assertMakeDir("test11a", 0755); + systemf("%s -cf - in/d1 | %s -xf - -s /realfile/foo/sR -C test11a", + testprog, testprog); + assertFileContents("foo", 3, "test11a/in/d1/foo"); + assertFileContents("realfile", 8, "test11a/in/d1/realfile"); + assertFileContents("foo", 3, "test11a/in/d1/symlink"); + assertIsSymlink("test11a/in/d1/symlink", "foo"); + /* At creation. */ + assertMakeDir("test11b", 0755); + systemf("%s -cf - -s /realfile/foo/R in/d1 | %s -xf - -C test11b", + testprog, testprog); + assertFileContents("foo", 3, "test11b/in/d1/foo"); + assertFileContents("realfile", 8, "test11b/in/d1/realfile"); + assertFileContents("foo", 3, "test11b/in/d1/symlink"); + assertIsSymlink("test11b/in/d1/symlink", "foo"); + } + + /* + * Test 12: renaming hardlink target without changing hardlink. + * (Requires a pre-built archive, since we otherwise can't know + * which element will be stored as the hardlink.) + */ + extract_reference_file("test_option_s.tar.Z"); + assertMakeDir("test12a", 0755); + systemf("%s -xf test_option_s.tar.Z -s /hardlink1/foo/H -s /foo/hardlink1/ %s -C test12a", + testprog, canSymlink()?"":"--exclude in/d1/symlink"); + assertFileContents("foo", 3, "test12a/in/d1/hardlink1"); + assertFileContents("hardlinkedfile", 14, "test12a/in/d1/foo"); + assertFileContents("foo", 3, "test12a/in/d1/hardlink2"); + assertIsHardlink("test12a/in/d1/hardlink1", "test12a/in/d1/hardlink2"); + /* TODO: Expand this test to verify creation as well. + * Since either hardlink1 or hardlink2 might get stored as a hardlink, + * this will either requiring testing both cases and accepting either + * pass, or some very creative renames that can be tested regardless. + */ + + /* + * Test 13: repoint hardlink without changing files + * (Requires a pre-built archive, since we otherwise can't know + * which element will be stored as the hardlink.) + */ + extract_reference_file("test_option_s.tar.Z"); + assertMakeDir("test13a", 0755); + systemf("%s -xf test_option_s.tar.Z -s /hardlink1/foo/Rh -s /foo/hardlink1/Rh %s -C test13a", + testprog, canSymlink()?"":"--exclude in/d1/symlink"); + assertFileContents("foo", 3, "test13a/in/d1/foo"); + assertFileContents("hardlinkedfile", 14, "test13a/in/d1/hardlink1"); + assertFileContents("foo", 3, "test13a/in/d1/hardlink2"); + assertIsHardlink("test13a/in/d1/foo", "test13a/in/d1/hardlink2"); + /* TODO: See above; expand this test to verify renames at creation. */ } diff --git a/contrib/libarchive/tar/test/test_option_s.tar.Z.uu b/contrib/libarchive/tar/test/test_option_s.tar.Z.uu new file mode 100644 index 0000000..df690bf --- /dev/null +++ b/contrib/libarchive/tar/test/test_option_s.tar.Z.uu @@ -0,0 +1,16 @@ +begin 644 test_option_s.tar.Z +M'YV0:=R\(!/C!8"#"!,J7,BPH<.'$"-*1`BCXHT:-4``J`CCAHV,&SG*H*&1 +MHTF3(&+$^%@C!HT8,&C(``%#Y0T9,P"`J#&QI\^?0(,"J#.'3A@Y(>FD:2/4 +M8=$P9LPT77@21LF3&J=JW<JUJU>A`0<6%'/TJ]FS"3G:H$$R9,>/5RN.C%L5 +MQHR4*S&ZA"F39HR1=G7"0$NX<$*B1I%65,KTZ].H7JO2K9C5L.7+F+>219JY +ML^?/H$.+'DVZM&G+80F^,//FS6G0:MG&]0C2Y%RW=>^J9+DWYLR:(V7($/SZ +M->*RBY>:?2RUJV3<E(M+GQZ1M6OJV+-KW\Z]NW?3J0NB.4J&3<`U,;YKC=V6 +M(VVZM^M67(F7]TO??F?4D#&8IGK,QRD&`V/+&069<UA!9]5_#'8VGASEG5<& +M&6:DP489#6:HX88<=NAA3^&]\&"$;JPQW(<0L3<;7+C%)Q]EN^EU7U\UV2!< +M3BF%.*)Y)::'XD,!)J6<8P8VQ]5SS_VHI$\ARE%&&&Q4>.&2#JGHUGLMMB<? +M3/7)R-=O,<P@4W^#4=E4D,DUYA5SD268I)EP,N0DE%)B&.>=>.:IYYX'A3A' +M'FWPN`:?[F&T8FTB:?EBERW-"&8-=N$HPYQ16F@GGPBA.>"0:Q;9)DH*5H;I +MJ*26:NJIJ*:JZJJLMNKJJ[#&*NNLM-9JZZVXYJKKKKSVZNNOP`8K[+#$%FOL +)L<@FJ^RRS.X) +` +end diff --git a/contrib/libarchive/tar/test/test_option_uid_uname.c b/contrib/libarchive/tar/test/test_option_uid_uname.c new file mode 100644 index 0000000..83ea5f1 --- /dev/null +++ b/contrib/libarchive/tar/test/test_option_uid_uname.c @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 2003-2010 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_uid_uname) +{ + char *reference, *data; + size_t s; + + assertUmask(0); + assertMakeFile("file", 0644, "1234567890"); + + /* Create archive with no special options. */ + failure("Error invoking %s c", testprog); + assertEqualInt(0, + systemf("%s cf archive1 --format=ustar file >stdout1.txt 2>stderr1.txt", + testprog)); + assertEmptyFile("stdout1.txt"); + assertEmptyFile("stderr1.txt"); + reference = slurpfile(&s, "archive1"); + + /* Again with both --uid and --uname */ + failure("Error invoking %s c", testprog); + assertEqualInt(0, + systemf("%s cf archive2 --uid=17 --uname=foofoofoo --format=ustar file >stdout2.txt 2>stderr2.txt", + testprog)); + assertEmptyFile("stdout2.txt"); + assertEmptyFile("stderr2.txt"); + data = slurpfile(&s, "archive2"); + /* Should force uid and uname fields in ustar header. */ + assertEqualMem(data + 108, "000021 \0", 8); + assertEqualMem(data + 265, "foofoofoo\0", 10); + + /* Again with just --uid */ + failure("Error invoking %s c", testprog); + assertEqualInt(0, + systemf("%s cf archive3 --uid=17 --format=ustar file >stdout3.txt 2>stderr3.txt", + testprog)); + assertEmptyFile("stdout3.txt"); + assertEmptyFile("stderr3.txt"); + data = slurpfile(&s, "archive3"); + assertEqualMem(data + 108, "000021 \0", 8); + /* Uname field in ustar header should be empty. */ + assertEqualMem(data + 265, "\0", 1); + + /* Again with just --uname */ + failure("Error invoking %s c", testprog); + assertEqualInt(0, + systemf("%s cf archive4 --uname=foofoofoo --format=ustar file >stdout4.txt 2>stderr4.txt", + testprog)); + assertEmptyFile("stdout4.txt"); + assertEmptyFile("stderr4.txt"); + data = slurpfile(&s, "archive4"); + /* Uid should be unchanged from original reference. */ + assertEqualMem(data + 108, reference + 108, 8); + assertEqualMem(data + 265, "foofoofoo\0", 10); +} diff --git a/contrib/libarchive/tar/test/test_patterns.c b/contrib/libarchive/tar/test/test_patterns.c index f909e27..deffe32 100644 --- a/contrib/libarchive/tar/test/test_patterns.c +++ b/contrib/libarchive/tar/test/test_patterns.c @@ -122,6 +122,7 @@ DEFINE_TEST(test_patterns) char file_b1[] = "tmp/server/share/fileXX"; char file_b2[] = "tmp/server\\share\\fileXX"; char file_c[] = "tmp/../fileXX"; + char file_d[] = "tmp/../../fileXX"; char *filex; int xsize; @@ -169,8 +170,13 @@ DEFINE_TEST(test_patterns) * \/?\UnC\../file54 */ assertFileNotExists(filex); - filex = file_c; - xsize = sizeof(file_c); + if (r == 6 || r == 26 || r == 43) { + filex = file_d; + xsize = sizeof(file_d); + } else { + filex = file_c; + xsize = sizeof(file_c); + } filex[xsize-3] = '0' + r / 10; filex[xsize-2] = '0' + r % 10; assertFileNotExists(filex); diff --git a/contrib/libarchive/tar/test/test_print_longpath.c b/contrib/libarchive/tar/test/test_print_longpath.c new file mode 100644 index 0000000..4bac167 --- /dev/null +++ b/contrib/libarchive/tar/test/test_print_longpath.c @@ -0,0 +1,54 @@ +/*- + * Copyright (c) 2011 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_print_longpath) +{ + const char *reffile = "test_print_longpath.tar.Z"; + char buff[2048]; + int i, j, k; + + /* Reference file has one entry "file" with a very old timestamp. */ + extract_reference_file(reffile); + + /* Build long path pattern. */ + memset(buff, 0, sizeof(buff)); + for (k = 0; k < 4; k++) { + for (j = 0; j < k+1; j++) { + for (i = 0; i < 10; i++) + strncat(buff, "0123456789", + sizeof(buff) - strlen(buff) -1); + strncat(buff, "/", sizeof(buff) - strlen(buff) -1); + } + strncat(buff, "\n", sizeof(buff) - strlen(buff) -1); + } + buff[sizeof(buff)-1] = '\0'; + + assertEqualInt(0, + systemf("%s -tf %s >test.out 2>test.err", testprog, reffile)); + assertTextFileContents(buff, "test.out"); + assertEmptyFile("test.err"); +} diff --git a/contrib/libarchive/tar/test/test_print_longpath.tar.Z.uu b/contrib/libarchive/tar/test/test_print_longpath.tar.Z.uu new file mode 100644 index 0000000..05658ff --- /dev/null +++ b/contrib/libarchive/tar/test/test_print_longpath.tar.Z.uu @@ -0,0 +1,24 @@ +begin 644 test_print_longpath.tar.Z +M'YV04,+@05(F#)DR<E[`B"%C!HT:-F[@R+&PX<.($RLZA"B1(L.-&#U:Y)CQ +MX\6.&D^6'!DR)4<``&#(O%&C!HB8"VG&N"DSADZ>,H/*E$$31(P8$6_0"$H4 +M!`R+-&@``($'IM6K6+-JW<JUJ]>O8+O6F4,GC!R<8^J4"<LV[5JV8(7*!"KT +M)MR[>//JW<NWK]>C.^&$H8.FA\N6)DF*!(DR,6*6C2&O9#Q9Y6++ASN^4"`# +M!H@Q=-*T*=,CQ@P9-638\%B#L^?!HDF;1JV:M8(9.$`P22(DB)0A2))8*>)B +MC)R"H=^X"3VZ].G4-B;FP*'`K_7KV+-KW\Z]N_?O5S-75BS^,GG'D2F;?ZR^ +M?.87.&'0M(G39XV=]7_&EQO4*-(;2C%U@U,RH`;15#6`IZ!V8Y5UEDQN:1=A +M=OS1U=^"&&:H85@!#53000FYA]YX[&$VXGKIF2@9BC`%-1]0]N'7DW[\R125 +M#/XEM91,-3DU`T0TS#!551L6"5>#9J&EEH1+4BB7A7/%=**(*U+9WI185IFE +M>D;Z)0-#(`A&F&%;JGBEEFB>J::9;"JF4)GGI=EFB7&N6>><FKGV&7.R/5<; +M##/<H"=LS<T&'44U4(>;;KSY!IQPQ!F'7!K*\>D<;:M55%V7G';J:896XDEB +MBG>62N>II$8$GXL]YG<?C#36V-]1.@;5(Z`TW&!##`A^ZJM52#X(PX38$7M= +MA?M%&:JIJ38[ZK,H0EO>KW=U2)!!"+TI)[/2PHEJMY"U.%.K,[[JJHPUVB!? +MC@#N&$-J/@(I%574^AJLDF\5VR1VR/;KK;/1!KSLMP*?6"];,Y@6YF"%#0RP +MP^#:27!YVDK\\+\1BUKPBA5K#/'&%F?,;0Z;=;9G;)<>"L-T@UIJZ)\RY'!; +M;KOU]EMPPQ5W'&R5HOQRIC%O>O#07WUL-,8@>XS>JN/25RZZ,4)9(:WM]@0O +MKC3=T"O17=X+X;[7&6M=OT]*N>W$2!]]-L!<>V7MA]FJ'7+2(SLLKGSDYF3N +MTU+/!(,-[`:X4)#QVA#5D&T;Z?6P8%LGME]DUV7VW'(KO;;((27.%0TQT+#P +MF)77G?;HEY,<.MJEGPYPQZ*G3CKE2+...NRNUSYWR9Z!YK.?F>800\N[8TJ1 +M[T(3K3KF%]N.)]-X.ZTWU+'*ZAG5@G<^@X^YUJ`U"`EJKN'BC_<5/E^17W@\ +:W;-;/K?W[+?O_OOPQR___/37;__]^.>OOU<` +` +end diff --git a/contrib/libarchive/tar/test/test_strip_components.c b/contrib/libarchive/tar/test/test_strip_components.c index 271f209..25ff1ea 100644 --- a/contrib/libarchive/tar/test/test_strip_components.c +++ b/contrib/libarchive/tar/test/test_strip_components.c @@ -25,18 +25,6 @@ #include "test.h" __FBSDID("$FreeBSD$"); -static int -touch(const char *fn) -{ - FILE *f = fopen(fn, "w"); - failure("Couldn't create file '%s', errno=%d (%s)\n", - fn, errno, strerror(errno)); - if (!assert(f != NULL)) - return (0); /* Failure. */ - fclose(f); - return (1); /* Success */ -} - DEFINE_TEST(test_strip_components) { assertMakeDir("d0", 0755); @@ -44,7 +32,7 @@ DEFINE_TEST(test_strip_components) assertMakeDir("d1", 0755); assertMakeDir("d1/d2", 0755); assertMakeDir("d1/d2/d3", 0755); - assertEqualInt(1, touch("d1/d2/f1")); + assertMakeFile("d1/d2/f1", 0644, ""); assertMakeHardlink("l1", "d1/d2/f1"); assertMakeHardlink("d1/l2", "d1/d2/f1"); if (canSymlink()) { @@ -53,7 +41,15 @@ DEFINE_TEST(test_strip_components) } assertChdir(".."); - assertEqualInt(0, systemf("%s -cf test.tar d0", testprog)); + /* + * Test 1: Strip components when extracting archives. + */ + if (canSymlink()) + assertEqualInt(0, systemf("%s -cf test.tar d0/l1 d0/s1 d0/d1", + testprog)); + else + assertEqualInt(0, systemf("%s -cf test.tar d0/l1 d0/d1", + testprog)); assertMakeDir("target", 0755); assertEqualInt(0, systemf("%s -x -C target --strip-components 2 " @@ -63,6 +59,8 @@ DEFINE_TEST(test_strip_components) assertFileNotExists("target/d0"); failure("d0/d1/ is too short and should not get restored"); assertFileNotExists("target/d1"); + failure("d0/s1 is too short and should not get restored"); + assertFileNotExists("target/s1"); failure("d0/d1/s2 is a symlink to something that won't be extracted"); /* If platform supports symlinks, target/s2 is a broken symlink. */ /* If platform does not support symlink, target/s2 doesn't exist. */ @@ -73,6 +71,8 @@ DEFINE_TEST(test_strip_components) assertIsDir("target/d2", -1); /* + * Test 1b: Strip components extracting archives involving hardlinks. + * * This next is a complicated case. d0/l1, d0/d1/l2, and * d0/d1/d2/f1 are all hardlinks to the same file; d0/l1 can't * be extracted with --strip-components=2 and the other two @@ -82,18 +82,11 @@ DEFINE_TEST(test_strip_components) * which these three names get archived. If d0/l1 is first, * none of the three can be restored. If either of the longer * names are first, then the two longer ones can both be - * restored. - * - * The tree-walking code used by bsdtar always visits files - * before subdirectories, so bsdtar's behavior is fortunately - * deterministic: d0/l1 will always get stored first and the - * other two will be stored as hardlinks to d0/l1. Since - * d0/l1 can't be extracted, none of these three will be - * extracted. + * restored. Note that the "tar -cf" command above explicitly + * lists d0/l1 before d0/d1. * - * It may be worth extending this test to force a particular - * archiving order so as to exercise both of the cases described - * above. + * It may be worth extending this test to exercise other + * archiving orders. * * Of course, this is all totally different for cpio and newc * formats because the hardlink management is different. @@ -106,4 +99,41 @@ DEFINE_TEST(test_strip_components) assertFileNotExists("target/l2"); failure("d0/d1/d2/f1 is a hardlink to file whose name was too short"); assertFileNotExists("target/d2/f1"); + + /* + * Test 2: Strip components when creating archives. + */ + if (canSymlink()) + assertEqualInt(0, systemf("%s --strip-components 2 -cf test2.tar " + "d0/l1 d0/s1 d0/d1", testprog)); + else + assertEqualInt(0, systemf("%s --strip-components 2 -cf test2.tar " + "d0/l1 d0/d1", testprog)); + + assertMakeDir("target2", 0755); + assertEqualInt(0, systemf("%s -x -C target2 -f test2.tar", testprog)); + + failure("d0/ is too short and should not have been archived"); + assertFileNotExists("target2/d0"); + failure("d0/d1/ is too short and should not have been archived"); + assertFileNotExists("target2/d1"); + failure("d0/s1 is too short and should not get restored"); + assertFileNotExists("target/s1"); + /* If platform supports symlinks, target/s2 is included. */ + if (canSymlink()) { + failure("d0/d1/s2 is a symlink to something included in archive"); + assertIsSymlink("target2/s2", "d2/f1"); + } + failure("d0/d1/d2 should be archived"); + assertIsDir("target2/d2", -1); + + /* + * Test 2b: Strip components creating archives involving hardlinks. + */ + failure("d0/l1 is too short and should not have been archived"); + assertFileNotExists("target/l1"); + failure("d0/d1/l2 is a hardlink to file whose name was too short"); + assertFileNotExists("target/l2"); + failure("d0/d1/d2/f1 is a hardlink to file whose name was too short"); + assertFileNotExists("target/d2/f1"); } diff --git a/contrib/libarchive/tar/test/test_symlink_dir.c b/contrib/libarchive/tar/test/test_symlink_dir.c index f0cfebb..96bc3a4 100644 --- a/contrib/libarchive/tar/test/test_symlink_dir.c +++ b/contrib/libarchive/tar/test/test_symlink_dir.c @@ -31,38 +31,22 @@ __FBSDID("$FreeBSD$"); * way of a dir extraction. */ -static int -mkfile(const char *name, int mode, const char *contents, size_t size) -{ - FILE *f = fopen(name, "wb"); - size_t written; - - (void)mode; /* UNUSED */ - if (f == NULL) - return (-1); - written = fwrite(contents, 1, size, f); - fclose(f); - if (size != written) - return (-1); - return (0); -} - DEFINE_TEST(test_symlink_dir) { assertUmask(0); assertMakeDir("source", 0755); - assertEqualInt(0, mkfile("source/file", 0755, "a", 1)); - assertEqualInt(0, mkfile("source/file2", 0755, "ab", 2)); + assertMakeFile("source/file", 0755, "a"); + assertMakeFile("source/file2", 0755, "ab"); assertMakeDir("source/dir", 0755); assertMakeDir("source/dir/d", 0755); - assertEqualInt(0, mkfile("source/dir/f", 0755, "abc", 3)); + assertMakeFile("source/dir/f", 0755, "abc"); assertMakeDir("source/dir2", 0755); assertMakeDir("source/dir2/d2", 0755); - assertEqualInt(0, mkfile("source/dir2/f2", 0755, "abcd", 4)); + assertMakeFile("source/dir2/f2", 0755, "abcd"); assertMakeDir("source/dir3", 0755); assertMakeDir("source/dir3/d3", 0755); - assertEqualInt(0, mkfile("source/dir3/f3", 0755, "abcde", 5)); + assertMakeFile("source/dir3/f3", 0755, "abcde"); assertEqualInt(0, systemf("%s -cf test.tar -C source dir dir2 dir3 file file2", @@ -82,11 +66,11 @@ DEFINE_TEST(test_symlink_dir) skipping("some symlink checks"); } /* "dir3" is a symlink to an existing "non_dir3" */ - assertEqualInt(0, mkfile("dest1/non_dir3", 0755, "abcdef", 6)); + assertMakeFile("dest1/non_dir3", 0755, "abcdef"); if (canSymlink()) assertMakeSymlink("dest1/dir3", "non_dir3"); /* "file" is a symlink to existing "real_file" */ - assertEqualInt(0, mkfile("dest1/real_file", 0755, "abcdefg", 7)); + assertMakeFile("dest1/real_file", 0755, "abcdefg"); if (canSymlink()) { assertMakeSymlink("dest1/file", "real_file"); /* "file2" is a symlink to non-existing "real_file2" */ @@ -122,11 +106,11 @@ DEFINE_TEST(test_symlink_dir) if (canSymlink()) assertMakeSymlink("dest2/dir2", "real_dir2"); /* "dir3" is a symlink to an existing "non_dir3" */ - assertEqualInt(0, mkfile("dest2/non_dir3", 0755, "abcdefgh", 8)); + assertMakeFile("dest2/non_dir3", 0755, "abcdefgh"); if (canSymlink()) assertMakeSymlink("dest2/dir3", "non_dir3"); /* "file" is a symlink to existing "real_file" */ - assertEqualInt(0, mkfile("dest2/real_file", 0755, "abcdefghi", 9)); + assertMakeFile("dest2/real_file", 0755, "abcdefghi"); if (canSymlink()) assertMakeSymlink("dest2/file", "real_file"); /* "file2" is a symlink to non-existing "real_file2" */ |