diff options
author | kobewi <kobewi4e@gmail.com> | 2021-08-17 14:15:51 +0200 |
---|---|---|
committer | kobewi <kobewi4e@gmail.com> | 2021-08-17 14:38:48 +0200 |
commit | 0dde3e5b59741630547a3ac6685d1125ab207b91 (patch) | |
tree | 6bba0f87cf56ac19dadb46846a86fc25a45ebf0c /core | |
parent | 45344c6a025b029ec864a6d9b7a1723fb43f4ab6 (diff) |
Fix renaming directories
Diffstat (limited to 'core')
-rw-r--r-- | core/core_bind.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp index f3f51e57ee..49c22ecc72 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -1560,15 +1560,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); } |