From 3258f1766f5b00703394694176d20d3434054fe6 Mon Sep 17 00:00:00 2001 From: Gina Peter Bnayard Date: Wed, 21 Aug 2024 14:32:05 +0200 Subject: [PATCH] Refactor plain wrapper to handle mkdir itself This effectively inlines the behaviour of php_mkdir_ex() which is a deprecated API from at least 17 years ago, and also fixes some of the return values --- UPGRADING.INTERNALS | 2 ++ ext/standard/file.c | 24 ------------------------ ext/standard/file.h | 2 -- main/streams/plain_wrapper.c | 12 +++++++++++- 4 files changed, 13 insertions(+), 27 deletions(-) diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS index fe4fd258531a5..ca5de1d36d7ad 100644 --- a/UPGRADING.INTERNALS +++ b/UPGRADING.INTERNALS @@ -344,6 +344,8 @@ PHP 8.4 INTERNALS UPGRADE NOTES - The deprecated php_uint32 and php_int32 typedefs have been removed from ext/standard/basic_functions.h. Use the standard uint32_t and int32_t types instead. + - The php_mkdir() and php_mkdir_ex() APIs have been removed, use + php_stream_mkdir() instead. h. ext/session - Added the php_get_session_status() API to get the session status, which is diff --git a/ext/standard/file.c b/ext/standard/file.c index 6b6b43b1fb672..185b3c6ad9225 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -1109,30 +1109,6 @@ PHPAPI PHP_FUNCTION(fseek) } /* }}} */ -/* {{{ php_mkdir */ - -/* DEPRECATED APIs: Use php_stream_mkdir() instead */ -PHPAPI int php_mkdir_ex(const char *dir, zend_long mode, int options) -{ - int ret; - - if (php_check_open_basedir(dir)) { - return -1; - } - - if ((ret = VCWD_MKDIR(dir, (mode_t)mode)) < 0 && (options & REPORT_ERRORS)) { - php_error_docref(NULL, E_WARNING, "%s", strerror(errno)); - } - - return ret; -} - -PHPAPI int php_mkdir(const char *dir, zend_long mode) -{ - return php_mkdir_ex(dir, mode, REPORT_ERRORS); -} -/* }}} */ - /* {{{ Create a directory */ PHP_FUNCTION(mkdir) { diff --git a/ext/standard/file.h b/ext/standard/file.h index ec5f41c52ad36..1792246ba62d3 100644 --- a/ext/standard/file.h +++ b/ext/standard/file.h @@ -41,8 +41,6 @@ PHPAPI int php_set_sock_blocking(php_socket_t socketd, int block); PHPAPI zend_result php_copy_file(const char *src, const char *dest); PHPAPI zend_result php_copy_file_ex(const char *src, const char *dest, int src_flags); PHPAPI zend_result php_copy_file_ctx(const char *src, const char *dest, int src_flags, php_stream_context *ctx); -PHPAPI int php_mkdir_ex(const char *dir, zend_long mode, int options); -PHPAPI int php_mkdir(const char *dir, zend_long mode); PHPAPI void php_fstat(php_stream *stream, zval *return_value); PHPAPI void php_flock_common(php_stream *stream, zend_long operation, uint32_t operation_arg_num, zval *wouldblock, zval *return_value); diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index fb2addb9e6de2..7b0813c3db623 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -1374,7 +1374,17 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i } if (!(options & PHP_STREAM_MKDIR_RECURSIVE)) { - return php_mkdir(dir, mode) == 0; + if (php_check_open_basedir(dir)) { + return 0; + } + + int ret = VCWD_MKDIR(dir, (mode_t)mode); + if (ret < 0 && (options & REPORT_ERRORS)) { + php_error_docref(NULL, E_WARNING, "%s", strerror(errno)); + return 0; + } + + return 1; } char buf[MAXPATHLEN];