summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-08-17 16:06:30 +0200
committerGitHub <noreply@github.com>2021-08-17 16:06:30 +0200
commit913a7a63d5260e32ac992ff419f35992446ead0b (patch)
treebea80ca4ffdb33d612334868c5c6c9cb9ebb569d /core
parent3d673fac50e385e79112ad44ac5887875c5e1459 (diff)
parent0dde3e5b59741630547a3ac6685d1125ab207b91 (diff)
Merge pull request #51793 from KoBeWi/direnam
Fix renaming directories
Diffstat (limited to 'core')
-rw-r--r--core/core_bind.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index e1d595e98c..7a2e6765b8 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -1555,15 +1555,17 @@ Error _Directory::copy(String p_from, String p_to) {
Error _Directory::rename(String p_from, String p_to) {
ERR_FAIL_COND_V_MSG(!is_open(), ERR_UNCONFIGURED, "Directory must be opened before use.");
+ ERR_FAIL_COND_V_MSG(p_from.is_empty() || p_from == "." || p_from == "..", ERR_INVALID_PARAMETER, "Invalid path to rename.");
+
if (!p_from.is_rel_path()) {
DirAccess *d = DirAccess::create_for_path(p_from);
- ERR_FAIL_COND_V_MSG(!d->file_exists(p_from), ERR_DOES_NOT_EXIST, "File does not exist.");
+ ERR_FAIL_COND_V_MSG(!d->file_exists(p_from) && !d->dir_exists(p_from), ERR_DOES_NOT_EXIST, "File or directory does not exist.");
Error err = d->rename(p_from, p_to);
memdelete(d);
return err;
}
- ERR_FAIL_COND_V_MSG(!d->file_exists(p_from), ERR_DOES_NOT_EXIST, "File does not exist.");
+ ERR_FAIL_COND_V_MSG(!d->file_exists(p_from) && !d->dir_exists(p_from), ERR_DOES_NOT_EXIST, "File or directory does not exist.");
return d->rename(p_from, p_to);
}