From c5183d21dbba852a45f818495c76bc9335dbe24e Mon Sep 17 00:00:00 2001 From: GlitchedCode Date: Sat, 4 Oct 2025 21:38:44 +0300 Subject: [PATCH] Project Manager: Prohibit duplicating a project into itself --- editor/project_manager/project_dialog.cpp | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/editor/project_manager/project_dialog.cpp b/editor/project_manager/project_dialog.cpp index 031ab7711fe..0d1cc67a8d4 100644 --- a/editor/project_manager/project_dialog.cpp +++ b/editor/project_manager/project_dialog.cpp @@ -245,6 +245,35 @@ void ProjectDialog::_validate_path() { } } } + + // Check if the target path is a subdirectory of original when duplicating + if (mode == MODE_DUPLICATE) { + String base_path = original_project_path; + String duplicate_target = target_path; + + // Ensure the paths end with a slash + if (!base_path.ends_with("/")) { + base_path += "/"; + } + + if (!duplicate_target.ends_with("/")) { + duplicate_target += "/"; + } + + bool is_subdirectory_or_equal; + + if (d->is_case_sensitive(base_path) || d->is_case_sensitive(duplicate_target)) { + is_subdirectory_or_equal = duplicate_target.begins_with(base_path); + } else { + base_path = base_path.to_lower(); + String target_lower = duplicate_target.to_lower(); + is_subdirectory_or_equal = target_lower.begins_with(base_path); + } + + if (is_subdirectory_or_equal) { + _set_message(TTRC("Cannot duplicate a project into itself."), MESSAGE_ERROR, target_path_input_type); + } + } } String ProjectDialog::_get_target_path() {