]> granicus.if.org Git - php/commitdiff
- Fix issues with metadata testing
authorMarcus Boerger <helly@php.net>
Sun, 21 Jan 2007 15:57:12 +0000 (15:57 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 21 Jan 2007 15:57:12 +0000 (15:57 +0000)
ext/phar/phar.c
ext/phar/tests/metadata_read.phpt
ext/phar/tests/phar_test.inc

index 2130d3c6ccd575855b13511b51be53e896bde201..cb79ab4c8583891a87534cfa043bb4884defdddf 100644 (file)
@@ -391,6 +391,7 @@ static int phar_parse_metadata(php_stream *fp, char **buffer, char *endbuffer, z
        php_uint32 datatype;
        php_uint16 len;
        char *data;
+
        do {
                /* for each meta-data, add an array index to the metadata array
                   if the index already exists, convert to a sub-array */
@@ -404,18 +405,18 @@ static int phar_parse_metadata(php_stream *fp, char **buffer, char *endbuffer, z
                        memcpy(data, *buffer, len);
                        data[len] = '\0';
                }
-               if (SUCCESS == zend_hash_index_find(metadata->value.ht, datatype, (void**)&found)) {
+               if (SUCCESS == zend_hash_index_find(HASH_OF(metadata), datatype, (void**)&found)) {
                        if (Z_TYPE_P(found) == IS_ARRAY) {
-                               add_next_index_stringl(dataarray, data, len, 0);
+                               dataarray = found;
                        } else {
                                MAKE_STD_ZVAL(dataarray);
                                array_init(dataarray);
                                add_next_index_zval(dataarray, found);
-                               add_next_index_stringl(dataarray, data, len, 0); 
                        }
                } else {
-                       add_index_stringl(metadata, datatype, data, len, 0);
+                       dataarray = metadata;
                }
+               add_index_stringl(dataarray, datatype, data, len, 0);
        } while (*(php_uint32 *) *buffer && *buffer < endbuffer);
        *buffer += 4;
        return SUCCESS;
index 0a5b3be68044c83430f91c35198f178ef3461895..c9dbc7eb21e053bdf211beadbf09ba9cbad12266 100644 (file)
@@ -7,34 +7,19 @@ if (!extension_loaded("zlib")) print "skip zlib not present"; ?>
 phar.require_hash=0
 --FILE--
 <?php
-$file = "<?php
-Phar::mapPhar('hio');
-__HALT_COMPILER(); ?>";
-// file length is too short
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php __HALT_COMPILER(); ?>";
 
 $files = array();
-$files['c'] = array('*', '*',                                           0x00000000);
-$manifest = '';
-foreach($files as $name => $cont) {
-       $ulen = strlen($cont[0]);
-       $clen = strlen($cont[1]);
-       $manifest .= pack('V', strlen($name)) . $name 
-                 . pack('VVVVVVv', $ulen, time(), $clen, crc32($cont[0]), $cont[2], 1, strlen('hi there')) . 'hi there' .
-                   pack('V', 0);
-}
-$alias = 'hio';
-$manifest = pack('VnVV', count($files), 0x0900, 0x00001000, strlen($alias)) . $alias . $manifest;
-$file .= pack('V', strlen($manifest)) . $manifest;
-foreach($files as $cont)
-{
-       $file .= $cont[1];
-}
+$files['c'] = array('cont' => '*', 'meta' => array(1, 'hi there'));
+
+include 'phar_test.inc';
+
+var_dump(file_get_contents($pname.'/c'));
 
-file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file);
-include dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
-var_dump(file_get_contents('phar://hio/c'));
 ?>
 --CLEAN--
 <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
 --EXPECT--
-string(1) "*"
\ No newline at end of file
+string(1) "*"
index 9f887dceb52440376023c4363336171f3ff1730e..13b9c8b5a59ac09eca6eb2aa8c9f70763e5adc4d 100755 (executable)
@@ -4,18 +4,35 @@ $manifest = '';
 
 foreach($files as $name => $cont)
 {
+       $time = isset($ftime) ? $ftime : @mktime(12, 0, 0, 3, 1, 2006);
+       $perm = 0x000001B6;
+       $meta = array();
+       if (is_array($cont))
+       {
+               foreach(array('time','perm','meta','cont') as $what)
+               {
+                       if (isset($cont[$what]))
+                       {
+                               $$what = $cont[$what];
+                       }
+               }
+       }
        $ulen = strlen($cont);
        $clen = $ulen;
-       $time = isset($ftime) ? $ftime : @mktime(12, 0, 0, 3, 1, 2006);
        $manifest .= pack('V', strlen($name)) . $name;
-       $manifest .= pack('VVVVVV', $ulen, $time, $clen, crc32($cont), 0x000001B6, 0);
+       $manifest .= pack('VVVVV', $ulen, $time, $clen, crc32($cont), $perm);
+       foreach($meta as $type => $data)
+       {
+               $manifest .= pack('Vv', $type, strlen($data)) . $data;
+       }
+       $manifest .= pack('V', 0);
 }
 $alias = 'hio';
 $manifest = pack('VnVV', count($files), 0x0900, 0x00000000, strlen($alias)) . $alias . $manifest;
 $file .= pack('V', strlen($manifest)) . $manifest;
 foreach($files as $cont)
 {
-       $file .= $cont;
+       $file .= is_array($cont) ? $cont['cont'] : $cont;
 }
 
 file_put_contents($fname, $file);