@@ -349,14 +349,15 @@ PHPAPI php_stream *_php_stream_fopen_from_pipe(FILE *file, const char *mode STRE
349
349
static ssize_t php_stdiop_write (php_stream * stream , const char * buf , size_t count )
350
350
{
351
351
php_stdio_stream_data * data = (php_stdio_stream_data * )stream -> abstract ;
352
+ ssize_t bytes_written ;
352
353
353
354
assert (data != NULL );
354
355
355
356
if (data -> fd >= 0 ) {
356
357
#ifdef PHP_WIN32
357
- ssize_t bytes_written = _write (data -> fd , buf , PLAIN_WRAP_BUF_SIZE (count ));
358
+ bytes_written = _write (data -> fd , buf , PLAIN_WRAP_BUF_SIZE (count ));
358
359
#else
359
- ssize_t bytes_written = write (data -> fd , buf , count );
360
+ bytes_written = write (data -> fd , buf , count );
360
361
#endif
361
362
if (bytes_written < 0 ) {
362
363
if (PHP_IS_TRANSIENT_ERROR (errno )) {
@@ -370,7 +371,6 @@ static ssize_t php_stdiop_write(php_stream *stream, const char *buf, size_t coun
370
371
php_error_docref (NULL , E_NOTICE , "Write of %zu bytes failed with errno=%d %s" , count , errno , strerror (errno ));
371
372
}
372
373
}
373
- return bytes_written ;
374
374
} else {
375
375
376
376
#ifdef HAVE_FLUSHIO
@@ -380,8 +380,15 @@ static ssize_t php_stdiop_write(php_stream *stream, const char *buf, size_t coun
380
380
data -> last_op = 'w' ;
381
381
#endif
382
382
383
- return (ssize_t ) fwrite (buf , 1 , count , data -> file );
383
+ bytes_written = (ssize_t ) fwrite (buf , 1 , count , data -> file );
384
384
}
385
+
386
+ if (EG (active )) {
387
+ /* clear stat cache as mtime and ctime got changed */
388
+ php_clear_stat_cache (0 , NULL , 0 );
389
+ }
390
+
391
+ return bytes_written ;
385
392
}
386
393
387
394
static ssize_t php_stdiop_read (php_stream * stream , char * buf , size_t count )
@@ -460,6 +467,12 @@ static ssize_t php_stdiop_read(php_stream *stream, char *buf, size_t count)
460
467
461
468
stream -> eof = feof (data -> file );
462
469
}
470
+
471
+ if (EG (active )) {
472
+ /* clear stat cache as atime got changed */
473
+ php_clear_stat_cache (0 , NULL , 0 );
474
+ }
475
+
463
476
return ret ;
464
477
}
465
478
@@ -540,6 +553,10 @@ static int php_stdiop_flush(php_stream *stream)
540
553
* something completely different.
541
554
*/
542
555
if (data -> file ) {
556
+ if (EG (active )) {
557
+ /* clear stat cache as there might be a write so mtime and ctime might have changed */
558
+ php_clear_stat_cache (0 , NULL , 0 );
559
+ }
543
560
return fflush (data -> file );
544
561
}
545
562
return 0 ;
@@ -1159,6 +1176,12 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, zen
1159
1176
ret = php_stream_fopen_from_fd_rel (fd , mode , persistent_id , (open_flags & O_APPEND ) == 0 );
1160
1177
}
1161
1178
1179
+ if (EG (active )) {
1180
+ /* clear stat cache as mtime and ctime might got changed - phar can use stream before
1181
+ * cache is initialized so we need to check if the execution is active. */
1182
+ php_clear_stat_cache (0 , NULL , 0 );
1183
+ }
1184
+
1162
1185
if (ret ) {
1163
1186
if (opened_path ) {
1164
1187
* opened_path = zend_string_init (realpath , strlen (realpath ), 0 );
0 commit comments