From: Greg Beaver Date: Mon, 21 Apr 2008 16:50:18 +0000 (+0000) Subject: another refactoring to combine an error and improve code coverage as a side effect X-Git-Tag: RELEASE_2_0_0b1~283 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aaf6101928adf1fe447ad7b6963eb2c9d2670d5d;p=php another refactoring to combine an error and improve code coverage as a side effect --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index bcb3f65333..001ae239b1 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -2163,31 +2163,34 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, int convert, efree(user_stub); } } else { + size_t written; + if (!user_stub && phar->halt_offset && oldfile && !phar->is_brandnew) { - if (phar->halt_offset != php_stream_copy_to_stream(oldfile, newfile, phar->halt_offset)) { - if (closeoldfile) { - php_stream_close(oldfile); - } - php_stream_close(newfile); - if (error) { - spprintf(error, 0, "unable to copy stub of old phar to new phar \"%s\"", phar->fname); - } - return EOF; - } + written = php_stream_copy_to_stream(oldfile, newfile, phar->halt_offset); + newstub = NULL; } else { /* this is either a brand new phar or a default stub overwrite */ newstub = phar_create_default_stub(NULL, NULL, &(phar->halt_offset), NULL TSRMLS_CC); - if (phar->halt_offset != php_stream_write(newfile, newstub, phar->halt_offset)) { - efree(newstub); - if (closeoldfile) { - php_stream_close(oldfile); - } - php_stream_close(newfile); - if (error) { + written = php_stream_write(newfile, newstub, phar->halt_offset); + } + if (phar->halt_offset != written) { + if (closeoldfile) { + php_stream_close(oldfile); + } + php_stream_close(newfile); + if (error) { + if (newstub) { spprintf(error, 0, "unable to create stub in new phar \"%s\"", phar->fname); + } else { + spprintf(error, 0, "unable to copy stub of old phar to new phar \"%s\"", phar->fname); } - return EOF; } + if (newstub) { + efree(newstub); + } + return EOF; + } + if (newstub) { efree(newstub); } }