From: Greg Beaver Date: Fri, 5 Jan 2007 03:04:56 +0000 (+0000) Subject: fix creation of phar from scratch, add test case X-Git-Tag: RELEASE_1_0_0RC1~396 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ef4749b8cfd7d92e34b04183e4dc21254208cacd;p=php fix creation of phar from scratch, add test case --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 9c444c4bb7..63d8b7371f 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -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(""); + if (sizeof("") != php_stream_write(newfile, "" ,sizeof(""))) { + 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); @@ -1771,15 +1779,17 @@ static int phar_flush(php_stream *stream TSRMLS_DC) /* {{{ */ php_stream_close(data->fp); php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "unable to seek to __HALT_COMPILER(); in new phar \"%s\"", data->phar->fname); } - - php_stream_close(data->fp); + + if (data->fp) { + php_stream_close(data->fp); + } data->fp = 0; if (data->phar->fp) { /* we will re-open this later */ php_stream_close(data->phar->fp); data->phar->fp = 0; } - + fname = estrndup(data->phar->fname, data->phar->fname_len); fname_len = data->phar->fname_len; alias = estrndup(data->phar->alias, data->phar->alias_len); diff --git a/ext/phar/tests/create_new_phar.phpt b/ext/phar/tests/create_new_phar.phpt new file mode 100644 index 0000000000..8b58aa892e --- /dev/null +++ b/ext/phar/tests/create_new_phar.phpt @@ -0,0 +1,18 @@ +--TEST-- +Phar: create a completely new phar +--SKIPIF-- + +--FILE-- + + +===DONE=== +--CLEAN-- + +--EXPECT-- +brand new! +===DONE===