diff options
| author | Sara Golemon <pollita@php.net> | 2003-12-12 23:06:42 +0000 |
|---|---|---|
| committer | Sara Golemon <pollita@php.net> | 2003-12-12 23:06:42 +0000 |
| commit | b1f8236b63ae9ee1f3cec490f093cbb8cfff407f (patch) | |
| tree | 7221777bf6d4cc433e5b9fb3503ba6123a12ee94 /main/streams/plain_wrapper.c | |
| parent | 23afd9b166ece8553e5b154d4ea58bfeec037374 (diff) | |
| download | php-git-b1f8236b63ae9ee1f3cec490f093cbb8cfff407f.tar.gz | |
Route rename() via wrapper ops.
Move current rename() code to main/streams/plain_wrapper.c
Implement ftp/rename()
Implement userstreams/rename()
Diffstat (limited to 'main/streams/plain_wrapper.c')
| -rw-r--r-- | main/streams/plain_wrapper.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 008e283367..3e2f67b57f 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -956,6 +956,49 @@ static int php_plain_files_unlink(php_stream_wrapper *wrapper, char *url, int op return 1; } +static int php_plain_files_rename(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC) +{ + char *p; + int ret; + + if (!url_from || !url_to) { + return 0; + } + + if ((p = strstr(url_from, "://")) != NULL) { + url_from = p + 3; + } + + if ((p = strstr(url_to, "://")) != NULL) { + url_to = p + 3; + } + + if (PG(safe_mode) &&(!php_checkuid(url_from, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { + return 0; + } + + if (php_check_open_basedir(url_from TSRMLS_CC)) { + return 0; + } + + ret = VCWD_RENAME(url_from, url_to); + + if (ret == -1) { +#ifdef EXDEV + if (errno == EXDEV) { + if (php_copy_file(url_from, url_to TSRMLS_CC) == SUCCESS) { + VCWD_UNLINK(url_from); + return 1; + } + } +#endif + php_error_docref2(NULL TSRMLS_CC, url_from, url_to, E_WARNING, "%s", strerror(errno)); + return 0; + } + + return 1; +} + static php_stream_wrapper_ops php_plain_files_wrapper_ops = { php_plain_files_stream_opener, NULL, @@ -963,7 +1006,8 @@ static php_stream_wrapper_ops php_plain_files_wrapper_ops = { php_plain_files_url_stater, php_plain_files_dir_opener, "plainfile", - php_plain_files_unlink + php_plain_files_unlink, + php_plain_files_rename }; php_stream_wrapper php_plain_files_wrapper = { |
