diff --git a/ext/standard/file.c b/ext/standard/file.c index 1ec6a74f3f0b5..67b8e40e9fc6d 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -1660,7 +1660,7 @@ PHPAPI int php_copy_file_ctx(const char *src, const char *dest, int src_flg, php return FAILURE; } - switch (php_stream_stat_path_ex(dest, PHP_STREAM_URL_STAT_QUIET, &dest_s, ctx)) { + switch (php_stream_stat_path_ex(dest, PHP_STREAM_URL_STAT_QUIET | PHP_STREAM_URL_STAT_NOCACHE, &dest_s, ctx)) { case -1: /* non-statable stream */ goto safe_to_copy; diff --git a/ext/standard/tests/file/bug65701.phpt b/ext/standard/tests/file/bug65701.phpt new file mode 100644 index 0000000000000..2b1b5d491df44 --- /dev/null +++ b/ext/standard/tests/file/bug65701.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test for bug #65701: copy() doesn't work when destination filename is created by tempnam() +--CREDITS-- +Boro Sitnikovski +--FILE-- + +--CLEAN-- + +--EXPECT-- +int(11) diff --git a/main/php_streams.h b/main/php_streams.h index c9732b484849a..cfe1b21789c6f 100644 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -373,6 +373,7 @@ END_EXTERN_C() /* Flags for url_stat method in wrapper ops */ #define PHP_STREAM_URL_STAT_LINK 1 #define PHP_STREAM_URL_STAT_QUIET 2 +#define PHP_STREAM_URL_STAT_NOCACHE 4 /* change the blocking mode of stream: value == 1 => blocking, value == 0 => non-blocking. */ #define PHP_STREAM_OPTION_BLOCKING 1 diff --git a/main/streams/streams.c b/main/streams/streams.c index d74f9fd04aa75..13aa7c3548991 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1915,16 +1915,18 @@ PHPAPI int _php_stream_stat_path(const char *path, int flags, php_stream_statbuf const char *path_to_open = path; int ret; - /* Try to hit the cache first */ - if (flags & PHP_STREAM_URL_STAT_LINK) { - if (BG(CurrentLStatFile) && strcmp(path, BG(CurrentLStatFile)) == 0) { - memcpy(ssb, &BG(lssb), sizeof(php_stream_statbuf)); - return 0; - } - } else { - if (BG(CurrentStatFile) && strcmp(path, BG(CurrentStatFile)) == 0) { - memcpy(ssb, &BG(ssb), sizeof(php_stream_statbuf)); - return 0; + if (!(flags & PHP_STREAM_URL_STAT_NOCACHE)) { + /* Try to hit the cache first */ + if (flags & PHP_STREAM_URL_STAT_LINK) { + if (BG(CurrentLStatFile) && strcmp(path, BG(CurrentLStatFile)) == 0) { + memcpy(ssb, &BG(lssb), sizeof(php_stream_statbuf)); + return 0; + } + } else { + if (BG(CurrentStatFile) && strcmp(path, BG(CurrentStatFile)) == 0) { + memcpy(ssb, &BG(ssb), sizeof(php_stream_statbuf)); + return 0; + } } } @@ -1932,19 +1934,21 @@ PHPAPI int _php_stream_stat_path(const char *path, int flags, php_stream_statbuf if (wrapper && wrapper->wops->url_stat) { ret = wrapper->wops->url_stat(wrapper, path_to_open, flags, ssb, context TSRMLS_CC); if (ret == 0) { - /* Drop into cache */ - if (flags & PHP_STREAM_URL_STAT_LINK) { - if (BG(CurrentLStatFile)) { - efree(BG(CurrentLStatFile)); - } - BG(CurrentLStatFile) = estrdup(path); - memcpy(&BG(lssb), ssb, sizeof(php_stream_statbuf)); - } else { - if (BG(CurrentStatFile)) { - efree(BG(CurrentStatFile)); + if (!(flags & PHP_STREAM_URL_STAT_NOCACHE)) { + /* Drop into cache */ + if (flags & PHP_STREAM_URL_STAT_LINK) { + if (BG(CurrentLStatFile)) { + efree(BG(CurrentLStatFile)); + } + BG(CurrentLStatFile) = estrdup(path); + memcpy(&BG(lssb), ssb, sizeof(php_stream_statbuf)); + } else { + if (BG(CurrentStatFile)) { + efree(BG(CurrentStatFile)); + } + BG(CurrentStatFile) = estrdup(path); + memcpy(&BG(ssb), ssb, sizeof(php_stream_statbuf)); } - BG(CurrentStatFile) = estrdup(path); - memcpy(&BG(ssb), ssb, sizeof(php_stream_statbuf)); } } return ret;