1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-12 13:20:55 +00:00

Merge pull request #104022 from precup/create_directory_fix

Defend against directories without trailing slashes
This commit is contained in:
Rémi Verschelde
2025-03-19 12:27:07 +01:00
2 changed files with 8 additions and 2 deletions

View File

@@ -3445,7 +3445,7 @@ Error EditorFileSystem::make_dir_recursive(const String &p_path, const String &p
ERR_FAIL_NULL_V(parent, ERR_FILE_NOT_FOUND); ERR_FAIL_NULL_V(parent, ERR_FILE_NOT_FOUND);
folders_to_sort.insert(parent->get_instance_id()); folders_to_sort.insert(parent->get_instance_id());
const PackedStringArray folders = p_path.trim_prefix(path).trim_suffix("/").split("/"); const PackedStringArray folders = p_path.trim_prefix(path).split("/", false);
for (const String &folder : folders) { for (const String &folder : folders) {
const int current = parent->find_dir_index(folder); const int current = parent->find_dir_index(folder);
if (current > -1) { if (current > -1) {

View File

@@ -2748,7 +2748,13 @@ void FileSystemDock::focus_on_filter() {
} }
void FileSystemDock::create_directory(const String &p_path, const String &p_base_dir) { void FileSystemDock::create_directory(const String &p_path, const String &p_base_dir) {
Error err = EditorFileSystem::get_singleton()->make_dir_recursive(p_path.trim_prefix(p_base_dir), p_base_dir); String trimmed_path = p_path;
if (!p_base_dir.is_empty()) {
// Trims off the joining '/' if the base didn't end with one. If the base did have it
// and there's two slashes, the empty directory is safe to trim off anyways.
trimmed_path = trimmed_path.trim_prefix(p_base_dir).trim_prefix("/");
}
Error err = EditorFileSystem::get_singleton()->make_dir_recursive(trimmed_path, p_base_dir);
if (err != OK) { if (err != OK) {
EditorNode::get_singleton()->show_warning(vformat(TTR("Could not create folder: %s"), error_names[err])); EditorNode::get_singleton()->show_warning(vformat(TTR("Could not create folder: %s"), error_names[err]));
} }