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

Project Manager: Prohibit duplicating a project into itself

This commit is contained in:
GlitchedCode
2025-10-04 21:38:44 +03:00
parent 06827c91c6
commit c5183d21db

View File

@@ -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() {