Skip to content

Commit 1221293

Browse files
committed
Avoid duplicate fstat() for includes
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.
1 parent b1f17a2 commit 1221293

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

main/streams/plain_wrapper.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ typedef struct {
128128
unsigned is_pipe:1; /* don't try and seek */
129129
unsigned cached_fstat:1; /* sb is valid */
130130
unsigned is_pipe_blocking:1; /* allow blocking read() on pipes, currently Windows only */
131+
unsigned no_forced_fstat:1; /* Use fstat cache even if forced */
131132
unsigned _reserved:28;
132133

133134
int lock_flag; /* stores the lock state */
@@ -152,7 +153,7 @@ typedef struct {
152153

153154
static int do_fstat(php_stdio_stream_data *d, int force)
154155
{
155-
if (!d->cached_fstat || force) {
156+
if (!d->cached_fstat || (force && !d->no_forced_fstat)) {
156157
int fd;
157158
int r;
158159

@@ -1079,6 +1080,10 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, zen
10791080
php_stream_close(ret);
10801081
return NULL;
10811082
}
1083+
1084+
/* Make sure the fstat result is reused when we later try to get the
1085+
* file size. */
1086+
self->no_forced_fstat = 1;
10821087
}
10831088

10841089
if (options & STREAM_USE_BLOCKING_PIPE) {

0 commit comments

Comments
 (0)