Skip to content

Commit fd5c14e

Browse files
committed
Revert "ext/phar: Voidify flush function as it always returns EOL"
This reverts commit 2513258.
1 parent 835c6c7 commit fd5c14e

File tree

5 files changed

+66
-62
lines changed

5 files changed

+66
-62
lines changed

ext/phar/phar.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,16 +2496,16 @@ zend_string *phar_create_default_stub(const char *index_php, const char *web_ind
24962496
}
24972497
/* }}} */
24982498

2499-
void phar_flush(phar_archive_data *phar, char **error) {
2500-
phar_flush_ex(phar, NULL, false, error);
2499+
int phar_flush(phar_archive_data *phar, char **error) {
2500+
return phar_flush_ex(phar, NULL, false, error);
25012501
}
25022502

25032503
/**
25042504
* Save phar contents to disk
25052505
*
25062506
* if user_stub is NULL the default or existing stub should be used
25072507
*/
2508-
void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error) /* {{{ */
2508+
int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error) /* {{{ */
25092509
{
25102510
static const char halt_stub[] = "__HALT_COMPILER();";
25112511

@@ -2533,31 +2533,29 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
25332533
if (error) {
25342534
spprintf(error, 0, "internal error: attempt to flush cached zip-based phar \"%s\"", phar->fname);
25352535
}
2536-
return;
2536+
return EOF;
25372537
}
25382538

25392539
if (error) {
25402540
*error = NULL;
25412541
}
25422542

25432543
if (!zend_hash_num_elements(&phar->manifest) && !user_stub) {
2544-
return;
2544+
return EOF;
25452545
}
25462546

25472547
zend_hash_clean(&phar->virtual_dirs);
25482548

25492549
if (phar->is_zip) {
2550-
phar_zip_flush(phar, user_stub, is_default_stub, error);
2551-
return;
2550+
return phar_zip_flush(phar, user_stub, is_default_stub, error);
25522551
}
25532552

25542553
if (phar->is_tar) {
2555-
phar_tar_flush(phar, user_stub, is_default_stub, error);
2556-
return;
2554+
return phar_tar_flush(phar, user_stub, is_default_stub, error);
25572555
}
25582556

25592557
if (PHAR_G(readonly)) {
2560-
return;
2558+
return EOF;
25612559
}
25622560

25632561
if (phar->fp && !phar->is_brandnew) {
@@ -2576,7 +2574,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
25762574
if (must_close_old_file) {
25772575
php_stream_close(oldfile);
25782576
}
2579-
return;
2577+
return EOF;
25802578
}
25812579

25822580
if (user_stub) {
@@ -2590,7 +2588,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
25902588
if (error) {
25912589
spprintf(error, 0, "illegal stub for phar \"%s\" (__HALT_COMPILER(); is missing)", phar->fname);
25922590
}
2593-
return;
2591+
return EOF;
25942592
}
25952593

25962594
size_t len = pos - ZSTR_VAL(user_stub) + strlen(halt_stub);
@@ -2608,7 +2606,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
26082606
if (error) {
26092607
spprintf(error, 0, "unable to create stub from string in new phar \"%s\"", phar->fname);
26102608
}
2611-
return;
2609+
return EOF;
26122610
}
26132611
phar->halt_offset = len + end_sequence_len;
26142612
} else {
@@ -2638,7 +2636,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
26382636
if (new_stub) {
26392637
zend_string_free(new_stub);
26402638
}
2641-
return;
2639+
return EOF;
26422640
}
26432641
if (new_stub) {
26442642
zend_string_free(new_stub);
@@ -2734,7 +2732,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
27342732
if (error) {
27352733
spprintf(error, 0, "unable to seek to start of file \"%s\" while creating new phar \"%s\"", entry->filename, phar->fname);
27362734
}
2737-
return;
2735+
return EOF;
27382736
}
27392737
newcrc32 = php_crc32_bulk_init();
27402738
php_crc32_stream_bulk_update(&newcrc32, file, entry->uncompressed_filesize);
@@ -2760,7 +2758,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
27602758
spprintf(error, 0, "unable to bzip2 compress file \"%s\" to new phar \"%s\"", entry->filename, phar->fname);
27612759
}
27622760
}
2763-
return;
2761+
return EOF;
27642762
}
27652763

27662764
/* create new file that holds the compressed versions */
@@ -3086,7 +3084,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
30863084
php_stream_close(oldfile);
30873085
}
30883086
php_stream_close(newfile);
3089-
return;
3087+
return EOF;
30903088
}
30913089

