From: Marcus Boerger Date: Mon, 22 Jan 2007 00:59:02 +0000 (+0000) Subject: - Finish get/setStub() X-Git-Tag: RELEASE_1_0_0RC1~164 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ed454d0fc8b447b08cefd1fd41d82950456cf635;p=php - Finish get/setStub() --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 900f4e8364..a101b7eee5 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -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) { diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 3750ed8663..5d35de239e 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -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); diff --git a/ext/phar/tests/phar_stub.phpt b/ext/phar/tests/phar_stub.phpt index 97f7f15ce2..5749b124af 100644 --- a/ext/phar/tests/phar_stub.phpt +++ b/ext/phar/tests/phar_stub.phpt @@ -72,9 +72,9 @@ unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.ph __HALT_COMPILER(); ?> --EXPECT-- -===DONE=== booya - \ No newline at end of file + +===DONE=== diff --git a/ext/phar/tests/phar_stub_write.phpt b/ext/phar/tests/phar_stub_write.phpt index 031ec681e2..c42a4a00d8 100755 --- a/ext/phar/tests/phar_stub_write.phpt +++ b/ext/phar/tests/phar_stub_write.phpt @@ -25,6 +25,7 @@ var_dump($phar->getStub() == $stub); $stub = ''; $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-- --EXPECT-- string(48) "" string(48) "" bool(true) +string(49) "" bool(true) bool(true) ===DONE===