Author: kientzle
Date: Sun Apr 26 18:57:50 2009
New Revision: 191527
URL: http://svn.freebsd.org/changeset/base/191527

Log:
  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 - @-

Modified:
  head/lib/libarchive/archive_read_support_format_mtree.c
  head/lib/libarchive/test/test_read_format_mtree.c

Modified: head/lib/libarchive/archive_read_support_format_mtree.c
==============================================================================
--- head/lib/libarchive/archive_read_support_format_mtree.c     Sun Apr 26 
18:46:40 2009        (r191526)
+++ head/lib/libarchive/archive_read_support_format_mtree.c     Sun Apr 26 
18:57:50 2009        (r191527)
@@ -990,8 +990,8 @@ read_data(struct archive_read *a, const 
                if (mtree->buff == NULL) {
                        archive_set_error(&a->archive, ENOMEM,
                            "Can't allocate memory");
+                       return (ARCHIVE_FATAL);
                }
-               return (ARCHIVE_FATAL);
        }
 
        *buff = mtree->buff;

Modified: head/lib/libarchive/test/test_read_format_mtree.c
==============================================================================
--- head/lib/libarchive/test/test_read_format_mtree.c   Sun Apr 26 18:46:40 
2009        (r191526)
+++ head/lib/libarchive/test/test_read_format_mtree.c   Sun Apr 26 18:57:50 
2009        (r191527)
@@ -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");
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to