30923090
php_stream_write(newfile, digest, digest_len);
@@ -3138,7 +3136,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
31383136
if (error) {
31393137
spprintf(error, 4096, "unable to open new phar \"%s\" for writing", phar->fname);
31403138
}
3141-
return;
3139+
return EOF;
31423140
}
31433141

31443142
if (phar->flags & PHAR_FILE_COMPRESSED_GZ) {
@@ -3154,7 +3152,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
31543152
if (error) {
31553153
spprintf(error, 4096, "unable to compress all contents of phar \"%s\" using zlib, PHP versions older than 5.2.6 have a buggy zlib", phar->fname);
31563154
}
3157-
return;
3155+
return EOF;
31583156
}
31593157

31603158
php_stream_filter_append(&phar->fp->writefilters, filter);
@@ -3184,9 +3182,10 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
31843182
if (error) {
31853183
spprintf(error, 0, "unable to seek to __HALT_COMPILER(); in new phar \"%s\"", phar->fname);
31863184
}
3185+
return EOF;
31873186
}
31883187

3189-
return;
3188+
return EOF;
31903189

31913190
cleanup:
31923191
if (shared_cfp != NULL) {
@@ -3198,6 +3197,8 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
31983197
entry->header_offset = 0;
31993198
}
32003199
} ZEND_HASH_FOREACH_END();
3200+
3201+
return EOF;
32013202
}
32023203
/* }}} */
32033204

ext/phar/phar_internal.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,12 @@ zend_result phar_copy_on_write(phar_archive_data **pphar);
447447
bool phar_is_tar(char *buf, char *fname);
448448
zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, char *alias, size_t alias_len, phar_archive_data** pphar, uint32_t compression, char **error);
449449
zend_result phar_open_or_create_tar(char *fname, size_t fname_len, char *alias, size_t alias_len, int is_data, uint32_t options, phar_archive_data** pphar, char **error);
450-
void phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error);
450+
int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error);
451451

452452
/* zip functions in zip.c */
453453
int phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alias, size_t alias_len, phar_archive_data** pphar, char **error);
454454
int phar_open_or_create_zip(char *fname, size_t fname_len, char *alias, size_t alias_len, int is_data, uint32_t options, phar_archive_data** pphar, char **error);
455-
void phar_zip_flush(phar_archive_data *archive, zend_string *user_stub, bool is_default_stub, char **error);
455+
int phar_zip_flush(phar_archive_data *archive, zend_string *user_stub, bool is_default_stub, char **error);
456456

457457
#ifdef PHAR_MAIN
458458
extern const php_stream_wrapper php_stream_phar_wrapper;
@@ -468,8 +468,8 @@ phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, size_t
468468
phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, size_t path_len, char dir, char **error, int security);
469469
phar_entry_data *phar_get_or_create_entry_data(char *fname, size_t fname_len, char *path, size_t path_len, const char *mode, char allow_dir, char **error, int security);
470470
zend_result phar_get_entry_data(phar_entry_data **ret, char *fname, size_t fname_len, char *path, size_t path_len, const char *mode, char allow_dir, char **error, int security);
471-
void phar_flush_ex(phar_archive_data *archive, zend_string *user_stub, bool is_default_stub, char **error);
472-
void phar_flush(phar_archive_data *archive, char **error);
471+
int phar_flush_ex(phar_archive_data *archive, zend_string *user_stub, bool is_default_stub, char **error);
472+
int phar_flush(phar_archive_data *archive, char **error);
473473
zend_result phar_detect_phar_fname_ext(const char *filename, size_t filename_len, const char **ext_str, size_t *ext_len, int executable, int for_create, int is_complete);
474474
zend_result phar_split_fname(const char *filename, size_t filename_len, char **arch, size_t *arch_len, char **entry, size_t *entry_len, int executable, int for_create);
475475

ext/phar/stream.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,16 +471,17 @@ static ssize_t phar_stream_write(php_stream *stream, const char *buf, size_t cou
471471
static int phar_stream_flush(php_stream *stream) /* {{{ */
472472
{
473473
char *error;
474+
int ret;
474475
phar_entry_data *data = (phar_entry_data *) stream->abstract;
475476

476477
if (data->internal_file->is_modified) {
477478
data->internal_file->timestamp = time(0);
478-
phar_flush(data->phar, &error);
479+
ret = phar_flush(data->phar, &error);
479480
if (error) {
480481
php_stream_wrapper_log_error(stream->wrapper, REPORT_ERRORS, "%s", error);
481482
efree(error);
482483
}
483-
return EOF;
484+
return ret;
484485
} else {
485486
return EOF;
486487
}

0 commit comments

Comments
 (0)