cosmetics/maintainability: reduce code redundancy on error conditions

This commit is contained in:
Greg Beaver 2008-10-11 21:22:58 +00:00
parent eb41e0d64f
commit bf268a68f9

View file

@ -1170,6 +1170,7 @@ nostub:
pass.filefp = php_stream_fopen_tmpfile(); pass.filefp = php_stream_fopen_tmpfile();
if (!pass.filefp) { if (!pass.filefp) {
fperror:
if (closeoldfile) { if (closeoldfile) {
php_stream_close(oldfile); php_stream_close(oldfile);
} }
@ -1182,13 +1183,7 @@ nostub:
pass.centralfp = php_stream_fopen_tmpfile(); pass.centralfp = php_stream_fopen_tmpfile();
if (!pass.centralfp) { if (!pass.centralfp) {
if (closeoldfile) { goto fperror;
php_stream_close(oldfile);
}
if (error) {
spprintf(error, 4096, "phar zip flush of \"%s\" failed: unable to open temporary file", phar->fname);
}
return EOF;
} }
pass.free_fp = pass.free_ufp = 1; pass.free_fp = pass.free_ufp = 1;
@ -1199,15 +1194,17 @@ nostub:
zend_hash_apply_with_argument(&phar->manifest, phar_zip_changed_apply, (void *) &pass TSRMLS_CC); zend_hash_apply_with_argument(&phar->manifest, phar_zip_changed_apply, (void *) &pass TSRMLS_CC);
if (temperr) { if (temperr) {
php_stream_close(pass.filefp);
php_stream_close(pass.centralfp);
if (closeoldfile) {
php_stream_close(oldfile);
}
if (error) { if (error) {
spprintf(error, 4096, "phar zip flush of \"%s\" failed: %s", phar->fname, temperr); spprintf(error, 4096, "phar zip flush of \"%s\" failed: %s", phar->fname, temperr);
} }
efree(temperr); efree(temperr);
temperror:
php_stream_close(pass.centralfp);
nocentralerror:
php_stream_close(pass.filefp);
if (closeoldfile) {
php_stream_close(oldfile);
}
return EOF; return EOF;
} }
@ -1217,15 +1214,10 @@ nostub:
php_stream_seek(pass.centralfp, 0, SEEK_SET); php_stream_seek(pass.centralfp, 0, SEEK_SET);
if (eocd.cdir_size != php_stream_copy_to_stream(pass.centralfp, pass.filefp, PHP_STREAM_COPY_ALL)) { if (eocd.cdir_size != php_stream_copy_to_stream(pass.centralfp, pass.filefp, PHP_STREAM_COPY_ALL)) {
php_stream_close(pass.filefp);
php_stream_close(pass.centralfp);
if (error) { if (error) {
spprintf(error, 4096, "phar zip flush of \"%s\" failed: unable to write central-directory", phar->fname); spprintf(error, 4096, "phar zip flush of \"%s\" failed: unable to write central-directory", phar->fname);
} }
if (closeoldfile) { goto temperror;
php_stream_close(oldfile);
}
return EOF;
} }
php_stream_close(pass.centralfp); php_stream_close(pass.centralfp);
@ -1238,41 +1230,27 @@ nostub:
eocd.comment_len = PHAR_SET_16(main_metadata_str.len); eocd.comment_len = PHAR_SET_16(main_metadata_str.len);
if (sizeof(eocd) != php_stream_write(pass.filefp, (char *)&eocd, sizeof(eocd))) { if (sizeof(eocd) != php_stream_write(pass.filefp, (char *)&eocd, sizeof(eocd))) {
php_stream_close(pass.filefp);
if (error) { if (error) {
spprintf(error, 4096, "phar zip flush of \"%s\" failed: unable to write end of central-directory", phar->fname); spprintf(error, 4096, "phar zip flush of \"%s\" failed: unable to write end of central-directory", phar->fname);
} }
if (closeoldfile) { goto nocentralerror;
php_stream_close(oldfile);
}
smart_str_free(&main_metadata_str);
return EOF;
} }
if (main_metadata_str.len != php_stream_write(pass.filefp, main_metadata_str.c, main_metadata_str.len)) { if (main_metadata_str.len != php_stream_write(pass.filefp, main_metadata_str.c, main_metadata_str.len)) {
php_stream_close(pass.filefp);
if (error) { if (error) {
spprintf(error, 4096, "phar zip flush of \"%s\" failed: unable to write metadata to zip comment", phar->fname); spprintf(error, 4096, "phar zip flush of \"%s\" failed: unable to write metadata to zip comment", phar->fname);
} }
if (closeoldfile) { goto nocentralerror;
php_stream_close(oldfile);
}
smart_str_free(&main_metadata_str);
return EOF;
} }
smart_str_free(&main_metadata_str); smart_str_free(&main_metadata_str);
} else { } else {
if (sizeof(eocd) != php_stream_write(pass.filefp, (char *)&eocd, sizeof(eocd))) { if (sizeof(eocd) != php_stream_write(pass.filefp, (char *)&eocd, sizeof(eocd))) {
php_stream_close(pass.filefp);
if (error) { if (error) {
spprintf(error, 4096, "phar zip flush of \"%s\" failed: unable to write end of central-directory", phar->fname); spprintf(error, 4096, "phar zip flush of \"%s\" failed: unable to write end of central-directory", phar->fname);
} }
if (closeoldfile) { goto nocentralerror;
php_stream_close(oldfile);
}
return EOF;
} }
} }