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 - @-
This commit is contained in:
Tim Kientzle 2009-04-26 18:57:50 +00:00
parent 9a4ac3e81e
commit d21d99e07e
2 changed files with 15 additions and 2 deletions

View File

@ -990,8 +990,8 @@ read_data(struct archive_read *a, const void **buff, size_t *size, off_t *offset
if (mtree->buff == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate memory");
return (ARCHIVE_FATAL);
}
return (ARCHIVE_FATAL);
}
*buff = mtree->buff;

View File

@ -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");