2008-01-01 22:28:04 +00:00
|
|
|
/*-
|
|
|
|
* 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$");
|
|
|
|
|
2009-12-30 05:59:21 +00:00
|
|
|
static void
|
|
|
|
test_read_format_mtree1(void)
|
2008-01-01 22:28:04 +00:00
|
|
|
{
|
2009-12-30 05:59:21 +00:00
|
|
|
const char reffile[] = "test_read_format_mtree.mtree";
|
2009-04-26 18:57:50 +00:00
|
|
|
char buff[16];
|
2008-01-01 22:28:04 +00:00
|
|
|
struct archive_entry *ae;
|
|
|
|
struct archive *a;
|
2009-12-30 05:59:21 +00:00
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
extract_reference_file(reffile);
|
2008-01-01 22:28:04 +00:00
|
|
|
|
2009-04-17 01:06:31 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2009-12-30 05:59:21 +00:00
|
|
|
assertMakeDir("dir", 0775);
|
|
|
|
assertMakeDir("dir2", 0775);
|
2009-04-17 01:06:31 +00:00
|
|
|
|
2008-01-01 22:28:04 +00:00
|
|
|
assert((a = archive_read_new()) != NULL);
|
|
|
|
assertEqualIntA(a, ARCHIVE_OK,
|
|
|
|
archive_read_support_compression_all(a));
|
|
|
|
assertEqualIntA(a, ARCHIVE_OK,
|
|
|
|
archive_read_support_format_all(a));
|
2009-12-30 05:59:21 +00:00
|
|
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_file(a, reffile, 11));
|
2009-04-26 18:57:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read "file", whose data is available on disk.
|
|
|
|
*/
|
2009-12-30 05:59:21 +00:00
|
|
|
f = fopen("file", "wb");
|
|
|
|
assert(f != NULL);
|
|
|
|
assertEqualInt(3, fwrite("hi\n", 1, 3, f));
|
|
|
|
fclose(f);
|
2008-01-01 22:28:04 +00:00
|
|
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
|
2008-09-18 04:13:36 +00:00
|
|
|
assertEqualInt(archive_format(a), ARCHIVE_FORMAT_MTREE);
|
2008-01-01 22:28:04 +00:00
|
|
|
assertEqualString(archive_entry_pathname(ae), "file");
|
|
|
|
assertEqualInt(archive_entry_uid(ae), 18);
|
2009-12-30 05:59:21 +00:00
|
|
|
assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
|
2008-01-01 22:28:04 +00:00
|
|
|
assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0123);
|
2009-04-26 18:57:50 +00:00
|
|
|
assertEqualInt(archive_entry_size(ae), 3);
|
|
|
|
assertEqualInt(3, archive_read_data(a, buff, 3));
|
|
|
|
assertEqualMem(buff, "hi\n", 3);
|
2008-01-01 22:28:04 +00:00
|
|
|
|
|
|
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
|
|
|
|
assertEqualString(archive_entry_pathname(ae), "dir");
|
2009-12-30 05:59:21 +00:00
|
|
|
assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
|
2008-01-01 22:28:04 +00:00
|
|
|
|
|
|
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
|
|
|
|
assertEqualString(archive_entry_pathname(ae), "dir/file with space");
|
|
|
|
|
|
|
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
|
2009-12-30 05:59:21 +00:00
|
|
|
assertEqualString(archive_entry_pathname(ae), "file with space");
|
2008-01-01 22:28:04 +00:00
|
|
|
|
|
|
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
|
|
|
|
assertEqualString(archive_entry_pathname(ae), "dir2");
|
|
|
|
|
|
|
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
|
|
|
|
assertEqualString(archive_entry_pathname(ae), "dir2/dir3a");
|
|
|
|
|
|
|
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
|
|
|
|
assertEqualString(archive_entry_pathname(ae), "dir2/dir3a/indir3a");
|
|
|
|
|
|
|
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
|
|
|
|
assertEqualString(archive_entry_pathname(ae), "dir2/fullindir2");
|
|
|
|
assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
|
|
|
|
|
|
|
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
|
|
|
|
assertEqualString(archive_entry_pathname(ae), "dir2/indir2");
|
|
|
|
|
|
|
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
|
|
|
|
assertEqualString(archive_entry_pathname(ae), "dir2/dir3b");
|
|
|
|
|
|
|
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
|
|
|
|
assertEqualString(archive_entry_pathname(ae), "dir2/dir3b/indir3b");
|
|
|
|
|
|
|
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
|
|
|
|
assertEqualString(archive_entry_pathname(ae), "notindir");
|
|
|
|
|
|
|
|
assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
|
|
|
|
assertEqualInt(ARCHIVE_OK, archive_read_close(a));
|
2008-09-01 05:38:33 +00:00
|
|
|
assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
|
2008-01-01 22:28:04 +00:00
|
|
|
}
|
|
|
|
|
2009-12-30 05:59:21 +00:00
|
|
|
static void
|
|
|
|
test_read_format_mtree2(void)
|
|
|
|
{
|
|
|
|
static char archive[] =
|
|
|
|
"#mtree\n"
|
|
|
|
"d type=dir content=.\n";
|
|
|
|
struct archive_entry *ae;
|
|
|
|
struct archive *a;
|
2008-01-01 22:28:04 +00:00
|
|
|
|
2009-12-30 05:59:21 +00:00
|
|
|
assert((a = archive_read_new()) != NULL);
|
|
|
|
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_format(a), ARCHIVE_FORMAT_MTREE);
|
|
|
|
assertEqualString(archive_entry_pathname(ae), "d");
|
|
|
|
assertEqualInt(archive_entry_filetype(ae), AE_IFDIR);
|
|
|
|
assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
|
|
|
|
assertEqualInt(ARCHIVE_OK, archive_read_close(a));
|
|
|
|
assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
|
|
|
|
}
|
|
|
|
|
2011-08-07 08:42:36 +00:00
|
|
|
/*
|
|
|
|
* Reported to libarchive.googlecode.com as Issue 121.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
test_read_format_mtree3(void)
|
|
|
|
{
|
|
|
|
static char archive[] =
|
|
|
|
"#mtree\n"
|
|
|
|
"a type=file contents=file\n"
|
|
|
|
"b type=link link=a\n"
|
|
|
|
"c type=file contents=file\n";
|
|
|
|
struct archive_entry *ae;
|
|
|
|
struct archive *a;
|
|
|
|
|
|
|
|
assertMakeDir("mtree3", 0777);
|
|
|
|
assertChdir("mtree3");
|
|
|
|
assertMakeFile("file", 0644, "file contents");
|
|
|
|
|
|
|
|
assert((a = archive_read_new()) != NULL);
|
|
|
|
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));
|
|
|
|
assertEqualString(archive_entry_pathname(ae), "a");
|
|
|
|
assertEqualInt(archive_entry_filetype(ae), AE_IFREG);
|
|
|
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
|
|
|
|
assertEqualString(archive_entry_pathname(ae), "b");
|
|
|
|
assertEqualInt(archive_entry_filetype(ae), AE_IFLNK);
|
|
|
|
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
|
|
|
|
assertEqualString(archive_entry_pathname(ae), "c");
|
|
|
|
assertEqualInt(archive_entry_filetype(ae), AE_IFREG);
|
|
|
|
|
|
|
|
assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
|
|
|
|
assertEqualInt(ARCHIVE_OK, archive_read_close(a));
|
|
|
|
assertEqualInt(ARCHIVE_OK, archive_read_finish(a));
|
|
|
|
|
|
|
|
assertChdir("..");
|
|
|
|
}
|
|
|
|
|
2009-12-30 05:59:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
DEFINE_TEST(test_read_format_mtree)
|
|
|
|
{
|
|
|
|
test_read_format_mtree1();
|
|
|
|
test_read_format_mtree2();
|
2011-08-07 08:42:36 +00:00
|
|
|
test_read_format_mtree3();
|
2009-12-30 05:59:21 +00:00
|
|
|
}
|