]> granicus.if.org Git - php/commitdiff
MFB: fix links for fseek as well
authorGreg Beaver <cellog@php.net>
Sat, 11 Oct 2008 22:21:07 +0000 (22:21 +0000)
committerGreg Beaver <cellog@php.net>
Sat, 11 Oct 2008 22:21:07 +0000 (22:21 +0000)
ext/phar/stream.c
ext/phar/tests/tar/links6.phpt

index 95950bf60f154c6c25738ec82e0e7723fba7a72c..6670f6d48c6797cc1ef4e2b4460405f2a9e2842d 100644 (file)
@@ -389,12 +389,19 @@ static size_t phar_stream_read(php_stream *stream, char *buf, size_t count TSRML
 static int phar_stream_seek(php_stream *stream, off_t offset, int whence, off_t *newoffset TSRMLS_DC) /* {{{ */
 {
        phar_entry_data *data = (phar_entry_data *)stream->abstract;
-
+       phar_entry_info *entry;
        int res;
        off_t temp;
+
+       if (data->internal_file->link) {
+               entry = phar_get_link_source(data->internal_file TSRMLS_CC);
+       } else {
+               entry = data->internal_file;
+       }
+
        switch (whence) {
                case SEEK_END :
-                       temp = data->zero + data->internal_file->uncompressed_filesize + offset;
+                       temp = data->zero + entry->uncompressed_filesize + offset;
                        break;
                case SEEK_CUR :
                        temp = data->zero + data->position + offset;
@@ -403,7 +410,7 @@ static int phar_stream_seek(php_stream *stream, off_t offset, int whence, off_t
                        temp = data->zero + offset;
                        break;
        }
-       if (temp > data->zero + (off_t) data->internal_file->uncompressed_filesize) {
+       if (temp > data->zero + (off_t) entry->uncompressed_filesize) {
                *newoffset = -1;
                return -1;
        }
index 622a8b61bfad619fbc4830c70558f7be599b2725..9a548a878405aba326112c6c970b342c0612bf6c 100644 (file)
@@ -9,6 +9,10 @@ if (!extension_loaded("phar")) die("skip");
 echo file_get_contents('phar://' . dirname(__FILE__) . '/files/links.phar.tar/link2');
 echo file_get_contents('phar://' . dirname(__FILE__) . '/files/links.phar.tar/link1');
 echo file_get_contents('phar://' . dirname(__FILE__) . '/files/links.phar.tar/testit.txt');
+
+$a = fopen('phar://' . dirname(__FILE__) . '/files/links.phar.tar/link2', 'r');
+fseek($a, 3);
+echo fread($a, 10);
 ?>
 ===DONE===
 --EXPECT--
@@ -18,4 +22,6 @@ hi there
 
 hi there
 
+there
+
 ===DONE===
\ No newline at end of file