]> granicus.if.org Git - php/commitdiff
- Finish get/setStub()
authorMarcus Boerger <helly@php.net>
Mon, 22 Jan 2007 00:59:02 +0000 (00:59 +0000)
committerMarcus Boerger <helly@php.net>
Mon, 22 Jan 2007 00:59:02 +0000 (00:59 +0000)
ext/phar/phar.c
ext/phar/phar_object.c
ext/phar/tests/phar_stub.phpt
ext/phar/tests/phar_stub_write.phpt

index 900f4e83642fabc807bb7c00ed853dba4b8779a1..a101b7eee5b4b5d693cc72298a7dc914ea67588e 100644 (file)
@@ -1597,7 +1597,8 @@ int phar_flush(phar_entry_data *data, char *user_stub, long len TSRMLS_DC) /* {{
                        } else {
                                len = -len;
                        }
-                       if (len != php_stream_copy_to_stream(stubfile, newfile, len) && len != PHP_STREAM_COPY_ALL) {
+                       offset = php_stream_copy_to_stream(stubfile, newfile, len);
+                       if (len != offset && len != PHP_STREAM_COPY_ALL) {
                                if (oldfile) {
                                        php_stream_close(oldfile);
                                }
@@ -1605,6 +1606,7 @@ int phar_flush(phar_entry_data *data, char *user_stub, long len TSRMLS_DC) /* {{
                                php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "unable to copy stub from resource to new phar \"%s\"", data->phar->fname);
                                return EOF;
                        }
+                       data->phar->halt_offset = offset;
                } else {
                        if (len != php_stream_write(newfile, user_stub, len)) {
                                if (oldfile) {
@@ -1614,6 +1616,7 @@ int phar_flush(phar_entry_data *data, char *user_stub, long len TSRMLS_DC) /* {{
                                php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "unable to create stub from string in new phar \"%s\"", data->phar->fname);
                                return EOF;
                        }
+                       data->phar->halt_offset = len;
                }
        } else {
                if (data->phar->halt_offset && oldfile) {
index 3750ed8663d8d9366d65354b7f1c4222a295747d..5d35de239ecfb617ad83e5c4122f359fbf37eb2d 100755 (executable)
@@ -421,24 +421,36 @@ PHP_METHOD(Phar, getStub)
 {
        char *buf;
        int len;
+       php_stream *fp;
        PHAR_ARCHIVE_OBJECT();
 
        len = phar_obj->arc.archive->halt_offset;
+       fp = phar_obj->arc.archive->fp;
+
+       if (!fp) {
+                fp = php_stream_open_wrapper(phar_obj->arc.archive->fname, "rb", 0, NULL);
+       }
 
-       if (!phar_obj->arc.archive->fp)  {
+       if (!fp)  {
                zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,
                        "Unable to read stub");
                return;
        }
 
        buf = emalloc(len+1);
-       php_stream_rewind(phar_obj->arc.archive->fp);
-       if (len != php_stream_read(phar_obj->arc.archive->fp, buf, len)) {
+       php_stream_rewind(fp);
+       if (len != php_stream_read(fp, buf, len)) {
+               if (fp != phar_obj->arc.archive->fp) {
+                       php_stream_close(fp);
+               }
                zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,
                        "Unable to read stub");
                efree(buf);
                return;
        }
+       if (fp != phar_obj->arc.archive->fp) {
+               php_stream_close(fp);
+       }
        buf[len] = '\0';
        
        RETURN_STRINGL(buf, len, 0);
index 97f7f15ce243b4c08040dd3386b7fdc243f1ef96..5749b124af53565d82929bae4beffe4809132c29 100644 (file)
@@ -72,9 +72,9 @@ unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.ph
 __HALT_COMPILER();
 ?>
 --EXPECT--
-===DONE===
 <?php echo "first stub\n"; __HALT_COMPILER(); ?>
 <?php echo "second stub\n"; __HALT_COMPILER(); ?>
 <?php echo "third stub\n"; __HALT_COMPILER(); ?>
 <?php echo "third stub\n"; __HALT_COMPILER(); ?>booya
-<?php echo "third stub\n"; __HALT_COMPILER(); ?>
\ No newline at end of file
+<?php echo "third stub\n"; __HALT_COMPILER(); ?>
+===DONE===
index 031ec681e20e59cf3f6b36e811c32169bcbd5f6a..c42a4a00d8f3d2e10016847f018d46a1130fb2cd 100755 (executable)
@@ -25,6 +25,7 @@ var_dump($phar->getStub() == $stub);
 
 $stub = '<?php echo "second stub\n"; __HALT_COMPILER(); ?>';
 $phar->setStub($stub);
+var_dump($phar->getStub());
 var_dump($phar->getStub() == $stub);
 
 $phar = new Phar($fname);
@@ -35,13 +36,13 @@ var_dump($phar->getStub() == $stub);
 --CLEAN--
 <?php 
 unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
-unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php');
 __HALT_COMPILER();
 ?>
 --EXPECT--
 string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
 string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
 bool(true)
+string(49) "<?php echo "second stub\n"; __HALT_COMPILER(); ?>"
 bool(true)
 bool(true)
 ===DONE===