瀏覽代碼

Cancel rename if file does not exist

(cherry picked from commit bb2684f4a71ea6cc150824223a3ec864770a56e2)
Tomasz Chabora 4 年之前
父節點
當前提交
11cbe99ccc
共有 1 個文件被更改,包括 2 次插入0 次删除
  1. 2 0
      core/bind/core_bind.cpp

+ 2 - 0
core/bind/core_bind.cpp

@@ -2501,11 +2501,13 @@ 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(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
 	if (!p_from.is_rel_path()) {
 	if (!p_from.is_rel_path()) {
 		DirAccess *d = DirAccess::create_for_path(p_from);
 		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.");
 		Error err = d->rename(p_from, p_to);
 		Error err = d->rename(p_from, p_to);
 		memdelete(d);
 		memdelete(d);
 		return err;
 		return err;
 	}
 	}
 
 
+	ERR_FAIL_COND_V_MSG(!d->file_exists(p_from), ERR_DOES_NOT_EXIST, "File does not exist.");
 	return d->rename(p_from, p_to);
 	return d->rename(p_from, p_to);
 }
 }
 Error _Directory::remove(String p_name) {
 Error _Directory::remove(String p_name) {