Skip to content

Refactor plain wrapper to handle mkdir itself #15520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,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.
- The php_strtoupper(), php_string_toupper(), php_strtolower(), and
php_string_tolower() functions has been removed, use zend_str_toupper(),
zend_string_toupper(), zend_str_tolower(), and zend_string_tolower()
Expand Down
24 changes: 0 additions & 24 deletions ext/standard/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 0 additions & 2 deletions ext/standard/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ PHPAPI int php_le_stream_context(void);
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);
Expand Down
12 changes: 11 additions & 1 deletion main/streams/plain_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Loading