} 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);
}
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) {
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) {
{
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);
__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===
$stub = '<?php echo "second stub\n"; __HALT_COMPILER(); ?>';
$phar->setStub($stub);
+var_dump($phar->getStub());
var_dump($phar->getStub() == $stub);
$phar = new Phar($fname);
--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===