|
19 | 19 | #include "ext/standard/file.h" |
20 | 20 | #include "ext/standard/flock_compat.h" |
21 | 21 | #include "ext/standard/php_filestat.h" |
| 22 | +#include "ext/standard/php_string.h" |
22 | 23 | #include <stddef.h> |
23 | 24 | #include <fcntl.h> |
24 | 25 | #ifdef HAVE_SYS_WAIT_H |
@@ -1397,8 +1398,9 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f |
1397 | 1398 | if (ret == -1) { |
1398 | 1399 | #ifndef PHP_WIN32 |
1399 | 1400 | char errstr[256]; |
| 1401 | + int rename_errno = errno; |
1400 | 1402 | # ifdef EXDEV |
1401 | | - if (errno == EXDEV) { |
| 1403 | + if (rename_errno == EXDEV) { |
1402 | 1404 | zend_stat_t sb; |
1403 | 1405 | # if !defined(ZTS) && !defined(TSRM_WIN32) |
1404 | 1406 | /* not sure what to do in ZTS case, umask is not thread-safe */ |
@@ -1458,9 +1460,30 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f |
1458 | 1460 | #ifdef PHP_WIN32 |
1459 | 1461 | php_win32_stream_wrapper_warn_error(wrapper, context, options, PHP_STREAM_EC(RenameFailed), GetLastError()); |
1460 | 1462 | #else |
1461 | | - php_stream_wrapper_warn(wrapper, context, options, |
1462 | | - RenameFailed, |
1463 | | - "%s", php_socket_strerror_s(errno, errstr, sizeof(errstr))); |
| 1463 | + if (rename_errno == ENOENT) { |
| 1464 | + zend_stat_t sb; |
| 1465 | + if (VCWD_STAT(url_from, &sb) != 0) { |
| 1466 | + php_stream_wrapper_warn(wrapper, context, options, RenameFailed, |
| 1467 | + "No such file or directory (source \"%s\")", url_from); |
| 1468 | + } else { |
| 1469 | + size_t to_len = strlen(url_to); |
| 1470 | + char *dir = estrndup(url_to, to_len); |
| 1471 | + php_dirname(dir, to_len); |
| 1472 | + if (dir[0] != '\0' && !(dir[0] == '.' && dir[1] == '\0') |
| 1473 | + && VCWD_STAT(dir, &sb) != 0) { |
| 1474 | + php_stream_wrapper_warn(wrapper, context, options, RenameFailed, |
| 1475 | + "No such file or directory (destination directory \"%s\")", dir); |
| 1476 | + } else { |
| 1477 | + php_stream_wrapper_warn(wrapper, context, options, RenameFailed, |
| 1478 | + "%s", php_socket_strerror_s(rename_errno, errstr, sizeof(errstr))); |
| 1479 | + } |
| 1480 | + efree(dir); |
| 1481 | + } |
| 1482 | + } else { |
| 1483 | + php_stream_wrapper_warn(wrapper, context, options, |
| 1484 | + RenameFailed, |
| 1485 | + "%s", php_socket_strerror_s(rename_errno, errstr, sizeof(errstr))); |
| 1486 | + } |
1464 | 1487 | #endif |
1465 | 1488 | return 0; |
1466 | 1489 | } |
|
0 commit comments