diff options
author | Tim Kientzle <kientzle@FreeBSD.org> | 2009-04-26 18:57:50 +0000 |
---|---|---|
committer | Tim Kientzle <kientzle@FreeBSD.org> | 2009-04-26 18:57:50 +0000 |
commit | d21d99e07e35684154111e261505a45c8ecfc71c (patch) | |
tree | b4a7f93e145d7ca36b772083b91b87cceb8cbfd1 /lib/libarchive/test | |
parent | 9a4ac3e81e5e9d3564868a233e3e7d866523d3c8 (diff) | |
download | src-d21d99e07e35684154111e261505a45c8ecfc71c.tar.gz src-d21d99e07e35684154111e261505a45c8ecfc71c.zip |
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 - @-
Notes
Notes:
svn path=/head/; revision=191527
Diffstat (limited to 'lib/libarchive/test')
-rw-r--r-- | lib/libarchive/test/test_read_format_mtree.c | 15 |
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 1f2ed8ff5486..b13034fbf4d3 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"); |