By adding a flag to avoid forced fstat for includes. The two fstats
will happen back to back and we don't care about a possible
invalidation.
I was hoping to move this higher up in the stack and make the
ISREG check somewhere in fsizer of fixup, but this doesn't really
seem to be possible. E.g. an FP stdin handle will not be a regular
file but of course needs to be allowed. Additionally custom stream
wrappers may not implement this functionality.
unsigned is_pipe:1; /* don't try and seek */
unsigned cached_fstat:1; /* sb is valid */
unsigned is_pipe_blocking:1; /* allow blocking read() on pipes, currently Windows only */
+ unsigned no_forced_fstat:1; /* Use fstat cache even if forced */
unsigned _reserved:28;
int lock_flag; /* stores the lock state */
static int do_fstat(php_stdio_stream_data *d, int force)
{
- if (!d->cached_fstat || force) {
+ if (!d->cached_fstat || (force && !d->no_forced_fstat)) {
int fd;
int r;
php_stream_close(ret);
return NULL;
}
+
+ /* Make sure the fstat result is reused when we later try to get the
+ * file size. */
+ self->no_forced_fstat = 1;
}
if (options & STREAM_USE_BLOCKING_PIPE) {