summaryrefslogtreecommitdiffstats
path: root/lib/libarchive/test/test_read_format_mtree.c
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2009-04-26 18:57:50 +0000
committerkientzle <kientzle@FreeBSD.org>2009-04-26 18:57:50 +0000
commit59019e8516a585542319c3d3a058f97468157f38 (patch)
treeb4a7f93e145d7ca36b772083b91b87cceb8cbfd1 /lib/libarchive/test/test_read_format_mtree.c
parent46f05636f646702fc3211002ea6cb863ea32b00f (diff)
downloadFreeBSD-src-59019e8516a585542319c3d3a058f97468157f38.zip
FreeBSD-src-59019e8516a585542319c3d3a058f97468157f38.tar.gz
Reading an mtree file is supposed to provide
access to the file data (if the file exists on disk). This was broken for the first regular file; fix it and add a test so it won't break again. In particular, this fixes the following idiom for creating a tar archive in which every file is owned by root: tar cf - --format=mtree . \ | sed -e 's/uname=[a-z]*/uname=root/' -e 's/uid=[0-9]*/uid=0/' \ | tar cf - @-
Diffstat (limited to 'lib/libarchive/test/test_read_format_mtree.c')
-rw-r--r--lib/libarchive/test/test_read_format_mtree.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/libarchive/test/test_read_format_mtree.c b/lib/libarchive/test/test_read_format_mtree.c
index 1f2ed8f..b13034f 100644
--- a/lib/libarchive/test/test_read_format_mtree.c
+++ b/lib/libarchive/test/test_read_format_mtree.c
@@ -28,7 +28,7 @@ __FBSDID("$FreeBSD$");
/* Single entry with a hardlink. */
static unsigned char archive[] = {
"#mtree\n"
- "file type=file uid=18 mode=0123\n"
+ "file type=file uid=18 mode=0123 size=3\n"
"dir type=dir\n"
" file\\040with\\040space type=file uid=18\n"
" ..\n"
@@ -49,8 +49,10 @@ static unsigned char archive[] = {
DEFINE_TEST(test_read_format_mtree)
{
+ char buff[16];
struct archive_entry *ae;
struct archive *a;
+ int fd;
/*
* An access error occurred on some platform when mtree
@@ -68,12 +70,23 @@ DEFINE_TEST(test_read_format_mtree)
archive_read_support_format_all(a));
assertEqualIntA(a, ARCHIVE_OK,
archive_read_open_memory(a, archive, sizeof(archive)));
+
+ /*
+ * Read "file", whose data is available on disk.
+ */
+ fd = open("file", O_WRONLY | O_CREAT, 0777);
+ assert(fd >= 0);
+ assertEqualInt(3, write(fd, "hi\n", 3));
+ close(fd);
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualInt(archive_format(a), ARCHIVE_FORMAT_MTREE);
assertEqualString(archive_entry_pathname(ae), "file");
assertEqualInt(archive_entry_uid(ae), 18);
assert(S_ISREG(archive_entry_mode(ae)));
assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0123);
+ assertEqualInt(archive_entry_size(ae), 3);
+ assertEqualInt(3, archive_read_data(a, buff, 3));
+ assertEqualMem(buff, "hi\n", 3);
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualString(archive_entry_pathname(ae), "dir");
OpenPOWER on IntegriCloud