Skip to content

Commit 2513258

Browse files
committed
ext/phar: Voidify flush function as it always returns EOL
1 parent 4f9fdf8 commit 2513258

File tree

5 files changed

+62
-66
lines changed

5 files changed

+62
-66
lines changed

ext/phar/phar.c

+20-21
Original file line numberDiff line numberDiff line change
@@ -2520,16 +2520,16 @@ zend_string *phar_create_default_stub(const char *index_php, const char *web_ind
25202520
}
25212521
/* }}} */
25222522

2523-
int phar_flush(phar_archive_data *phar, char **error) {
2524-
return phar_flush_ex(phar, NULL, false, error);
2523+
void phar_flush(phar_archive_data *phar, char **error) {
2524+
phar_flush_ex(phar, NULL, false, error);
25252525
}
25262526

25272527
/**
25282528
* Save phar contents to disk
25292529
*
25302530
* if user_stub is NULL the default or existing stub should be used
25312531
*/
2532-
int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error) /* {{{ */
2532+
void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error) /* {{{ */
25332533
{
25342534
static const char halt_stub[] = "__HALT_COMPILER();";
25352535

@@ -2557,29 +2557,31 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
25572557
if (error) {
25582558
spprintf(error, 0, "internal error: attempt to flush cached zip-based phar \"%s\"", phar->fname);
25592559
}
2560-
return EOF;
2560+
return;
25612561
}
25622562

25632563
if (error) {
25642564
*error = NULL;
25652565
}
25662566

25672567
if (!zend_hash_num_elements(&phar->manifest) && !user_stub) {
2568-
return EOF;
2568+
return;
25692569
}
25702570

25712571
zend_hash_clean(&phar->virtual_dirs);
25722572

25732573
if (phar->is_zip) {
2574-
return phar_zip_flush(phar, user_stub, is_default_stub, error);
2574+
phar_zip_flush(phar, user_stub, is_default_stub, error);
2575+
return;
25752576
}
25762577

25772578
if (phar->is_tar) {
2578-
return phar_tar_flush(phar, user_stub, is_default_stub, error);
2579+
phar_tar_flush(phar, user_stub, is_default_stub, error);
2580+
return;
25792581
}
25802582

25812583
if (PHAR_G(readonly)) {
2582-
return EOF;
2584+
return;
25832585
}
25842586

25852587
if (phar->fp && !phar->is_brandnew) {
@@ -2598,7 +2600,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
25982600
if (must_close_old_file) {
25992601
php_stream_close(oldfile);
26002602
}
2601-
return EOF;
2603+
return;
26022604
}
26032605

26042606
if (user_stub) {
@@ -2612,7 +2614,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
26122614
if (error) {
26132615
spprintf(error, 0, "illegal stub for phar \"%s\" (__HALT_COMPILER(); is missing)", phar->fname);
26142616
}
2615-
return EOF;
2617+
return;
26162618
}
26172619

26182620
size_t len = pos - ZSTR_VAL(user_stub) + strlen(halt_stub);
@@ -2630,7 +2632,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
26302632
if (error) {
26312633
spprintf(error, 0, "unable to create stub from string in new phar \"%s\"", phar->fname);
26322634
}
2633-
return EOF;
2635+
return;
26342636
}
26352637
phar->halt_offset = len + end_sequence_len;
26362638
} else {
@@ -2660,7 +2662,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
26602662
if (new_stub) {
26612663
zend_string_free(new_stub);
26622664
}
2663-
return EOF;
2665+
return;
26642666
}
26652667
if (new_stub) {
26662668
zend_string_free(new_stub);
@@ -2756,7 +2758,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
27562758
if (error) {
27572759
spprintf(error, 0, "unable to seek to start of file \"%s\" while creating new phar \"%s\"", entry->filename, phar->fname);
27582760
}
2759-
return EOF;
2761+
return;
27602762
}
27612763
newcrc32 = php_crc32_bulk_init();
27622764
php_crc32_stream_bulk_update(&newcrc32, file, entry->uncompressed_filesize);
@@ -2782,7 +2784,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
27822784
spprintf(error, 0, "unable to bzip2 compress file \"%s\" to new phar \"%s\"", entry->filename, phar->fname);
27832785
}
27842786
}
2785-
return EOF;
2787+
return;
27862788
}
27872789

27882790
/* create new file that holds the compressed versions */
@@ -3105,7 +3107,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
31053107
php_stream_close(oldfile);
31063108
}
31073109
php_stream_close(newfile);
3108-
return EOF;
3110+
return;
31093111
}
31103112

31113113
php_stream_write(newfile, digest, digest_len);
@@ -3157,7 +3159,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
31573159
if (error) {
31583160
spprintf(error, 4096, "unable to open new phar \"%s\" for writing", phar->fname);
31593161
}
3160-
return EOF;
3162+
return;
31613163
}
31623164

31633165
if (phar->flags & PHAR_FILE_COMPRESSED_GZ) {
@@ -3173,7 +3175,7 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
31733175
if (error) {
31743176
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);
31753177
}
3176-
return EOF;
3178+
return;
31773179
}
31783180

31793181
php_stream_filter_append(&phar->fp->writefilters, filter);
@@ -3203,10 +3205,9 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
32033205
if (error) {
32043206
spprintf(error, 0, "unable to seek to __HALT_COMPILER(); in new phar \"%s\"", phar->fname);
32053207
}
3206-
return EOF;
32073208
}
32083209

3209-
return EOF;
3210+
return;
32103211

32113212
cleanup:
32123213
if (shared_cfp != NULL) {
@@ -3218,8 +3219,6 @@ int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defau
32183219
entry->header_offset = 0;
32193220
}
32203221
} ZEND_HASH_FOREACH_END();
3221-
3222-
return EOF;
32233222
}
32243223
/* }}} */
32253224

ext/phar/phar_internal.h

+4-4
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-
int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error);
450+
void 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-
int phar_zip_flush(phar_archive_data *archive, zend_string *user_stub, bool is_default_stub, char **error);
455+
void 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-
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);
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);
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

+2-3
Original file line numberDiff line numberDiff line change
@@ -469,17 +469,16 @@ static ssize_t phar_stream_write(php_stream *stream, const char *buf, size_t cou
469469
static int phar_stream_flush(php_stream *stream) /* {{{ */
470470
{
471471
char *error;
472-
int ret;
473472
phar_entry_data *data = (phar_entry_data *) stream->abstract;
474473

475474
if (data->internal_file->is_modified) {
476475
data->internal_file->timestamp = time(0);
477-
ret = phar_flush(data->phar, &error);
476+
phar_flush(data->phar, &error);
478477
if (error) {
479478
php_stream_wrapper_log_error(stream->wrapper, REPORT_ERRORS, "%s", error);
480479
efree(error);
481480
}
482-
return ret;
481+
return EOF;
483482
} else {
484483
return EOF;
485484
}

0 commit comments

Comments
 (0)