mirror of
https://github.com/php/php-src.git
synced 2024-09-23 19:07:26 +00:00
fix creation of phar from scratch, add test case
This commit is contained in:
parent
344cda1666
commit
ef4749b8cf
@ -1425,7 +1425,7 @@ static size_t phar_write(php_stream *stream, const char *buf, size_t count TSRML
|
||||
data->internal_file->uncompressed_filesize += count;
|
||||
data->internal_file->compressed_filesize = data->internal_file->uncompressed_filesize;
|
||||
data->internal_file->flags |= PHAR_ENT_MODIFIED;
|
||||
return 0;
|
||||
return count;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@ -1499,6 +1499,14 @@ static int phar_flush(php_stream *stream TSRMLS_DC) /* {{{ */
|
||||
php_stream_close(newfile);
|
||||
php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "unable to copy prologue of old phar to new phar \"%s\"", data->phar->fname);
|
||||
}
|
||||
} else {
|
||||
/* this is a brand new phar */
|
||||
data->phar->halt_offset = sizeof("<?php __HALT_COMPILER(); ?>");
|
||||
if (sizeof("<?php __HALT_COMPILER(); ?>") != php_stream_write(newfile, "<?php __HALT_COMPILER(); ?>" ,sizeof("<?php __HALT_COMPILER(); ?>"))) {
|
||||
php_stream_close(data->fp);
|
||||
php_stream_close(newfile);
|
||||
php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "unable to create prologue in new phar \"%s\"", data->phar->fname);
|
||||
}
|
||||
}
|
||||
manifest_ftell = php_stream_tell(newfile);
|
||||
buffer = (char *) emalloc(300);
|
||||
@ -1772,7 +1780,9 @@ static int phar_flush(php_stream *stream TSRMLS_DC) /* {{{ */
|
||||
php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "unable to seek to __HALT_COMPILER(); in new phar \"%s\"", data->phar->fname);
|
||||
}
|
||||
|
||||
if (data->fp) {
|
||||
php_stream_close(data->fp);
|
||||
}
|
||||
data->fp = 0;
|
||||
if (data->phar->fp) {
|
||||
/* we will re-open this later */
|
||||
|
18
ext/phar/tests/create_new_phar.phpt
Normal file
18
ext/phar/tests/create_new_phar.phpt
Normal file
@ -0,0 +1,18 @@
|
||||
--TEST--
|
||||
Phar: create a completely new phar
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("phar")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
file_put_contents('phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/a.php',
|
||||
'brand new!');
|
||||
include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/a.php';
|
||||
?>
|
||||
|
||||
===DONE===
|
||||
--CLEAN--
|
||||
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
|
||||
--EXPECT--
|
||||
brand new!
|
||||
===DONE===
|
Loading…
Reference in New Issue
Block a user