diff options
Diffstat (limited to 'lib/libarchive')
42 files changed, 2236 insertions, 349 deletions
diff --git a/lib/libarchive/test/Makefile b/lib/libarchive/test/Makefile index 3dc7fc6..d266d82 100644 --- a/lib/libarchive/test/Makefile +++ b/lib/libarchive/test/Makefile @@ -17,6 +17,7 @@ TESTS= \ test_compat_gtar.c \ test_compat_gzip.c \ test_compat_tar_hardlink.c \ + test_compat_xz.c \ test_compat_zip.c \ test_empty_write.c \ test_entry.c \ @@ -24,10 +25,14 @@ TESTS= \ test_extattr_freebsd.c \ test_fuzz.c \ test_link_resolver.c \ + test_open_fd.c \ + test_open_file.c \ + test_open_filename.c \ test_pax_filename_encoding.c \ test_read_compress_program.c \ test_read_data_large.c \ test_read_disk.c \ + test_read_disk_entry_from_file.c \ test_read_extract.c \ test_read_file_nonexistent.c \ test_read_format_ar.c \ @@ -35,13 +40,16 @@ TESTS= \ test_read_format_cpio_bin_Z.c \ test_read_format_cpio_bin_bz2.c \ test_read_format_cpio_bin_gz.c \ + test_read_format_cpio_bin_xz.c \ test_read_format_cpio_odc.c \ test_read_format_cpio_svr4_gzip.c \ test_read_format_cpio_svr4c_Z.c \ test_read_format_empty.c \ test_read_format_gtar_gz.c \ + test_read_format_gtar_lzma.c \ test_read_format_gtar_sparse.c \ test_read_format_iso_gz.c \ + test_read_format_isojoliet_bz2.c \ test_read_format_isorr_bz2.c \ test_read_format_mtree.c \ test_read_format_pax_bz2.c \ @@ -49,6 +57,7 @@ TESTS= \ test_read_format_tar_empty_filename.c \ test_read_format_tbz.c \ test_read_format_tgz.c \ + test_read_format_txz.c \ test_read_format_tz.c \ test_read_format_zip.c \ test_read_large.c \ @@ -59,7 +68,11 @@ TESTS= \ test_tar_large.c \ test_ustar_filenames.c \ test_write_compress.c \ + test_write_compress_bzip2.c \ + test_write_compress_gzip.c \ + test_write_compress_lzma.c \ test_write_compress_program.c \ + test_write_compress_xz.c \ test_write_disk.c \ test_write_disk_failures.c \ test_write_disk_hardlink.c \ @@ -72,6 +85,7 @@ TESTS= \ test_write_format_cpio_empty.c \ test_write_format_cpio_newc.c \ test_write_format_cpio_odc.c \ + test_write_format_mtree.c \ test_write_format_pax.c \ test_write_format_shar_empty.c \ test_write_format_tar.c \ @@ -93,10 +107,18 @@ PROG=libarchive_test INTERNALPROG=yes # Don't install this; it's just for testing DPADD=${LIBBZ2} ${LIBZ} CFLAGS+= -DPLATFORM_CONFIG_H=\"config_freebsd.h\" -LDADD= -lz -lbz2 -CFLAGS+= -static -g +LDADD= -lz -lbz2 -lmd -lcrypto +CFLAGS+= -g CFLAGS+= -I${LA_SRCDIR} -I. +# Uncomment to build and test lzma support via liblzmadec +#CFLAGS+= -I/usr/local/include -DHAVE_LIBLZMADEC=1 -DHAVE_LZMADEC_H=1 +#LDADD+= -L/usr/local/lib -llzmadec + +# Uncomment to build and test lzma and xz support via liblzma +CFLAGS+= -I/usr/local/include -DHAVE_LIBLZMA=1 -DHAVE_LZMA_H=1 +LDADD+= -L/usr/local/lib -llzma + # Uncomment to link against dmalloc #LDADD+= -L/usr/local/lib -ldmalloc #CFLAGS+= -I/usr/local/include -DUSE_DMALLOC @@ -108,9 +130,10 @@ check test: libarchive_test # list.h is just a list of all tests, as indicated by DEFINE_TEST macro lines list.h: ${TESTS} Makefile - (cd ${.CURDIR}; cat ${TESTS}) | grep DEFINE_TEST > list.h + (cd ${.CURDIR}; cat test_*.c) | grep DEFINE_TEST > list.h -CLEANFILES += *.out *.o *.core *~ list.h +CLEANFILES += *.out *.o *.core *~ list.h .dirstamp .depend +CLEANDIRS += .deps .libs cleantest: -chmod -R +w /tmp/libarchive_test.* diff --git a/lib/libarchive/test/main.c b/lib/libarchive/test/main.c index 01a0817..4022370 100644 --- a/lib/libarchive/test/main.c +++ b/lib/libarchive/test/main.c @@ -62,11 +62,7 @@ __FBSDID("$FreeBSD$"); */ #undef DEFINE_TEST #define DEFINE_TEST(name) void name(void); -#ifdef LIST_H -#include LIST_H -#else #include "list.h" -#endif /* Interix doesn't define these in a standard header. */ #if __INTERIX__ @@ -128,13 +124,28 @@ static const char *failed_filename = NULL; static struct line { int line; int count; + int critical; } failed_lines[1000]; /* + * Called at the beginning of each assert() function. + */ +static void +count_assertion(const char *file, int line) +{ + (void)file; /* UNUSED */ + (void)line; /* UNUSED */ + ++assertions; + /* Uncomment to print file:line after every assertion. + * Verbose, but occasionally useful in tracking down crashes. */ + /* printf("Checked %s:%d\n", file, line); */ +} + +/* * Count this failure; return the number of previous failures. */ static int -previous_failures(const char *filename, int line) +previous_failures(const char *filename, int line, int critical) { unsigned int i; int count; @@ -152,6 +163,7 @@ previous_failures(const char *filename, int line) if (failed_lines[i].line == 0) { failed_lines[i].line = line; failed_lines[i].count = 1; + failed_lines[i].critical = critical; return (0); } } @@ -178,7 +190,7 @@ test_skipping(const char *fmt, ...) { va_list ap; - if (previous_failures(test_filename, test_line)) + if (previous_failures(test_filename, test_line, 0)) return; va_start(ap, fmt); @@ -241,7 +253,7 @@ summarize(void) for (i = 0; i < sizeof(failed_lines)/sizeof(failed_lines[0]); i++) { if (failed_lines[i].line == 0) break; - if (failed_lines[i].count > 1) + if (failed_lines[i].count > 1 && failed_lines[i].critical) fprintf(stderr, "%s:%d: Failed %d times\n", failed_filename, failed_lines[i].line, failed_lines[i].count); @@ -264,13 +276,13 @@ failure(const char *fmt, ...) int test_assert(const char *file, int line, int value, const char *condition, void *extra) { - ++assertions; + count_assertion(file, line); if (value) { msg[0] = '\0'; return (value); } failures ++; - if (!verbose && previous_failures(file, line)) + if (!verbose && previous_failures(file, line, 1)) return (value); fprintf(stderr, "%s:%d: Assertion failed\n", file, line); fprintf(stderr, " Condition: %s\n", condition); @@ -283,13 +295,13 @@ int test_assert_equal_int(const char *file, int line, int v1, const char *e1, int v2, const char *e2, void *extra) { - ++assertions; + count_assertion(file, line); if (v1 == v2) { msg[0] = '\0'; return (1); } failures ++; - if (!verbose && previous_failures(file, line)) + if (!verbose && previous_failures(file, line, 1)) return (0); fprintf(stderr, "%s:%d: Assertion failed: Ints not equal\n", file, line); @@ -330,7 +342,7 @@ test_assert_equal_string(const char *file, int line, const char *v2, const char *e2, void *extra) { - ++assertions; + count_assertion(file, line); if (v1 == NULL || v2 == NULL) { if (v1 == v2) { msg[0] = '\0'; @@ -341,7 +353,7 @@ test_assert_equal_string(const char *file, int line, return (1); } failures ++; - if (!verbose && previous_failures(file, line)) + if (!verbose && previous_failures(file, line, 1)) return (0); fprintf(stderr, "%s:%d: Assertion failed: Strings not equal\n", file, line); @@ -383,7 +395,7 @@ test_assert_equal_wstring(const char *file, int line, const wchar_t *v2, const char *e2, void *extra) { - ++assertions; + count_assertion(file, line); if (v1 == NULL) { if (v2 == NULL) { msg[0] = '\0'; @@ -399,7 +411,7 @@ test_assert_equal_wstring(const char *file, int line, return (1); } failures ++; - if (!verbose && previous_failures(file, line)) + if (!verbose && previous_failures(file, line, 1)) return (0); fprintf(stderr, "%s:%d: Assertion failed: Unicode strings not equal\n", file, line); @@ -458,7 +470,7 @@ test_assert_equal_mem(const char *file, int line, const char *v2, const char *e2, size_t l, const char *ld, void *extra) { - ++assertions; + count_assertion(file, line); if (v1 == NULL || v2 == NULL) { if (v1 == v2) { msg[0] = '\0'; @@ -469,7 +481,7 @@ test_assert_equal_mem(const char *file, int line, return (1); } failures ++; - if (!verbose && previous_failures(file, line)) + if (!verbose && previous_failures(file, line, 1)) return (0); fprintf(stderr, "%s:%d: Assertion failed: memory not equal\n", file, line); @@ -507,7 +519,7 @@ test_assert_empty_file(const char *f1fmt, ...) return (1); failures ++; - if (!verbose && previous_failures(test_filename, test_line)) + if (!verbose && previous_failures(test_filename, test_line, 1)) return (0); fprintf(stderr, "%s:%d: File not empty: %s\n", test_filename, test_line, f1); @@ -554,7 +566,7 @@ test_assert_equal_file(const char *f1, const char *f2pattern, ...) break; } failures ++; - if (!verbose && previous_failures(test_filename, test_line)) + if (!verbose && previous_failures(test_filename, test_line, 1)) return (0); fprintf(stderr, "%s:%d: Files are not identical\n", test_filename, test_line); @@ -576,7 +588,7 @@ test_assert_file_exists(const char *fpattern, ...) if (!access(f, F_OK)) return (1); - if (!previous_failures(test_filename, test_line)) { + if (!previous_failures(test_filename, test_line, 1)) { fprintf(stderr, "%s:%d: File doesn't exist\n", test_filename, test_line); fprintf(stderr, " file=\"%s\"\n", f); @@ -597,7 +609,7 @@ test_assert_file_not_exists(const char *fpattern, ...) if (access(f, F_OK)) return (1); - if (!previous_failures(test_filename, test_line)) { + if (!previous_failures(test_filename, test_line, 1)) { fprintf(stderr, "%s:%d: File exists and shouldn't\n", test_filename, test_line); fprintf(stderr, " file=\"%s\"\n", f); @@ -628,7 +640,7 @@ test_assert_file_contents(const void *buff, int s, const char *fpattern, ...) return (1); } failures ++; - if (!previous_failures(test_filename, test_line)) { + if (!previous_failures(test_filename, test_line, 1)) { fprintf(stderr, "%s:%d: File contents don't match\n", test_filename, test_line); fprintf(stderr, " file=\"%s\"\n", f); @@ -722,13 +734,19 @@ slurpfile(size_t * sizep, const char *fmt, ...) #undef DEFINE_TEST #define DEFINE_TEST(n) { n, #n }, struct { void (*func)(void); const char *name; } tests[] = { -#ifdef LIST_H - #include LIST_H -#else #include "list.h" -#endif }; +/* + * This is well-intentioned, but sometimes the standard libraries + * leave open file descriptors and expect to be able to come back to + * them (e.g., for username lookups or logging). Closing these + * descriptors out from under those libraries creates havoc. + * + * Maybe there's some reasonably portable way to tell if a descriptor + * is open without using close()? + */ +#if 0 static void close_descriptors(int warn) { @@ -745,6 +763,7 @@ close_descriptors(int warn) report_failure(NULL); } } +#endif /* * Each test is run in a private work dir. Those work dirs @@ -788,11 +807,12 @@ static int test_run(int i, const char *tmpdir) /* Explicitly reset the locale before each test. */ setlocale(LC_ALL, "C"); /* Make sure there are no stray descriptors going into the test. */ - close_descriptors(0); + /* TODO: Find a better way to identify file descriptor leaks. */ + //close_descriptors(0); /* Run the actual test. */ (*tests[i].func)(); /* Close stray descriptors, record as errors against this test. */ - close_descriptors(1); + //close_descriptors(1); /* Summarize the results of this test. */ summarize(); /* If there were no failures, we can remove the work dir. */ @@ -894,30 +914,34 @@ extract_reference_file(const char *name) fclose(in); } -#if defined(_WIN32) && !defined(__CYGWIN__) -#define DEV_NULL "NUL" -#else -#define DEV_NULL "/dev/null" -#endif +/* Since gzip is by far the most popular external compression program + * available, we try to use it in the read_program and write_program + * tests. But if it's not available, then we can't use it. This + * function just tries to run gzip/gunzip to see if they're available. + * If not, some of the external compression program tests will be + * skipped. */ const char * external_gzip_program(int un) { - const char *extprog; - - if (un) { - extprog = "gunzip"; - if (systemf("%s -V >" DEV_NULL " 2>" DEV_NULL, extprog) == 0) - return (extprog); - extprog = "gzip -d"; - if (systemf("%s -V >" DEV_NULL " 2>" DEV_NULL, extprog) == 0) - return (extprog); - } else { - extprog = "gzip"; - if (systemf("%s -V >" DEV_NULL " 2>" DEV_NULL, extprog) == 0) - return (extprog); + static int tested = 0; + static const char *compress_prog = NULL; + static const char *decompress_prog = NULL; + /* Args vary depending on the command interpreter we're using. */ +#if defined(_WIN32) && !defined(__CYGWIN__) + static const char *args = "-V >NUL 2>NUL"; /* Win32 cmd.exe */ +#else + static const char *args = "-V >/dev/null 2>/dev/null"; /* POSIX 'sh' */ +#endif + + if (!tested) { + if (systemf("gunzip %s", args) == 0) + decompress_prog = "gunzip"; + if (systemf("gzip %s", args) == 0) + compress_prog = "gzip"; + tested = 1; } - return (NULL); + return (un ? decompress_prog : compress_prog); } static char * @@ -1144,16 +1168,30 @@ int main(int argc, char **argv) } } else { while (*(argv) != NULL) { - i = atoi(*argv); - if (**argv < '0' || **argv > '9' || i < 0 || i >= limit) { - printf("*** INVALID Test %s\n", *argv); - free(refdir_alloc); - usage(progname); + 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 */ + } } else { - if (test_run(i, tmpdir)) - tests_failed++; - tests_run++; + for (i = 0; i < limit; ++i) { + if (strcmp(*argv, tests[i].name) == 0) + break; + } + if (i >= limit) { + printf("*** INVALID Test ``%s''\n", + *argv); + free(refdir_alloc); + usage(progname); + /* usage() never returns */ + } } + if (test_run(i, tmpdir)) + tests_failed++; + tests_run++; argv++; } } diff --git a/lib/libarchive/test/read_open_memory.c b/lib/libarchive/test/read_open_memory.c index 312e9ad..17e7f75 100644 --- a/lib/libarchive/test/read_open_memory.c +++ b/lib/libarchive/test/read_open_memory.c @@ -96,7 +96,7 @@ read_open_memory_internal(struct archive *a, void *buff, memory_read, memory_read_skip, memory_read_close)); else return (archive_read_open2(a, mine, NULL, - memory_read, NULL, NULL)); + memory_read, NULL, memory_read_close)); } /* diff --git a/lib/libarchive/test/test_compat_bzip2.c b/lib/libarchive/test/test_compat_bzip2.c index 4b2cf05..cbd113b 100644 --- a/lib/libarchive/test/test_compat_bzip2.c +++ b/lib/libarchive/test/test_compat_bzip2.c @@ -44,7 +44,7 @@ compat_bzip2(const char *name) const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL }; struct archive_entry *ae; struct archive *a; - int i,r; + int i; assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); @@ -54,19 +54,9 @@ compat_bzip2(const char *name) /* Read entries, match up names with list above. */ for (i = 0; i < 6; ++i) { - r = archive_read_next_header(a, &ae); - if (UnsupportedCompress(r, a)) { - skipping("Skipping BZIP2 compression check: " - "This version of libarchive was compiled " - "without bzip2 support"); - goto finish; - } failure("Could not read file %d (%s) from %s", i, n[i], name); - assertEqualIntA(a, ARCHIVE_OK, r); - if (r != ARCHIVE_OK) { - archive_read_finish(a); - return; - } + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); assertEqualString(n[i], archive_entry_pathname(ae)); } @@ -79,12 +69,7 @@ compat_bzip2(const char *name) assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); assertEqualInt(ARCHIVE_OK, archive_read_close(a)); -finish: -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -#endif } diff --git a/lib/libarchive/test/test_compat_gzip.c b/lib/libarchive/test/test_compat_gzip.c index 25cdc2b..eb9981d 100644 --- a/lib/libarchive/test/test_compat_gzip.c +++ b/lib/libarchive/test/test_compat_gzip.c @@ -47,22 +47,22 @@ verify(const char *name) int i,r; assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_gzip(a); + if (r == ARCHIVE_WARN) { + skipping("gzip reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, r); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); extract_reference_file(name); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 200)); /* Read entries, match up names with list above. */ for (i = 0; i < 6; ++i) { - r = archive_read_next_header(a, &ae); - if (UnsupportedCompress(r, a)) { - skipping("Skipping GZIP compression check: " - "This version of libarchive was compiled " - "without gzip support"); - goto finish; - } failure("Could not read file %d (%s) from %s", i, n[i], name); - assertEqualIntA(a, ARCHIVE_OK, r); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); if (r != ARCHIVE_OK) { archive_read_finish(a); return; @@ -79,12 +79,7 @@ verify(const char *name) assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); assertEqualInt(ARCHIVE_OK, archive_read_close(a)); -finish: -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -#endif } diff --git a/lib/libarchive/test/test_compat_xz.c b/lib/libarchive/test/test_compat_xz.c new file mode 100644 index 0000000..9041427 --- /dev/null +++ b/lib/libarchive/test/test_compat_xz.c @@ -0,0 +1,84 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * Copyright (c) 2003-2008 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$"); + +/* + * Verify our ability to read sample files compatibly with unxz. + * + * In particular: + * * unxz will read multiple xz streams, concatenating the output + */ + +/* + * All of the sample files have the same contents; they're just + * compressed in different ways. + */ +static void +compat_xz(const char *name) +{ + const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL }; + struct archive_entry *ae; + struct archive *a; + int i, r; + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_xz(a); + if (r == ARCHIVE_WARN) { + skipping("xz reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + extract_reference_file(name); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2)); + + /* Read entries, match up names with list above. */ + for (i = 0; i < 6; ++i) { + failure("Could not read file %d (%s) from %s", i, n[i], name); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualString(n[i], archive_entry_pathname(ae)); + } + + /* Verify the end-of-archive. */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Verify that the format detection worked. */ + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_XZ); + assertEqualString(archive_compression_name(a), "xz"); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); + + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} + + +DEFINE_TEST(test_compat_xz) +{ + compat_xz("test_compat_xz_1.txz"); +} diff --git a/lib/libarchive/test/test_compat_xz_1.txz.uu b/lib/libarchive/test/test_compat_xz_1.txz.uu new file mode 100644 index 0000000..82794fd --- /dev/null +++ b/lib/libarchive/test/test_compat_xz_1.txz.uu @@ -0,0 +1,13 @@ +$FreeBSD$ +begin 644 test_compat_gzip_1.txz +M_3=Z6%H```3FUK1&`@`A`18```!T+^6CX`^?`(-=`#,,/!NGC#0&C6L"2_R2 +M/O9*^(7KX=WM^(=KA(RH"\09$$)!Q_+JUHQ*`]R;ITL_F3/I6:^Q0550A&)B +MHS@=K]7@K1-9FOIP#PU!I<PUHW+W#<F(6FSL/<?5:4*>?E5&IHH&Q=N>_C&G +M-$G]+L[\,B<7%8&$NO5K31*Y>"D^*ZG,Z=H```"KU50H$1^1S``!GP&@'P`` +MLZ042+'$9_L"``````196OTW>EA:```$YM:T1@(`(0$6````="_EH^`,7P!I +M70``;IBIKOMK%/A?-<U3^2)5\V,DQ(:ZUH:[B'3>TZV0266G?2,[/?\,JE6` +M__C/SA[W1?*2<Y3NQ'DCK4JEJYHQU`Q\N=H9LL3KRAH,VQQ2OD*@?1NLV]<E +MF&X."!L\R:Z]=*TJPT/BJ^``````R[PG*'(H!W,``84!X!@``/;+`G2QQ&?[ +(`@`````$65H` +` +end diff --git a/lib/libarchive/test/test_entry.c b/lib/libarchive/test/test_entry.c index fd1b2f2..b79e822 100644 --- a/lib/libarchive/test/test_entry.c +++ b/lib/libarchive/test/test_entry.c @@ -137,11 +137,17 @@ DEFINE_TEST(test_entry) assertEqualString(archive_entry_hardlink(e), "hardlinkname2"); memset(buff, 0, sizeof(buff)); assertEqualString(archive_entry_hardlink(e), "hardlinkname2"); + archive_entry_copy_hardlink(e, NULL); + assertEqualString(archive_entry_hardlink(e), NULL); + assertEqualWString(archive_entry_hardlink_w(e), NULL); wcscpy(wbuff, L"whardlink"); archive_entry_copy_hardlink_w(e, wbuff); assertEqualWString(archive_entry_hardlink_w(e), L"whardlink"); memset(wbuff, 0, sizeof(wbuff)); assertEqualWString(archive_entry_hardlink_w(e), L"whardlink"); + archive_entry_copy_hardlink_w(e, NULL); + assertEqualString(archive_entry_hardlink(e), NULL); + assertEqualWString(archive_entry_hardlink_w(e), NULL); #if ARCHIVE_VERSION_NUMBER >= 1009000 /* ino */ archive_entry_set_ino(e, 8593); @@ -233,6 +239,10 @@ DEFINE_TEST(test_entry) assertEqualInt(archive_entry_size(e), 0); assert(!archive_entry_size_is_set(e)); + /* sourcepath */ + archive_entry_copy_sourcepath(e, "path1"); + assertEqualString(archive_entry_sourcepath(e), "path1"); + /* symlink */ archive_entry_set_symlink(e, "symlinkname"); assertEqualString(archive_entry_symlink(e), "symlinkname"); @@ -243,8 +253,14 @@ DEFINE_TEST(test_entry) memset(buff, 0, sizeof(buff)); assertEqualString(archive_entry_symlink(e), "symlinkname2"); #endif + archive_entry_copy_symlink_w(e, NULL); + assertEqualWString(archive_entry_symlink_w(e), NULL); + assertEqualString(archive_entry_symlink(e), NULL); archive_entry_copy_symlink_w(e, L"wsymlink"); assertEqualWString(archive_entry_symlink_w(e), L"wsymlink"); + archive_entry_copy_symlink(e, NULL); + assertEqualWString(archive_entry_symlink_w(e), NULL); + assertEqualString(archive_entry_symlink(e), NULL); /* uid */ archive_entry_set_uid(e, 83); @@ -271,9 +287,13 @@ DEFINE_TEST(test_entry) /* TODO: Make this system-independent. */ assertEqualString(archive_entry_fflags_text(e), "uappnd,nouchg,nodump,noopaque,uunlnk"); - /* TODO: Test archive_entry_copy_fflags_text_w() */ + /* Test archive_entry_copy_fflags_text_w() */ + archive_entry_copy_fflags_text_w(e, L" ,nouappnd, nouchg, dump,uunlnk"); + archive_entry_fflags(e, &set, &clear); + assertEqualInt(16, set); + assertEqualInt(7, clear); /* Test archive_entry_copy_fflags_text() */ - archive_entry_copy_fflags_text(e, "nouappnd, nouchg, dump,uunlnk"); + archive_entry_copy_fflags_text(e, " ,nouappnd, nouchg, dump,uunlnk"); archive_entry_fflags(e, &set, &clear); assertEqualInt(16, set); assertEqualInt(7, clear); @@ -343,6 +363,7 @@ DEFINE_TEST(test_entry) archive_entry_set_rdev(e, 532); #endif archive_entry_set_size(e, 987654321); + archive_entry_copy_sourcepath(e, "source"); archive_entry_set_symlink(e, "symlinkname"); archive_entry_set_uid(e, 83); archive_entry_set_uname(e, "user"); @@ -385,6 +406,7 @@ DEFINE_TEST(test_entry) assertEqualInt(archive_entry_rdev(e2), 532); #endif assertEqualInt(archive_entry_size(e2), 987654321); + assertEqualString(archive_entry_sourcepath(e2), "source"); assertEqualString(archive_entry_symlink(e2), "symlinkname"); assertEqualInt(archive_entry_uid(e2), 83); assertEqualString(archive_entry_uname(e2), "user"); @@ -472,6 +494,7 @@ DEFINE_TEST(test_entry) archive_entry_set_rdev(e, 132); #endif archive_entry_set_size(e, 987456321); + archive_entry_copy_sourcepath(e, "source2"); archive_entry_set_symlink(e, "symlinkpath"); archive_entry_set_uid(e, 93); archive_entry_set_uname(e, "username"); @@ -508,6 +531,7 @@ DEFINE_TEST(test_entry) assertEqualInt(archive_entry_rdev(e2), 532); #endif assertEqualInt(archive_entry_size(e2), 987654321); + assertEqualString(archive_entry_sourcepath(e2), "source"); assertEqualString(archive_entry_symlink(e2), "symlinkname"); assertEqualInt(archive_entry_uid(e2), 83); assertEqualString(archive_entry_uname(e2), "user"); diff --git a/lib/libarchive/test/test_entry_strmode.c b/lib/libarchive/test/test_entry_strmode.c index 43b01b4..5ede8b6 100644 --- a/lib/libarchive/test/test_entry_strmode.c +++ b/lib/libarchive/test/test_entry_strmode.c @@ -34,15 +34,38 @@ DEFINE_TEST(test_entry_strmode) archive_entry_set_mode(entry, S_IFREG | 0642); assertEqualString(archive_entry_strmode(entry), "-rw-r---w- "); + /* Regular file + hardlink still shows as regular file. */ + archive_entry_set_mode(entry, S_IFREG | 0644); + archive_entry_set_hardlink(entry, "link"); + assertEqualString(archive_entry_strmode(entry), "-rw-r--r-- "); + + archive_entry_set_mode(entry, 0640); + archive_entry_set_hardlink(entry, "link"); + assertEqualString(archive_entry_strmode(entry), "hrw-r----- "); + archive_entry_set_hardlink(entry, NULL); + + archive_entry_set_mode(entry, S_IFDIR | 0777); + assertEqualString(archive_entry_strmode(entry), "drwxrwxrwx "); + archive_entry_set_mode(entry, S_IFBLK | 03642); assertEqualString(archive_entry_strmode(entry), "brw-r-S-wT "); archive_entry_set_mode(entry, S_IFCHR | 05777); assertEqualString(archive_entry_strmode(entry), "crwsrwxrwt "); + archive_entry_set_mode(entry, S_IFSOCK | 0222); + assertEqualString(archive_entry_strmode(entry), "s-w--w--w- "); + + archive_entry_set_mode(entry, S_IFIFO | 0444); + assertEqualString(archive_entry_strmode(entry), "pr--r--r-- "); + archive_entry_set_mode(entry, S_IFLNK | 04000); assertEqualString(archive_entry_strmode(entry), "l--S------ "); + archive_entry_acl_add_entry(entry, ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + 0007, ARCHIVE_ENTRY_ACL_GROUP, 78, "group78"); + assertEqualString(archive_entry_strmode(entry), "l--S------+"); + /* Release the experimental entry. */ archive_entry_free(entry); } diff --git a/lib/libarchive/test/test_extattr_freebsd.c b/lib/libarchive/test/test_extattr_freebsd.c index 7d2abb9..19881c2 100644 --- a/lib/libarchive/test/test_extattr_freebsd.c +++ b/lib/libarchive/test/test_extattr_freebsd.c @@ -169,5 +169,6 @@ DEFINE_TEST(test_extattr_freebsd) assertEqualMem(xval, "12345", xsize); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + archive_entry_free(ae); #endif } diff --git a/lib/libarchive/test/test_open_fd.c b/lib/libarchive/test/test_open_fd.c new file mode 100644 index 0000000..0aec1d5 --- /dev/null +++ b/lib/libarchive/test/test_open_fd.c @@ -0,0 +1,117 @@ +/*- + * Copyright (c) 2003-2007 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_open_fd) +{ + char buff[64]; + struct archive_entry *ae; + struct archive *a; + int fd; + + fd = open("test.tar", O_RDWR | O_CREAT, 0777); + assert(fd >= 0); + if (fd < 0) + return; + + /* Write an archive through this fd. */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_open_fd(a, fd)); + + /* + * Write a file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 1, 0); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 8); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); + + /* + * Write a second file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file2"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 819200); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + + /* Close out the archive. */ + assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + /* + * Now, read the data back. + */ + assert(lseek(fd, 0, SEEK_SET) == 0); + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_fd(a, fd, 512)); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(1, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + assertEqualInt(0, archive_entry_atime(ae)); + assertEqualInt(0, archive_entry_ctime(ae)); + assertEqualString("file", archive_entry_pathname(ae)); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assertEqualInt(8, archive_entry_size(ae)); + assertEqualIntA(a, 8, archive_read_data(a, buff, 10)); + assertEqualMem(buff, "12345678", 8); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("file2", archive_entry_pathname(ae)); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assertEqualInt(819200, archive_entry_size(ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_data_skip(a)); + + /* Verify the end of the archive. */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + close(fd); + + + /* + * Verify some of the error handling. + */ + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + /* FD 100 shouldn't be open. */ + assertEqualIntA(a, ARCHIVE_FATAL, + archive_read_open_fd(a, 100, 512)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} diff --git a/lib/libarchive/test/test_open_file.c b/lib/libarchive/test/test_open_file.c new file mode 100644 index 0000000..e931163 --- /dev/null +++ b/lib/libarchive/test/test_open_file.c @@ -0,0 +1,108 @@ +/*- + * Copyright (c) 2003-2007 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_open_file) +{ + char buff[64]; + struct archive_entry *ae; + struct archive *a; + FILE *f; + + f = fopen("test.tar", "w"); + assert(f != NULL); + if (f == NULL) + return; + + /* Write an archive through this FILE *. */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_open_FILE(a, f)); + + /* + * Write a file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 1, 0); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 8); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); + + /* + * Write a second file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file2"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 819200); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + + /* Close out the archive. */ + assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + fclose(f); + + /* + * Now, read the data back. + */ + f = fopen("test.tar", "r"); + assert(f != NULL); + if (f == NULL) + return; + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_FILE(a, f)); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(1, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + assertEqualInt(0, archive_entry_atime(ae)); + assertEqualInt(0, archive_entry_ctime(ae)); + assertEqualString("file", archive_entry_pathname(ae)); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assertEqualInt(8, archive_entry_size(ae)); + assertEqualIntA(a, 8, archive_read_data(a, buff, 10)); + assertEqualMem(buff, "12345678", 8); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("file2", archive_entry_pathname(ae)); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assertEqualInt(819200, archive_entry_size(ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_data_skip(a)); + + /* Verify the end of the archive. */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + fclose(f); +} diff --git a/lib/libarchive/test/test_open_filename.c b/lib/libarchive/test/test_open_filename.c new file mode 100644 index 0000000..b096afc --- /dev/null +++ b/lib/libarchive/test/test_open_filename.c @@ -0,0 +1,109 @@ +/*- + * Copyright (c) 2003-2007 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_open_filename) +{ + char buff[64]; + struct archive_entry *ae; + struct archive *a; + + /* Write an archive through this FILE *. */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_open_filename(a, "test.tar")); + + /* + * Write a file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 1, 0); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 8); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); + + /* + * Write a second file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file2"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 819200); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + + /* Close out the archive. */ + assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + /* + * Now, read the data back. + */ + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_filename(a, "test.tar", 512)); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(1, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + assertEqualInt(0, archive_entry_atime(ae)); + assertEqualInt(0, archive_entry_ctime(ae)); + assertEqualString("file", archive_entry_pathname(ae)); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assertEqualInt(8, archive_entry_size(ae)); + assertEqualIntA(a, 8, archive_read_data(a, buff, 10)); + assertEqualMem(buff, "12345678", 8); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("file2", archive_entry_pathname(ae)); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assertEqualInt(819200, archive_entry_size(ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_data_skip(a)); + + /* Verify the end of the archive. */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Verify some of the error handling. + */ + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_FATAL, + archive_read_open_filename(a, "nonexistent.tar", 512)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + +} diff --git a/lib/libarchive/test/test_pax_filename_encoding.c b/lib/libarchive/test/test_pax_filename_encoding.c index 0983dff..f882b28 100644 --- a/lib/libarchive/test/test_pax_filename_encoding.c +++ b/lib/libarchive/test/test_pax_filename_encoding.c @@ -57,7 +57,7 @@ DEFINE_TEST(test_pax_filename_encoding_1) extract_reference_file(testname); a = archive_read_new(); assertEqualInt(ARCHIVE_OK, archive_read_support_format_tar(a)); - assertEqualInt(ARCHIVE_OK, archive_read_support_compression_gzip(a)); + assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a)); assertEqualInt(ARCHIVE_OK, archive_read_open_filename(a, testname, 10240)); /* diff --git a/lib/libarchive/test/test_pax_filename_encoding.tar.uu b/lib/libarchive/test/test_pax_filename_encoding.tar.uu index e902c70..e7773fd 100644 --- a/lib/libarchive/test/test_pax_filename_encoding.tar.uu +++ b/lib/libarchive/test/test_pax_filename_encoding.tar.uu @@ -1,5 +1,4 @@ $FreeBSD$ - begin 644 test_pax_filename_encoding.tar M4&%X2&5A9&5R+V%B8\R,;6YO6'AY>@`````````````````````````````` M```````````````````````````````````````````````````````````` diff --git a/lib/libarchive/test/test_read_compress_program.c b/lib/libarchive/test/test_read_compress_program.c index 1044197..042c615 100644 --- a/lib/libarchive/test/test_read_compress_program.c +++ b/lib/libarchive/test/test_read_compress_program.c @@ -61,7 +61,7 @@ DEFINE_TEST(test_read_compress_program) assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); /* - * If we have "gunzip", try using that. + * If we have "gzip -d", try using that. */ if ((extprog = external_gzip_program(1)) == NULL) { skipping("There is no gzip uncompression " diff --git a/lib/libarchive/test/test_read_disk.c b/lib/libarchive/test/test_read_disk.c index ce10440..cd87c5b 100644 --- a/lib/libarchive/test/test_read_disk.c +++ b/lib/libarchive/test/test_read_disk.c @@ -124,21 +124,23 @@ DEFINE_TEST(test_read_disk) /* Get the group name for group 0 and see if it makes sense. */ p = archive_read_disk_gname(a, 0); - i = 0; - while (i < sizeof(zero_groups)/sizeof(zero_groups[0])) { - if (strcmp(zero_groups[i], p) == 0) - break; - ++i; - } - if (i == sizeof(zero_groups)/sizeof(zero_groups[0])) { - /* If you get a failure here, either - * archive_read_disk_gname() isn't working or - * your system uses a different name for group - * number zero. If the latter, please add a - * new entry to the zero_groups[] array above. - */ - failure("group 0 didn't have any of the expected names"); - assertEqualString(p, zero_groups[0]); + if (assert(p != NULL)) { + i = 0; + while (i < sizeof(zero_groups)/sizeof(zero_groups[0])) { + if (strcmp(zero_groups[i], p) == 0) + break; + ++i; + } + if (i == sizeof(zero_groups)/sizeof(zero_groups[0])) { + /* If you get a failure here, either + * archive_read_disk_gname() isn't working or + * your system uses a different name for group + * number zero. If the latter, please add a + * new entry to the zero_groups[] array above. + */ + failure("group 0 didn't have any of the expected names"); + assertEqualString(p, zero_groups[0]); + } } #endif } diff --git a/lib/libarchive/test/test_read_disk_entry_from_file.c b/lib/libarchive/test/test_read_disk_entry_from_file.c new file mode 100644 index 0000000..8b3b6d7 --- /dev/null +++ b/lib/libarchive/test/test_read_disk_entry_from_file.c @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 2003-2009 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 * +gname_lookup(void *d, gid_t g) +{ + (void)d; /* UNUSED */ + (void)g; /* UNUSED */ + return ("FOOGROUP"); +} + +static const char * +uname_lookup(void *d, uid_t u) +{ + (void)d; /* UNUSED */ + (void)u; /* UNUSED */ + return ("FOO"); +} + +DEFINE_TEST(test_read_disk_entry_from_file) +{ + struct archive *a; + struct archive_entry *entry; + int fd; + + assert((a = archive_read_disk_new()) != NULL); + + assertEqualInt(ARCHIVE_OK, archive_read_disk_set_uname_lookup(a, + NULL, &uname_lookup, NULL)); + assertEqualInt(ARCHIVE_OK, archive_read_disk_set_gname_lookup(a, + NULL, &gname_lookup, NULL)); + assertEqualString(archive_read_disk_uname(a, 0), "FOO"); + assertEqualString(archive_read_disk_gname(a, 0), "FOOGROUP"); + + /* Create a file on disk. */ + fd = open("foo", O_WRONLY | O_CREAT, 0777); + assert(fd >= 0); + assertEqualInt(4, write(fd, "1234", 4)); + close(fd); + + /* Use archive_read_disk_entry_from_file to get information about it. */ + entry = archive_entry_new(); + assert(entry != NULL); + archive_entry_copy_pathname(entry, "foo"); + assertEqualInt(ARCHIVE_OK, + archive_read_disk_entry_from_file(a, entry, -1, NULL)); + + /* Verify the information we got back. */ + assertEqualString(archive_entry_uname(entry), "FOO"); + assertEqualString(archive_entry_gname(entry), "FOOGROUP"); + assertEqualInt(archive_entry_size(entry), 4); + + /* Destroy the archive. */ + archive_entry_free(entry); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} diff --git a/lib/libarchive/test/test_read_format_cpio_bin_bz2.c b/lib/libarchive/test/test_read_format_cpio_bin_bz2.c index 426841b..90270c8 100644 --- a/lib/libarchive/test/test_read_format_cpio_bin_bz2.c +++ b/lib/libarchive/test/test_read_format_cpio_bin_bz2.c @@ -36,7 +36,6 @@ DEFINE_TEST(test_read_format_cpio_bin_bz2) { struct archive_entry *ae; struct archive *a; - int r; assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, @@ -44,23 +43,11 @@ DEFINE_TEST(test_read_format_cpio_bin_bz2) assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, archive, sizeof(archive))); - r = archive_read_next_header(a, &ae); - if (UnsupportedCompress(r, a)) { - skipping("Skipping BZ2 compression check: " - "This version of libarchive was compiled " - "without bz2 support"); - goto finish; - } - assertEqualIntA(a, ARCHIVE_OK, r); + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assert(archive_compression(a) == ARCHIVE_COMPRESSION_BZIP2); assert(archive_format(a) == ARCHIVE_FORMAT_CPIO_BIN_LE); assert(0 == archive_read_close(a)); -finish: -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); } diff --git a/lib/libarchive/test/test_read_format_cpio_bin_gz.c b/lib/libarchive/test/test_read_format_cpio_bin_gz.c index 77e322f..a57e2f1 100644 --- a/lib/libarchive/test/test_read_format_cpio_bin_gz.c +++ b/lib/libarchive/test/test_read_format_cpio_bin_gz.c @@ -38,26 +38,24 @@ DEFINE_TEST(test_read_format_cpio_bin_gz) int r; assert((a = archive_read_new()) != NULL); - assert(0 == archive_read_support_compression_all(a)); - assert(0 == archive_read_support_format_all(a)); - assert(0 == archive_read_open_memory(a, archive, sizeof(archive))); - r = archive_read_next_header(a, &ae); - if (UnsupportedCompress(r, a)) { - skipping("Skipping GZIP compression check: " - "This version of libarchive was compiled " - "without gzip support"); - goto finish; + assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_gzip(a); + if (r == ARCHIVE_WARN) { + skipping("gzip reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; } - assert(0 == r); - assert(archive_compression(a) == ARCHIVE_COMPRESSION_GZIP); - assert(archive_format(a) == ARCHIVE_FORMAT_CPIO_BIN_LE); - assert(0 == archive_read_close(a)); -finish: -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif + failure("archive_read_support_compression_gzip"); + assertEqualInt(ARCHIVE_OK, r); + assertEqualInt(ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualInt(ARCHIVE_OK, + archive_read_open_memory(a, archive, sizeof(archive))); + assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), + ARCHIVE_COMPRESSION_GZIP); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_CPIO_BIN_LE); + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); } diff --git a/lib/libarchive/test/test_read_format_cpio_bin_xz.c b/lib/libarchive/test/test_read_format_cpio_bin_xz.c new file mode 100644 index 0000000..e864e5a --- /dev/null +++ b/lib/libarchive/test/test_read_format_cpio_bin_xz.c @@ -0,0 +1,70 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * Copyright (c) 2003-2007 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 unsigned char archive[] = { + 0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00, 0x00, 0x04, + 0xe6, 0xd6, 0xb4, 0x46, 0x02, 0x00, 0x21, 0x01, + 0x16, 0x00, 0x00, 0x00, 0x74, 0x2f, 0xe5, 0xa3, + 0xe0, 0x01, 0xff, 0x00, 0x33, 0x5d, 0x00, 0x63, + 0x9c, 0x3e, 0xa0, 0x43, 0x7c, 0xe6, 0x5d, 0xdc, + 0xeb, 0x76, 0x1d, 0x4b, 0x1b, 0xe2, 0x9e, 0x43, + 0x95, 0x97, 0x60, 0x16, 0x36, 0xc6, 0xd1, 0x3f, + 0x68, 0xd1, 0x94, 0xf9, 0xee, 0x47, 0xbb, 0xc9, + 0xf3, 0xa2, 0x01, 0x2a, 0x2f, 0x2b, 0xb2, 0x23, + 0x5a, 0x06, 0x9c, 0xd0, 0x4a, 0x6b, 0x5b, 0x14, + 0xb4, 0x00, 0x00, 0x00, 0x91, 0x62, 0x1e, 0x15, + 0x04, 0x46, 0x6b, 0x4d, 0x00, 0x01, 0x4f, 0x80, + 0x04, 0x00, 0x00, 0x00, 0xa1, 0x4b, 0xdf, 0x03, + 0xb1, 0xc4, 0x67, 0xfb, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x04, 0x59, 0x5a +}; + +DEFINE_TEST(test_read_format_cpio_bin_xz) +{ + struct archive_entry *ae; + struct archive *a; + int r; + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_xz(a); + if (r == ARCHIVE_WARN) { + skipping("xz reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, archive, sizeof(archive))); + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_XZ); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_CPIO_BIN_LE); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} + diff --git a/lib/libarchive/test/test_read_format_cpio_svr4_gzip.c b/lib/libarchive/test/test_read_format_cpio_svr4_gzip.c index e517bb2..63a51c4 100644 --- a/lib/libarchive/test/test_read_format_cpio_svr4_gzip.c +++ b/lib/libarchive/test/test_read_format_cpio_svr4_gzip.c @@ -39,26 +39,23 @@ DEFINE_TEST(test_read_format_cpio_svr4_gzip) int r; assert((a = archive_read_new()) != NULL); - assert(0 == archive_read_support_compression_all(a)); - assert(0 == archive_read_support_format_all(a)); - assert(0 == archive_read_open_memory(a, archive, sizeof(archive))); - r = archive_read_next_header(a, &ae); - if (UnsupportedCompress(r, a)) { - skipping("Skipping GZIP compression check: " - "This version of libarchive was compiled " - "without gzip support"); - goto finish; + assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_gzip(a); + if (r == ARCHIVE_WARN) { + skipping("gzip reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; } - assert(0 == r); - assert(archive_compression(a) == ARCHIVE_COMPRESSION_GZIP); - assert(archive_format(a) == ARCHIVE_FORMAT_CPIO_SVR4_NOCRC); - assert(0 == archive_read_close(a)); -finish: -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif + assertEqualInt(ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualInt(ARCHIVE_OK, + archive_read_open_memory(a, archive, sizeof(archive))); + assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), + ARCHIVE_COMPRESSION_GZIP); + assertEqualInt(archive_format(a), + ARCHIVE_FORMAT_CPIO_SVR4_NOCRC); + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); } diff --git a/lib/libarchive/test/test_read_format_gtar_gz.c b/lib/libarchive/test/test_read_format_gtar_gz.c index 6d3b66d..8f12a65 100644 --- a/lib/libarchive/test/test_read_format_gtar_gz.c +++ b/lib/libarchive/test/test_read_format_gtar_gz.c @@ -39,26 +39,22 @@ DEFINE_TEST(test_read_format_gtar_gz) int r; assert((a = archive_read_new()) != NULL); - assert(0 == archive_read_support_compression_all(a)); - assert(0 == archive_read_support_format_all(a)); - assert(0 == archive_read_open_memory(a, archive, sizeof(archive))); - r = archive_read_next_header(a, &ae); - if (UnsupportedCompress(r, a)) { - skipping("Skipping GZIP compression check: " - "This version of libarchive was compiled " - "without gzip support"); - goto finish; + assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_gzip(a); + if (r == ARCHIVE_WARN) { + skipping("gzip reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; } - assert(0 == r); - assert(archive_compression(a) == ARCHIVE_COMPRESSION_GZIP); - assert(archive_format(a) == ARCHIVE_FORMAT_TAR_GNUTAR); - assert(0 == archive_read_close(a)); -finish: -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif + assertEqualInt(ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualInt(ARCHIVE_OK, + archive_read_open_memory(a, archive, sizeof(archive))); + assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), + ARCHIVE_COMPRESSION_GZIP); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_GNUTAR); + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); } diff --git a/lib/libarchive/test/test_read_format_gtar_lzma.c b/lib/libarchive/test/test_read_format_gtar_lzma.c new file mode 100644 index 0000000..f19d0b8 --- /dev/null +++ b/lib/libarchive/test/test_read_format_gtar_lzma.c @@ -0,0 +1,78 @@ +/*- + * Copyright (c) 2008 Miklos Vajna + * 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 unsigned char archive[] = { +0x5d, 0x0, 0x0, 0x80, 0x0, 0x0, 0x28, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, +0x17, 0xb, 0xbc, 0x1c, 0x7d, 0x1, 0x95, 0xc0, 0x1d, 0x4a, 0x46, 0x9c, +0x1c, 0xc5, 0x8, 0x82, 0x10, 0xed, 0x84, 0xf6, 0xea, 0x7a, 0xfe, 0x63, +0x5a, 0x34, 0x5e, 0xf7, 0xc, 0x60, 0xd6, 0x8b, 0xc1, 0x47, 0xaf, 0x11, +0x6f, 0x18, 0x94, 0x81, 0x74, 0x8a, 0xf8, 0x47, 0xcc, 0xdd, 0xc0, 0xd9, +0x40, 0xa, 0xc3, 0xac, 0x43, 0x47, 0xb5, 0xac, 0x2b, 0x31, 0xd3, 0x6, +0xa4, 0x2c, 0x44, 0x80, 0x24, 0x4b, 0xfe, 0x43, 0x22, 0x4e, 0x14, 0x30, +0x7a, 0xef, 0x99, 0x6e, 0xf, 0x8b, 0xc1, 0x79, 0x93, 0x88, 0x54, 0x73, +0x59, 0x3f, 0xc, 0xfb, 0xee, 0x9c, 0x83, 0x49, 0x93, 0x33, 0xad, 0x44, +0xbe, 0x0}; + +DEFINE_TEST(test_read_format_gtar_lzma) +{ + int r; + + struct archive_entry *ae; + struct archive *a; + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + r = archive_read_support_compression_lzma(a); + if (r == ARCHIVE_WARN) { + skipping("lzma reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + + assertEqualIntA(a, ARCHIVE_OK, r); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_format_all(a)); + r = archive_read_open_memory2(a, archive, sizeof(archive), 3); + if (r != ARCHIVE_OK) { + skipping("Skipping LZMA compression check: %s", + archive_error_string(a)); + goto finish; + } + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_LZMA); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_GNUTAR); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); +finish: +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +#endif +} + + diff --git a/lib/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu b/lib/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu index dc9eec1..7b19d67 100644 --- a/lib/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu +++ b/lib/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu @@ -1,5 +1,4 @@ $FreeBSD$ - begin 644 test_read_format_gtar_sparse_1_13.tar M<W!A<G-E```````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` diff --git a/lib/libarchive/test/test_read_format_iso_gz.c b/lib/libarchive/test/test_read_format_iso_gz.c index 6a9172f..73c8415 100644 --- a/lib/libarchive/test/test_read_format_iso_gz.c +++ b/lib/libarchive/test/test_read_format_iso_gz.c @@ -25,62 +25,35 @@ #include "test.h" __FBSDID("$FreeBSD$"); -static unsigned char archive[] = { -31,139,8,8,201,'R','p','C',0,3,'t','e','s','t','-','r','e','a','d','_','f', -'o','r','m','a','t','.','i','s','o',0,237,219,223,'k',211,'@',28,0,240,212, -23,'K','}',20,169,143,135,15,162,224,218,180,']','W',186,183,173,'I',183, -206,254,144,'d',19,246,'$',5,';',24,'2',11,235,240,239,221,127,162,233,'f', -17,29,219,24,12,'\'',243,243,'!',185,187,220,']',146,';',8,9,223,131,'D', -17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'P',234, -'%','q',220,'(','E',253,211,217,'l',';','O',194,'u','z','I','6',25,']',219, -26,194,234,'z',241,'o',217,13,247,'-',182,229,30,149,203,'Q',229,178,170, -242,252,'W',243,139,'e',242,'*',170,'^',30,'U',163,242,'2','+','G',199,207, -158,'V','_',190,';',127,178,':',255,134,1,241,23,140,222,15,242,'I','?',15, -'E',26,186,27,27,'q','}',183,'8',232,15,134,'i','~',152,239,167,163,176,'}', -'0',24,'&','i',22,'^','/',159,159,180,'7',201,146,162,176,150,213,147,143, -'E','!','K',183,246,'\'','Y','x',211,'{',27,26,221,'n','+',164,181,195,201, -193,'x','\'',217,26,166,171,202,'N',216,171,'}','H',183,178,'|','2',174,239, -213,242,222,238,'`','8',28,140,'w',30,'j',186,205,'8','n','7',26,'q',167, -217,'j',174,183,';','q','|','~',165,'"',254,'C','t',165,'G',')','z',168,209, -243,'o',184,143,215,'6',220,139,239,'?',191,255,0,192,255,163,136,224,194, -'h',254,'5',140,231,223,'B',232,132,'f','k',179,185,190,217,238,'\\',132, -':',149,147,'/',199,139,249,209,'"','4','k','q',173,21,214,230,225,'l',182, -'8','[',';',157,'M','?',127,':',154,159,158,'L',207,'j','E','{',152,'>',244, -28,0,128,187,')',']',172,177,139,255,1,0,0,224,'1',187,136,252,171,22,0,0, -0,0,224,'1',187,253,31,187,'[','{','X',';',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,224,206, -'~',0,137,'#',195,182,0,128,1,0}; - DEFINE_TEST(test_read_format_iso_gz) { struct archive_entry *ae; struct archive *a; int r; + const char *name = "test_read_format_iso_gz.iso.gz"; + + extract_reference_file(name); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_gzip(a); + if (r == ARCHIVE_WARN) { + skipping("gzip reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - r = archive_read_next_header(a, &ae); - if (UnsupportedCompress(r, a)) { - skipping("Skipping GZIP compression check: " - "This version of libarchive was compiled " - "without gzip support"); - goto finish; - } - assertEqualIntA(a, ARCHIVE_OK, r); - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_GZIP); + archive_read_open_filename(a, name, 512)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), + ARCHIVE_COMPRESSION_GZIP); assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); -finish: -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -#endif } diff --git a/lib/libarchive/test/test_read_format_iso_gz.iso.gz.uu b/lib/libarchive/test/test_read_format_iso_gz.iso.gz.uu new file mode 100644 index 0000000..759e5b6 --- /dev/null +++ b/lib/libarchive/test/test_read_format_iso_gz.iso.gz.uu @@ -0,0 +1,16 @@ +$FreeBSD$ +begin 755 test_read_format_iso_gz.iso.gz +M'XL(",E2<$,``W1E<W0M<F5A9%]F;W)M870N:7-O`.W;WVO30!P`\-072WT4 +MJ8^'#Z+@VK1=5[JWK4FWSOZ09!/V)`4[&#(+Z_#OW7^BZ681'=L8#"?S\R&Y +MN]Q=DCL("=^#1!$`````````````````````````````````````````4.HE +M<=PH1?W3V6P[3\)U>DDV&5W;&L+J>O%OV0WW+;;E'I7+4>6RJO+\5_.+9?(J +MJEX>5:/R,BM'Q\^>5E^^.W^R.O^&`?$7C-X/\DD_#T4:NAL;<7VW..@/AFE^ +MF.^GH[!],!@F:19>+Y^?M#?)DJ*PEM63CT4A2[?V)UEXTWL;&MUN*Z2UP\G! +M>"?9&J:KRD[8JWU(M[)\,J[OU?+>[F`X'(QW'FJZS3AN-QIQI]EJKK<[<7Q^ +MI2+^0W2E1REZJ-'S;[B/US;<B^\_O_\`P/^CB.#":/XUC.??0NB$9FNSN;[9 +M[ER$.I63+\>+^=$B-&MQK176YN%LMCA;.YU-/W\ZFI^>3,]J17N8/O0<`("[ +M*5VLL8O_`0``X#&[B/RK%@````#@,;O]'[M;>U@[```````````````````` +M`````````````````````````````````````````````.#.?@")(\.V`(`! +!```` +` +end diff --git a/lib/libarchive/test/test_read_format_isojoliet_bz2.c b/lib/libarchive/test/test_read_format_isojoliet_bz2.c index 8ae578d..19754b7 100644 --- a/lib/libarchive/test/test_read_format_isojoliet_bz2.c +++ b/lib/libarchive/test/test_read_format_isojoliet_bz2.c @@ -69,15 +69,16 @@ joliettest(int withrr) extract_reference_file(refname); assert((a = archive_read_new()) != NULL); - assertEqualInt(0, archive_read_support_compression_bzip2(a)); - assertEqualInt(0, archive_read_support_format_all(a)); - r = archive_read_open_filename(a, refname, 10240); - if (r == ARCHIVE_FATAL) { - skipping("Bzip2 decompression unsupported on this platform"); - archive_read_finish(a); + r = archive_read_support_compression_bzip2(a); + if (r == ARCHIVE_WARN) { + skipping("bzip2 reading not fully supported on this platform"); + assertEqualInt(0, archive_read_finish(a)); return; } assertEqualInt(0, r); + assertEqualInt(0, archive_read_support_format_all(a)); + assertEqualInt(ARCHIVE_OK, + archive_read_open_filename(a, refname, 10240)); /* First entry is '.' root directory. */ assertEqualInt(0, archive_read_next_header(a, &ae)); @@ -169,11 +170,7 @@ joliettest(int withrr) /* Close the archive. */ assertEqualInt(0, archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else assertEqualInt(0, archive_read_finish(a)); -#endif } diff --git a/lib/libarchive/test/test_read_format_isorr_bz2.c b/lib/libarchive/test/test_read_format_isorr_bz2.c index 79e8522..f00bbbe 100644 --- a/lib/libarchive/test/test_read_format_isorr_bz2.c +++ b/lib/libarchive/test/test_read_format_isorr_bz2.c @@ -55,15 +55,16 @@ DEFINE_TEST(test_read_format_isorr_bz2) extract_reference_file(refname); assert((a = archive_read_new()) != NULL); - assertEqualInt(0, archive_read_support_compression_bzip2(a)); - assertEqualInt(0, archive_read_support_format_all(a)); - r = archive_read_open_filename(a, refname, 10240); - if (r == ARCHIVE_FATAL) { - skipping("Bzip2 decompression unsupported on this platform"); - archive_read_finish(a); + r = archive_read_support_compression_bzip2(a); + if (r == ARCHIVE_WARN) { + skipping("bzip2 reading not fully supported on this platform"); + assertEqualInt(0, archive_read_finish(a)); return; } assertEqualInt(0, r); + assertEqualInt(0, archive_read_support_format_all(a)); + assertEqualInt(ARCHIVE_OK, + archive_read_open_filename(a, refname, 10240)); /* First entry is '.' root directory. */ assertEqualInt(0, archive_read_next_header(a, &ae)); diff --git a/lib/libarchive/test/test_read_format_mtree.c b/lib/libarchive/test/test_read_format_mtree.c index 2b858ad..1f2ed8f 100644 --- a/lib/libarchive/test/test_read_format_mtree.c +++ b/lib/libarchive/test/test_read_format_mtree.c @@ -52,6 +52,15 @@ DEFINE_TEST(test_read_format_mtree) struct archive_entry *ae; struct archive *a; + /* + * An access error occurred on some platform when mtree + * format handling open a directory. It is for through + * the routine which open a directory that we create + * "dir" and "dir2" directories. + */ + assertEqualInt(0, mkdir("dir", 0775)); + assertEqualInt(0, mkdir("dir2", 0775)); + assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); diff --git a/lib/libarchive/test/test_read_format_pax_bz2.c b/lib/libarchive/test/test_read_format_pax_bz2.c index e0d0d2a..a0b74e1 100644 --- a/lib/libarchive/test/test_read_format_pax_bz2.c +++ b/lib/libarchive/test/test_read_format_pax_bz2.c @@ -44,29 +44,17 @@ DEFINE_TEST(test_read_format_pax_bz2) { struct archive_entry *ae; struct archive *a; - int r; assert((a = archive_read_new()) != NULL); - assert(0 == archive_read_support_compression_all(a)); - assert(0 == archive_read_support_format_all(a)); - assert(0 == archive_read_open_memory(a, archive, sizeof(archive))); - r = archive_read_next_header(a, &ae); - if (UnsupportedCompress(r, a)) { - skipping("Skipping BZIP2 compression check: " - "This version of libarchive was compiled " - "without bzip2 support"); - goto finish; - } - assert(0 == r); - assert(archive_compression(a) == ARCHIVE_COMPRESSION_BZIP2); - assert(archive_format(a) == ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE); - assert(0 == archive_read_close(a)); -finish: -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif + assertEqualIntA(a,ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a,ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a,ARCHIVE_OK, + archive_read_open_memory(a, archive, sizeof(archive))); + assertEqualIntA(a,ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE); + assertEqualIntA(a,ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); } diff --git a/lib/libarchive/test/test_read_format_tbz.c b/lib/libarchive/test/test_read_format_tbz.c index 3d0e474..00d4094 100644 --- a/lib/libarchive/test/test_read_format_tbz.c +++ b/lib/libarchive/test/test_read_format_tbz.c @@ -37,29 +37,17 @@ DEFINE_TEST(test_read_format_tbz) { struct archive_entry *ae; struct archive *a; - int r; assert((a = archive_read_new()) != NULL); - assert(0 == archive_read_support_compression_all(a)); - assert(0 == archive_read_support_format_all(a)); - assert(0 == archive_read_open_memory(a, archive, sizeof(archive))); - r = archive_read_next_header(a, &ae); - if (UnsupportedCompress(r, a)) { - skipping("Skipping BZIP2 compression check: " - "This version of libarchive was compiled " - "without bzip2 support"); - goto finish; - } - assert(0 == r); - assert(archive_compression(a) == ARCHIVE_COMPRESSION_BZIP2); - assert(archive_format(a) == ARCHIVE_FORMAT_TAR_USTAR); - assert(0 == archive_read_close(a)); -finish: -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, archive, sizeof(archive))); + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); } diff --git a/lib/libarchive/test/test_read_format_tgz.c b/lib/libarchive/test/test_read_format_tgz.c index 4b3d420..6b27d3c 100644 --- a/lib/libarchive/test/test_read_format_tgz.c +++ b/lib/libarchive/test/test_read_format_tgz.c @@ -39,26 +39,22 @@ DEFINE_TEST(test_read_format_tgz) int r; assert((a = archive_read_new()) != NULL); - assert(0 == archive_read_support_compression_all(a)); - assert(0 == archive_read_support_format_all(a)); - assert(0 == archive_read_open_memory(a, archive, sizeof(archive))); - r = archive_read_next_header(a, &ae); - if (UnsupportedCompress(r, a)) { - skipping("Skipping GZIP compression check: " - "This version of libarchive was compiled " - "without gzip support"); - goto finish; + assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_gzip(a); + if (r == ARCHIVE_WARN) { + skipping("gzip reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; } - assert(0 == r); - assert(archive_compression(a) == ARCHIVE_COMPRESSION_GZIP); - assert(archive_format(a) == ARCHIVE_FORMAT_TAR_USTAR); - assert(0 == archive_read_close(a)); -finish: -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif + assertEqualInt(ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualInt(ARCHIVE_OK, + archive_read_open_memory(a, archive, sizeof(archive))); + assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), + ARCHIVE_COMPRESSION_GZIP); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK,archive_read_finish(a)); } diff --git a/lib/libarchive/test/test_read_format_txz.c b/lib/libarchive/test/test_read_format_txz.c new file mode 100644 index 0000000..4d088b2 --- /dev/null +++ b/lib/libarchive/test/test_read_format_txz.c @@ -0,0 +1,63 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * Copyright (c) 2003-2007 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 unsigned char archive[] = { +253, 55,122, 88, 90, 0, 0, 4,230,214,180, 70, 2, 0, 33, 1, + 22, 0, 0, 0,116, 47,229,163,224, 5,255, 0, 73, 93, 0, 23, + 0, 51, 80, 24,164,204,238, 45, 77, 28,191, 13,144, 8, 10, 70, + 5,173,215, 47,132,237,145,162, 96, 6,131,168,152, 8,135,161, +189, 73,110,132, 27,195, 52,109,203, 22, 17,168,211, 18,181, 76, + 93,120, 88,154,155,244,141,193,206,170,224, 80,137,134, 67, 1, + 9,123,121,188,247, 28,139, 0, 0, 0, 0, 0,112,184, 17, 5, +103, 16, 8, 73, 0, 1,101,128, 12, 0, 0, 0, 30, 69, 92, 96, +177,196,103,251, 2, 0, 0, 0, 0, 4, 89, 90 +}; + +DEFINE_TEST(test_read_format_txz) +{ + struct archive_entry *ae; + struct archive *a; + int r; + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_xz(a); + if (r == ARCHIVE_WARN) { + skipping("xz reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, archive, sizeof(archive))); + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_XZ); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} diff --git a/lib/libarchive/test/test_write_compress_bzip2.c b/lib/libarchive/test/test_write_compress_bzip2.c new file mode 100644 index 0000000..54c8a50 --- /dev/null +++ b/lib/libarchive/test/test_write_compress_bzip2.c @@ -0,0 +1,228 @@ +/*- + * Copyright (c) 2007 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 + * in this position and unchanged. + * 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$"); + +/* + * A basic exercise of bzip2 reading and writing. + * + * TODO: Add a reference file and make sure we can decompress that. + */ + +DEFINE_TEST(test_write_compress_bzip2) +{ + struct archive_entry *ae; + struct archive* a; + char *buff, *data; + size_t buffsize, datasize; + char path[16]; + size_t used1, used2; + int i, r; + + buffsize = 2000000; + assert(NULL != (buff = (char *)malloc(buffsize))); + + datasize = 10000; + assert(NULL != (data = (char *)malloc(datasize))); + memset(data, 0, datasize); + + /* + * Write a 100 files and read them all back. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + r = archive_write_set_compression_bzip2(a); + if (r == ARCHIVE_FATAL) { + skipping("bzip2 writing not supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertEqualInt(ARCHIVE_COMPRESSION_BZIP2, archive_compression(a)); + assertEqualString("bzip2", archive_compression_name(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used1)); + assertEqualInt(ARCHIVE_COMPRESSION_BZIP2, archive_compression(a)); + assertEqualString("bzip2", archive_compression_name(a)); + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_filetype(ae, AE_IFREG); + archive_entry_set_size(ae, datasize); + for (i = 0; i < 999; i++) { + sprintf(path, "file%03d", i); + archive_entry_copy_pathname(ae, path); + assertA(0 == archive_write_header(a, ae)); + assertA(datasize + == (size_t)archive_write_data(a, data, datasize)); + } + archive_entry_free(ae); + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff, used1)); + for (i = 0; i < 999; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(0, archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assert(0 == archive_read_close(a)); + assert(0 == archive_read_finish(a)); + + /* + * Repeat the cycle again, this time setting some compression + * options. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertA(0 == archive_write_set_compression_bzip2(a)); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "nonexistent-option=0")); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "compression-level=abc")); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "compression-level=99")); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_compressor_options(a, "compression-level=9")); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + for (i = 0; i < 999; i++) { + sprintf(path, "file%03d", i); + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, path); + archive_entry_set_size(ae, datasize); + archive_entry_set_filetype(ae, AE_IFREG); + assertA(0 == archive_write_header(a, ae)); + assertA(datasize == (size_t)archive_write_data(a, data, datasize)); + archive_entry_free(ae); + } + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + /* Curiously, this test fails; the test data above compresses + * better at default compression than at level 9. */ + /* + failure("compression-level=9 wrote %d bytes, default wrote %d bytes", + (int)used2, (int)used1); + assert(used2 < used1); + */ + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff, used2)); + for (i = 0; i < 999; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(0, archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assert(0 == archive_read_close(a)); + assert(0 == archive_read_finish(a)); + + /* + * Repeat again, with much lower compression. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertA(0 == archive_write_set_compression_bzip2(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_compressor_options(a, "compression-level=1")); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + for (i = 0; i < 999; i++) { + sprintf(path, "file%03d", i); + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, path); + archive_entry_set_size(ae, datasize); + archive_entry_set_filetype(ae, AE_IFREG); + assertA(0 == archive_write_header(a, ae)); + failure("Writing file %s", path); + assertEqualIntA(a, datasize, + (size_t)archive_write_data(a, data, datasize)); + archive_entry_free(ae); + } + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + /* Level 0 really does result in larger data. */ + failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", + (int)used2, (int)used1); + assert(used2 > used1); + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff, used2)); + for (i = 0; i < 999; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(0, archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assert(0 == archive_read_close(a)); + assert(0 == archive_read_finish(a)); + + /* + * Test various premature shutdown scenarios to make sure we + * don't crash or leak memory. + */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + /* + * Clean up. + */ + free(data); + free(buff); +} diff --git a/lib/libarchive/test/test_write_compress_gzip.c b/lib/libarchive/test/test_write_compress_gzip.c new file mode 100644 index 0000000..9e42b13 --- /dev/null +++ b/lib/libarchive/test/test_write_compress_gzip.c @@ -0,0 +1,252 @@ +/*- + * Copyright (c) 2007 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 + * in this position and unchanged. + * 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$"); + +/* + * A basic exercise of gzip reading and writing. + * + * TODO: Add a reference file and make sure we can decompress that. + */ + +DEFINE_TEST(test_write_compress_gzip) +{ + struct archive_entry *ae; + struct archive* a; + char *buff, *data; + size_t buffsize, datasize; + char path[16]; + size_t used1, used2; + int i, r; + + buffsize = 2000000; + assert(NULL != (buff = (char *)malloc(buffsize))); + + datasize = 10000; + assert(NULL != (data = (char *)malloc(datasize))); + memset(data, 0, datasize); + + /* + * Write a 100 files and read them all back. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + r = archive_write_set_compression_gzip(a); + if (r == ARCHIVE_FATAL) { + skipping("gzip writing not supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertEqualInt(ARCHIVE_COMPRESSION_GZIP, archive_compression(a)); + assertEqualString("gzip", archive_compression_name(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used1)); + assertEqualInt(ARCHIVE_COMPRESSION_GZIP, archive_compression(a)); + assertEqualString("gzip", archive_compression_name(a)); + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_filetype(ae, AE_IFREG); + archive_entry_set_size(ae, datasize); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + archive_entry_copy_pathname(ae, path); + assertA(0 == archive_write_header(a, ae)); + assertA(datasize + == (size_t)archive_write_data(a, data, datasize)); + } + archive_entry_free(ae); + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + r = archive_read_support_compression_gzip(a); + if (r == ARCHIVE_WARN) { + skipping("Can't verify gzip writing by reading back;" + " gzip reading not fully supported on this platform"); + } else { + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used1)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(ARCHIVE_OK, + archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + } + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Repeat the cycle again, this time setting some compression + * options. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertA(0 == archive_write_set_compression_gzip(a)); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "nonexistent-option=0")); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "compression-level=abc")); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "compression-level=99")); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_compressor_options(a, "compression-level=9")); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, path); + archive_entry_set_size(ae, datasize); + archive_entry_set_filetype(ae, AE_IFREG); + assertA(0 == archive_write_header(a, ae)); + assertA(datasize == (size_t)archive_write_data(a, data, datasize)); + archive_entry_free(ae); + } + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + /* Curiously, this test fails; the test data above compresses + * better at default compression than at level 9. */ + /* + failure("compression-level=9 wrote %d bytes, default wrote %d bytes", + (int)used2, (int)used1); + assert(used2 < used1); + */ + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + r = archive_read_support_compression_gzip(a); + if (r == ARCHIVE_WARN) { + skipping("gzip reading not fully supported on this platform"); + } else { + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(ARCHIVE_OK, + archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + } + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Repeat again, with much lower compression. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertA(0 == archive_write_set_compression_gzip(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_compressor_options(a, "compression-level=0")); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, path); + archive_entry_set_size(ae, datasize); + archive_entry_set_filetype(ae, AE_IFREG); + assertA(0 == archive_write_header(a, ae)); + failure("Writing file %s", path); + assertEqualIntA(a, datasize, + (size_t)archive_write_data(a, data, datasize)); + archive_entry_free(ae); + } + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + /* Level 0 really does result in larger data. */ + failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", + (int)used2, (int)used1); + assert(used2 > used1); + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + r = archive_read_support_compression_gzip(a); + if (r == ARCHIVE_WARN) { + skipping("gzip reading not fully supported on this platform"); + } else { + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(ARCHIVE_OK, + archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + } + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Test various premature shutdown scenarios to make sure we + * don't crash or leak memory. + */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + /* + * Clean up. + */ + free(data); + free(buff); +} diff --git a/lib/libarchive/test/test_write_compress_lzma.c b/lib/libarchive/test/test_write_compress_lzma.c new file mode 100644 index 0000000..639e58f --- /dev/null +++ b/lib/libarchive/test/test_write_compress_lzma.c @@ -0,0 +1,245 @@ +/*- + * Copyright (c) 2007-2009 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 + * in this position and unchanged. + * 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$"); + +/* + * A basic exercise of lzma reading and writing. + * + */ + +DEFINE_TEST(test_write_compress_lzma) +{ + struct archive_entry *ae; + struct archive* a; + char *buff, *data; + size_t buffsize, datasize; + char path[16]; + size_t used1, used2; + int i, r; + + buffsize = 2000000; + assert(NULL != (buff = (char *)malloc(buffsize))); + + datasize = 10000; + assert(NULL != (data = (char *)malloc(datasize))); + memset(data, 0, datasize); + + /* + * Write a 100 files and read them all back. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + r = archive_write_set_compression_lzma(a); + if (r == ARCHIVE_FATAL) { + skipping("lzma writing not supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertEqualInt(ARCHIVE_COMPRESSION_LZMA, archive_compression(a)); + assertEqualString("lzma", archive_compression_name(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used1)); + assertEqualInt(ARCHIVE_COMPRESSION_LZMA, archive_compression(a)); + assertEqualString("lzma", archive_compression_name(a)); + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_filetype(ae, AE_IFREG); + archive_entry_set_size(ae, datasize); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + archive_entry_copy_pathname(ae, path); + assertA(0 == archive_write_header(a, ae)); + assertA(datasize + == (size_t)archive_write_data(a, data, datasize)); + } + archive_entry_free(ae); + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + r = archive_read_support_compression_lzma(a); + if (r == ARCHIVE_WARN) { + skipping("Can't verify lzma writing by reading back;" + " lzma reading not fully supported on this platform"); + } else { + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used1)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(ARCHIVE_OK, + archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + } + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Repeat the cycle again, this time setting some compression + * options. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertA(0 == archive_write_set_compression_lzma(a)); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "nonexistent-option=0")); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "compression-level=abc")); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "compression-level=99")); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_compressor_options(a, "compression-level=9")); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, path); + archive_entry_set_size(ae, datasize); + archive_entry_set_filetype(ae, AE_IFREG); + assertA(0 == archive_write_header(a, ae)); + assertA(datasize == (size_t)archive_write_data(a, data, datasize)); + archive_entry_free(ae); + } + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + r = archive_read_support_compression_lzma(a); + if (r == ARCHIVE_WARN) { + skipping("lzma reading not fully supported on this platform"); + } else { + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + failure("Trying to read %s", path); + if (!assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + } + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Repeat again, with much lower compression. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertA(0 == archive_write_set_compression_lzma(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_compressor_options(a, "compression-level=0")); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, path); + archive_entry_set_size(ae, datasize); + archive_entry_set_filetype(ae, AE_IFREG); + assertA(0 == archive_write_header(a, ae)); + failure("Writing file %s", path); + assertEqualIntA(a, datasize, + (size_t)archive_write_data(a, data, datasize)); + archive_entry_free(ae); + } + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + /* Level 0 really does result in larger data. */ + failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", + (int)used2, (int)used1); + assert(used2 > used1); + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + r = archive_read_support_compression_lzma(a); + if (r == ARCHIVE_WARN) { + skipping("lzma reading not fully supported on this platform"); + } else { + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(ARCHIVE_OK, + archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + } + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Test various premature shutdown scenarios to make sure we + * don't crash or leak memory. + */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + /* + * Clean up. + */ + free(data); + free(buff); +} diff --git a/lib/libarchive/test/test_write_compress_program.c b/lib/libarchive/test/test_write_compress_program.c index e00e398..713638e 100644 --- a/lib/libarchive/test/test_write_compress_program.c +++ b/lib/libarchive/test/test_write_compress_program.c @@ -38,18 +38,20 @@ DEFINE_TEST(test_write_compress_program) size_t used; int blocksize = 1024; int r; - const char *extprog; + const char *compprog, *decompprog; - if ((extprog = external_gzip_program(0)) == NULL) { + decompprog = external_gzip_program(1); + if ((compprog = external_gzip_program(0)) == NULL) { skipping("There is no gzip compression " "program in this platform"); return; } + /* Create a new archive in memory. */ /* Write it through an external "gzip" program. */ assert((a = archive_write_new()) != NULL); assertA(0 == archive_write_set_format_ustar(a)); - r = archive_write_set_compression_program(a, extprog); + r = archive_write_set_compression_program(a, compprog); if (r == ARCHIVE_FATAL) { skipping("Write compression via external " "program unsupported on this platform"); @@ -77,60 +79,43 @@ DEFINE_TEST(test_write_compress_program) /* Close out the archive. */ assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else assertA(0 == archive_write_finish(a)); -#endif /* * Now, read the data back through the built-in gzip support. */ assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_gzip(a); + /* The compression_gzip() handler will fall back to gunzip + * automatically, but if we know gunzip isn't available, then + * skip the rest. */ + if (r != ARCHIVE_OK && decompprog == NULL) { + skipping("No gzip decompression is available; " + "unable to verify gzip compression"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used)); - r = archive_read_next_header(a, &ae); - if (UnsupportedCompress(r, a)) { - skipping("This version of libarchive was compiled " - "without gzip support"); - assert(0 == archive_read_finish(a)); - /* - * Try using an external "gunzip","gzip -d" program - */ - if ((extprog = external_gzip_program(1)) == NULL) { - skipping("There is no gzip uncompression " - "program in this platform"); - return; - } - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_none(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_program(a, extprog)); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used)); - r = archive_read_next_header(a, &ae); + if (!assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae))) { + archive_read_finish(a); + return; } - assertA(0 == r); - assert(1 == archive_entry_mtime(ae)); - assert(0 == archive_entry_atime(ae)); - assert(0 == archive_entry_ctime(ae)); + assertEqualInt(1, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_atime(ae)); + assertEqualInt(0, archive_entry_ctime(ae)); assertEqualString("file", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assert(8 == archive_entry_size(ae)); - assertA(8 == archive_read_data(a, buff2, 10)); - assert(0 == memcmp(buff2, "12345678", 8)); + assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); + assertEqualInt(8, archive_entry_size(ae)); + assertEqualIntA(a, 8, archive_read_data(a, buff2, 10)); + assertEqualMem(buff2, "12345678", 8); /* Verify the end of the archive. */ - assert(1 == archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); #endif } diff --git a/lib/libarchive/test/test_write_compress_xz.c b/lib/libarchive/test/test_write_compress_xz.c new file mode 100644 index 0000000..988fb6e --- /dev/null +++ b/lib/libarchive/test/test_write_compress_xz.c @@ -0,0 +1,253 @@ +/*- + * Copyright (c) 2007 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 + * in this position and unchanged. + * 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$"); + +/* + * A basic exercise of xz reading and writing. + * + * TODO: Add a reference file and make sure we can decompress that. + */ + +DEFINE_TEST(test_write_compress_xz) +{ + struct archive_entry *ae; + struct archive* a; + char *buff, *data; + size_t buffsize, datasize; + char path[16]; + size_t used1, used2; + int i, r; + + buffsize = 2000000; + assert(NULL != (buff = (char *)malloc(buffsize))); + + datasize = 10000; + assert(NULL != (data = (char *)malloc(datasize))); + memset(data, 0, datasize); + + /* + * Write a 100 files and read them all back. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + r = archive_write_set_compression_xz(a); + if (r == ARCHIVE_FATAL) { + skipping("xz writing not supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertEqualInt(ARCHIVE_COMPRESSION_XZ, archive_compression(a)); + assertEqualString("xz", archive_compression_name(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used1)); + assertEqualInt(ARCHIVE_COMPRESSION_XZ, archive_compression(a)); + assertEqualString("xz", archive_compression_name(a)); + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_filetype(ae, AE_IFREG); + archive_entry_set_size(ae, datasize); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + archive_entry_copy_pathname(ae, path); + assertA(0 == archive_write_header(a, ae)); + assertA(datasize + == (size_t)archive_write_data(a, data, datasize)); + } + archive_entry_free(ae); + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + r = archive_read_support_compression_xz(a); + if (r == ARCHIVE_WARN) { + skipping("Can't verify xz writing by reading back;" + " xz reading not fully supported on this platform"); + } else { + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used1)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(ARCHIVE_OK, + archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + } + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Repeat the cycle again, this time setting some compression + * options. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertA(0 == archive_write_set_compression_xz(a)); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "nonexistent-option=0")); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "compression-level=abc")); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "compression-level=99")); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_compressor_options(a, "compression-level=9")); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, path); + archive_entry_set_size(ae, datasize); + archive_entry_set_filetype(ae, AE_IFREG); + assertA(0 == archive_write_header(a, ae)); + assertA(datasize == (size_t)archive_write_data(a, data, datasize)); + archive_entry_free(ae); + } + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + /* Curiously, this test fails; the test data above compresses + * better at default compression than at level 9. */ + /* + failure("compression-level=9 wrote %d bytes, default wrote %d bytes", + (int)used2, (int)used1); + assert(used2 < used1); + */ + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + r = archive_read_support_compression_xz(a); + if (r == ARCHIVE_WARN) { + skipping("xz reading not fully supported on this platform"); + } else { + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + failure("Trying to read %s", path); + if (!assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + } + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Repeat again, with much lower compression. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertA(0 == archive_write_set_compression_xz(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_compressor_options(a, "compression-level=0")); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, path); + archive_entry_set_size(ae, datasize); + archive_entry_set_filetype(ae, AE_IFREG); + assertA(0 == archive_write_header(a, ae)); + failure("Writing file %s", path); + assertEqualIntA(a, datasize, + (size_t)archive_write_data(a, data, datasize)); + archive_entry_free(ae); + } + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + /* Level 0 really does result in larger data. */ + failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", + (int)used2, (int)used1); + assert(used2 > used1); + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + r = archive_read_support_compression_xz(a); + if (r == ARCHIVE_WARN) { + skipping("xz reading not fully supported on this platform"); + } else { + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(ARCHIVE_OK, + archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + } + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Test various premature shutdown scenarios to make sure we + * don't crash or leak memory. + */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + /* + * Clean up. + */ + free(data); + free(buff); +} diff --git a/lib/libarchive/test/test_write_disk_failures.c b/lib/libarchive/test/test_write_disk_failures.c index 0d7b894..1befbac 100644 --- a/lib/libarchive/test/test_write_disk_failures.c +++ b/lib/libarchive/test/test_write_disk_failures.c @@ -39,6 +39,7 @@ DEFINE_TEST(test_write_disk_failures) #else struct archive_entry *ae; struct archive *a; + int fd; /* Force the umask to something predictable. */ umask(UMASK); @@ -46,6 +47,15 @@ DEFINE_TEST(test_write_disk_failures) /* A directory that we can't write to. */ assertEqualInt(0, mkdir("dir", 0555)); + /* Can we? */ + fd = open("dir/testfile", O_WRONLY | O_CREAT, 0777); + if (fd >= 0) { + /* Apparently, we can, so the test below won't work. */ + close(fd); + skipping("Can't test writing to non-writable directory"); + return; + } + /* Try to extract a regular file into the directory above. */ assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, "dir/file"); diff --git a/lib/libarchive/test/test_write_disk_sparse.c b/lib/libarchive/test/test_write_disk_sparse.c index 6179610..c9c00d3 100644 --- a/lib/libarchive/test/test_write_disk_sparse.c +++ b/lib/libarchive/test/test_write_disk_sparse.c @@ -116,6 +116,7 @@ verify_write_data(struct archive *a, int sparse) /* XXX more XXX */ assertEqualInt(0, close(fd)); + archive_entry_free(ae); free(buff); } @@ -249,6 +250,7 @@ verify_write_data_block(struct archive *a, int sparse) assertEqualInt(0, close(fd)); free(buff); + archive_entry_free(ae); } DEFINE_TEST(test_write_disk_sparse) diff --git a/lib/libarchive/test/test_write_format_mtree.c b/lib/libarchive/test/test_write_format_mtree.c new file mode 100644 index 0000000..b9de422 --- /dev/null +++ b/lib/libarchive/test/test_write_format_mtree.c @@ -0,0 +1,155 @@ +/*- + * Copyright (c) 2009 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 + * in this position and unchanged. + * 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 char buff[4096]; +static struct { + const char *path; + mode_t mode; + time_t mtime; + uid_t uid; + gid_t gid; +} entries[] = { + { "./Makefile", S_IFREG | 0644, 1233041050, 1001, 1001 }, + { "./NEWS", S_IFREG | 0644, 1231975636, 1001, 1001 }, + { "./PROJECTS", S_IFREG | 0644, 1231975636, 1001, 1001 }, + { "./README", S_IFREG | 0644, 1231975636, 1001, 1001 }, + { "./COPYING", S_IFREG | 0644, 1231975636, 1001, 1001 }, + { "./subdir", S_IFDIR | 0755, 1233504586, 1001, 1001 }, + { "./subdir/README", S_IFREG | 0664, 1231975636, 1002, 1001 }, + { "./subdir/config", S_IFREG | 0664, 1232266273, 1003, 1003 }, + { "./subdir2", S_IFDIR | 0755, 1233504586, 1001, 1001 }, + { "./subdir3", S_IFDIR | 0755, 1233504586, 1001, 1001 }, + { "./subdir3/mtree", S_IFREG | 0664, 1232266273, 1003, 1003 }, + { NULL, 0, 0, 0, 0 } +}; + +static void +test_write_format_mtree_sub(int use_set, int dironly) +{ + struct archive_entry *ae; + struct archive* a; + size_t used; + int i; + + /* Create a mtree format archive. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_mtree(a)); + if (use_set) + assertA(0 == archive_write_set_options(a, "use-set")); + if (dironly) + assertA(0 == archive_write_set_options(a, "dironly")); + assertA(0 == archive_write_open_memory(a, buff, sizeof(buff)-1, &used)); + + /* Write entries */ + for (i = 0; entries[i].path != NULL; i++) { + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, entries[i].mtime, 0); + assert(entries[i].mtime == archive_entry_mtime(ae)); + archive_entry_set_mode(ae, entries[i].mode); + assert(entries[i].mode == archive_entry_mode(ae)); + archive_entry_set_uid(ae, entries[i].uid); + assert(entries[i].uid == archive_entry_uid(ae)); + archive_entry_set_gid(ae, entries[i].gid); + assert(entries[i].gid == archive_entry_gid(ae)); + archive_entry_copy_pathname(ae, entries[i].path); + if ((entries[i].mode & AE_IFMT) != S_IFDIR) + archive_entry_set_size(ae, 8); + assertA(0 == archive_write_header(a, ae)); + if ((entries[i].mode & AE_IFMT) != S_IFDIR) + assertA(8 == archive_write_data(a, "Hello012", 15)); + archive_entry_free(ae); + } + archive_write_close(a); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assertEqualInt(0, archive_write_finish(a)); +#endif + if (use_set) { + const char *p; + + buff[used] = '\0'; + assert(NULL != (p = strstr(buff, "\n/set "))); + if (p != NULL) { + char *r; + const char *o; + p++; + r = strchr(p, '\n'); + if (r != NULL) + *r = '\0'; + if (dironly) + o = "/set type=dir uid=1001 gid=1001 mode=755"; + else + o = "/set type=file uid=1001 gid=1001 mode=644"; + assertEqualString(o, p); + if (r != NULL) + *r = '\n'; + } + } + + /* + * Read the data and check it. + */ + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used)); + + /* Read entries */ + for (i = 0; entries[i].path != NULL; i++) { + if (dironly && (entries[i].mode & AE_IFMT) != S_IFDIR) + continue; + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(entries[i].mtime, archive_entry_mtime(ae)); + assertEqualInt(entries[i].mode, archive_entry_mode(ae)); + assertEqualInt(entries[i].uid, archive_entry_uid(ae)); + assertEqualInt(entries[i].gid, archive_entry_gid(ae)); + assertEqualString(entries[i].path, archive_entry_pathname(ae)); + if ((entries[i].mode & AE_IFMT) != S_IFDIR) + assertEqualInt(8, archive_entry_size(ae)); + } + assertEqualIntA(a, 0, archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assertEqualInt(0, archive_read_finish(a)); +#endif +} + +DEFINE_TEST(test_write_format_mtree) +{ + /* Default setting */ + test_write_format_mtree_sub(0, 0); + /* Directory only */ + test_write_format_mtree_sub(0, 1); + /* Use /set keyword */ + test_write_format_mtree_sub(1, 0); + /* Use /set keyword with directory only */ + test_write_format_mtree_sub(1, 1); +} |