mirror of
https://github.com/php/php-src.git
synced 2025-08-16 14:08:47 +02:00
- Finish get/setStub()
This commit is contained in:
parent
038de43fd6
commit
ed454d0fc8
4 changed files with 23 additions and 7 deletions
|
@ -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) {
|
||||
|
|
|
@ -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 (!phar_obj->arc.archive->fp) {
|
||||
if (!fp) {
|
||||
fp = php_stream_open_wrapper(phar_obj->arc.archive->fname, "rb", 0, NULL);
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -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(); ?>
|
||||
<?php echo "third stub\n"; __HALT_COMPILER(); ?>
|
||||
===DONE===
|
||||
|
|
|
@ -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===
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue