Skip to content

Commit ddca87b

Browse files
committed
Improve error messages during certain rename conditions:
Error messages improved to point out that the target name chosen is already used for a directory/file if the source is file/directory. Shooting in the dark for Windows here so will see if it compiles.
1 parent fdc0764 commit ddca87b

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

ext/standard/tests/file/rename_variation.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ bool(false)
5555
bool(true)
5656
-- Iteration 2 --
5757

58-
Warning: rename(): Not a directory (%s) in %s on line %d
58+
Warning: rename(): (%s) Not a directory in %s on line %d
5959
bool(false)
6060
bool(false)
6161
bool(false)

ext/standard/tests/file/rename_variation5.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,27 @@ bool(true)
7070

7171
-- Renaming existing link to existing directory name --
7272

73-
Warning: rename(): Is a directory (%s) in %s on line %d
73+
Warning: rename(): (%s) Is a directory in %s on line %d
7474
bool(false)
7575

7676
-- Renaming existing link to existing file name --
7777
bool(true)
7878

7979
-- Renaming existing file to existing directory name --
8080

81-
Warning: rename(): Is a directory (%s) in %s on line %d
81+
Warning: rename(): (%s) Is a directory in %s on line %d
8282
bool(false)
8383

8484
-- Renaming existing file to existing link name --
8585
bool(true)
8686

8787
-- Renaming existing directory to existing file name --
8888

89-
Warning: rename(): Not a directory (%s) in %s on line %d
89+
Warning: rename(): (%s) Not a directory in %s on line %d
9090
bool(false)
9191

9292
-- Renaming existing directory to existing link name --
9393

94-
Warning: rename(): Not a directory (%s) in %s on line %d
94+
Warning: rename(): (%s) Not a directory in %s on line %d
9595
bool(false)
9696
Done

main/streams/plain_wrapper.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,10 +1248,15 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f
12481248
# endif
12491249
#endif
12501250

1251+
/* If error is "Is directory" or "Not a directory" then faulty argument is url_to */
1252+
if (errno == EISDIR || errno == ENOTDIR) {
1253+
php_error_docref(NULL, E_WARNING, "(%s) %s", url_to, strerror(errno));
1254+
} else {
12511255
#ifdef PHP_WIN32
1252-
php_win32_docref2_from_error(GetLastError(), url_from, url_to);
1256+
php_win32_docref2_from_error(GetLastError(), url_from, url_from);
12531257
#else
1254-
php_error_docref(NULL, E_WARNING, "%s (%s)", strerror(errno), url_from);
1258+
php_error_docref(NULL, E_WARNING, "%s (%s)", strerror(errno), url_from);
1259+
}
12551260
#endif
12561261
return 0;
12571262
}

0 commit comments

Comments
 (0)