Răsfoiți Sursa

Fix renaming directories

(cherry picked from commit 0dde3e5b59741630547a3ac6685d1125ab207b91)
kobewi 4 ani în urmă
părinte
comite
f604b32081
2 a modificat fișierele cu 5 adăugiri și 3 ștergeri
  1. 4 2
      core/bind/core_bind.cpp
  2. 1 1
      doc/classes/Directory.xml

+ 4 - 2
core/bind/core_bind.cpp

@@ -2532,15 +2532,17 @@ Error _Directory::copy(String p_from, String p_to) {
 Error _Directory::rename(String p_from, String p_to) {
 
 	ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
+	ERR_FAIL_COND_V_MSG(p_from.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);
 }
 Error _Directory::remove(String p_name) {

+ 1 - 1
doc/classes/Directory.xml

@@ -156,7 +156,7 @@
 			<argument index="0" name="from" type="String" />
 			<argument index="1" name="to" type="String" />
 			<description>
-				Renames (move) the [code]from[/code] file to the [code]to[/code] destination. Both arguments should be paths to files, either relative or absolute. If the destination file exists and is not access-protected, it will be overwritten.
+				Renames (move) the [code]from[/code] file or directory to the [code]to[/code] destination. Both arguments should be paths to files or directories, either relative or absolute. If the destination file or directory exists and is not access-protected, it will be overwritten.
 				Returns one of the [enum Error] code constants ([code]OK[/code] on success).
 			</description>
 		</method>