Repository: godotengine/godot (language: cpp)

Issue:
Crash when duplicating file with Ctrl+Drag and drop
### Tested versions

4.4 dev7, dev6, didn't test earlier

### System information

W10

### Issue description

```
CrashHandlerException: Program crashed
Engine version: Godot Engine v4.4.dev.custom_build (d2ada64a03d2abdb97cafe8f10623db8a2ce1d4c)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[0] std::_Atomic_storage<unsigned __int64,8>::load (C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\atomic:1121)
[1] std::_Atomic_storage<unsigned __int64,8>::load (C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\atomic:1121)
[2] SafeNumeric<unsigned __int64>::conditional_increment (C:\godot_source\core\templates\safe_refcount.h:139)
[3] CowData<char32_t>::_ref (C:\godot_source\core\templates\cowdata.h:502)
[4] String::String (C:\godot_source\core\string\ustring.h:602)
[5] EditorFileSystemDirectory::get_file (C:\godot_source\editor\editor_file_system.cpp:94)
[6] EditorFileSystemDirectory::get_file_path (C:\godot_source\editor\editor_file_system.cpp:126)
[7] EditorFileSystem::_update_scan_actions (C:\godot_source\editor\editor_file_system.cpp:847)
[8] EditorFileSystem::_notification (C:\godot_source\editor\editor_file_system.cpp:1714)
[9] EditorFileSystem::_notificationv (C:\godot_source\editor\editor_file_system.h:145)
[10] Object::notification (C:\godot_source\core\object\object.cpp:883)
[11] SceneTree::_process_group (C:\godot_source\scene\main\scene_tree.cpp:1063)
[12] SceneTree::_process (C:\godot_source\scene\main\scene_tree.cpp:1140)
[13] SceneTree::process (C:\godot_source\scene\main\scene_tree.cpp:580)
[14] Main::iteration (C:\godot_source\main\main.cpp:4493)
[15] ProgressDialog::_update_ui (C:\godot_source\editor\progress_dialog.cpp:135)
[16] ProgressDialog::task_step (C:\godot_source\editor\progress_dialog.cpp:222)
[17] EditorNode::progress_task_step (C:\godot_source\editor\editor_node.cpp:4965)
[18] EditorProgress::step (C:\godot_source\editor\editor_node.cpp:180)
[19] EditorFileSystem::reimport_files (C:\godot_source\editor\editor_file_system.cpp:3118)
[20] EditorFileSystem::_update_scan_actions (C:\godot_source\editor\editor_file_system.cpp:963)
[21] EditorFileSystem::_refresh_filesystem (C:\godot_source\editor\editor_file_system.cpp:3044)
[22] call_with_variant_args_helper<EditorFileSystem> (C:\godot_source\core\variant\binder_common.h:320)
[23] call_with_variant_args<EditorFileSystem> (C:\godot_source\core\variant\binder_common.h:430)
[24] CallableCustomMethodPointer<EditorFileSystem,void>::call (C:\godot_source\core\object\callable_method_pointer.h:109)
[25] Callable::callp (C:\godot_source\core\variant\callable.cpp:58)
[26] Object::emit_signalp (C:\godot_source\core\object\object.cpp:1206)
[27] Object::emit_signal<> (C:\godot_source\core\object\object.h:926)
[28] SceneTree::process (C:\godot_source\scene\main\scene_tree.cpp:574)
[29] Main::iteration (C:\godot_source\main\main.cpp:4493)
[30] OS_Windows::run (C:\godot_source\platform\windows\os_windows.cpp:2062)
[31] widechar_main (C:\godot_source\platform\windows\godot_windows.cpp:181)
[32] _main (C:\godot_source\platform\windows\godot_windows.cpp:206)
[33] main (C:\godot_source\platform\windows\godot_windows.cpp:220)
[34] WinMain (C:\godot_source\platform\windows\godot_windows.cpp:234)
[35] __scrt_common_main_seh (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
[36] <couldn't map PC to fn name>
-- END OF BACKTRACE --
```
Alternatively this error will appear:
```
ERROR: Condition "idx == -1" is true. Continuing.
   at: EditorFileSystem::_update_scan_actions (C:\godot_source\editor/editor_file_system.cpp:899)
ERROR: Attempted to call reimport_files() recursively, this is not allowed.
   at: (C:\godot_source\editor/editor_file_system.cpp:3055)
```

### Steps to reproduce

1. Have any PNG file in your project
2. Drag and drop it to another directory while holding Ctrl
3. Either crash or error

### Minimal reproduction project (MRP)

N/A


Discussion / hints:
Seems to be a regression between 4.4 dev 3 and 4.4 dev 4, bisecting.
Bisected to #97090, @KoBeWi 

![Image](https://github.com/user-attachments/assets/466fdf14-8e8d-4a91-9bfa-c35f552ecbf3)

<br>

Testing in the latest master i receive this errors when doing a duplication

```
ERROR: Condition "!tasks.has(p_task)" is true.
   at: ProgressDialog::end_task (C:\Users\Matheus\Downloads\Godot Source\editor/progress_dialog.cpp:226)
ERROR: Task '_update_scan_actions' already exists.
   at: (C:\Users\Matheus\Downloads\Godot Source\editor/progress_dialog.cpp:173)
```

<br>

And this errors when duplicating and overwriting a file:

```
ERROR: Task '_update_scan_actions' already exists.
   at: (C:\Users\Matheus\Downloads\Godot Source\editor/progress_dialog.cpp:173)
ERROR: Condition "idx == -1" is true. Continuing.
   at: EditorFileSystem::_update_scan_actions (C:\Users\Matheus\Downloads\Godot Source\editor/editor_file_system.cpp:899)
ERROR: Condition "!tasks.has(p_task)" is true.
   at: ProgressDialog::end_task (C:\Users\Matheus\Downloads\Godot Source\editor/progress_dialog.cpp:226)
```

<br>

And this is the backtrace when crash:

```
ERROR: Task '_update_scan_actions' already exists.
   at: (C:\Users\Matheus\Downloads\Godot Source\editor/progress_dialog.cpp:173)
WARNING: Duplicate UID detected for Resource at "res:///470544931_9164046170306256_6536684793976517544_n.jpg".
Old Resource path: "res://470544931_9164046170306256_6536684793976517544_n.jpg". The new file UID was changed automatically.
     at: EditorFileSystem::_update_scan_actions (C:\Users\Matheus\Downloads\Godot Source\editor/editor_file_system.cpp:854)

================================================================
CrashHandlerException: Program crashed
Engine version: Godot Engine v4.4.dev.custom_build (8c6dbff6d35eb613c83f065c408a49ab02fa7f67)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[0] CowData<EditorFileSystemDirectory::FileInfo *>::size (C:\Users\Matheus\Downloads\Godot Source\core\templates\cowdata.h:197)
[1] CowData<EditorFileSystemDirectory::FileInfo *>::size (C:\Users\Matheus\Downloads\Godot Source\core\templates\cowdata.h:197)
[2] Vector<EditorFileSystemDirectory::FileInfo *>::size (C:\Users\Matheus\Downloads\Godot Source\core\templates\vector.h:98)
[3] EditorFileSystemDirectory::find_file_index (C:\Users\Matheus\Downloads\Godot Source\editor\editor_file_system.cpp:55)
[4] EditorFileSystem::_update_scan_actions (C:\Users\Matheus\Downloads\Godot Source\editor\editor_file_system.cpp:898)
[5] EditorFileSystem::_notification (C:\Users\Matheus\Downloads\Godot Source\editor\editor_file_system.cpp:1714)
[6] EditorFileSystem::_notificationv (C:\Users\Matheus\Downloads\Godot Source\editor\editor_file_system.h:145)
[7] Object::notification (C:\Users\Matheus\Downloads\Godot Source\core\object\object.cpp:883)
[8] SceneTree::_process_group (C:\Users\Matheus\Downloads\Godot Source\scene\main\scene_tree.cpp:1063)
[9] SceneTree::_process (C:\Users\Matheus\Downloads\Godot Source\scene\main\scene_tree.cpp:1140)
[10] SceneTree::process (C:\Users\Matheus\Downloads\Godot Source\scene\main\scene_tree.cpp:580)
[11] Main::iteration (C:\Users\Matheus\Downloads\Godot Source\main\main.cpp:4493)
[12] ProgressDialog::_update_ui (C:\Users\Matheus\Downloads\Godot Source\editor\progress_dialog.cpp:135)
[13] ProgressDialog::add_task (C:\Users\Matheus\Downloads\Godot Source\editor\progress_dialog.cpp:200)
[14] EditorNode::progress_add_task (C:\Users\Matheus\Downloads\Godot Source\editor\editor_node.cpp:4956)
[15] EditorProgress::EditorProgress (C:\Users\Matheus\Downloads\Godot Source\editor\editor_node.cpp:190)
[16] EditorFileSystem::_update_scan_actions (C:\Users\Matheus\Downloads\Godot Source\editor\editor_file_system.cpp:800)
[17] EditorFileSystem::_refresh_filesystem (C:\Users\Matheus\Downloads\Godot Source\editor\editor_file_system.cpp:3044)
[18] call_with_variant_args_helper<EditorFileSystem> (C:\Users\Matheus\Downloads\Godot Source\core\variant\binder_common.h:320)
[19] call_with_variant_args<EditorFileSystem> (C:\Users\Matheus\Downloads\Godot Source\core\variant\binder_common.h:430)
[20] CallableCustomMethodPointer<EditorFileSystem,void>::call (C:\Users\Matheus\Downloads\Godot Source\core\object\callable_method_pointer.h:109)
[21] Callable::callp (C:\Users\Matheus\Downloads\Godot Source\core\variant\callable.cpp:58)
[22] Object::emit_signalp (C:\Users\Matheus\Downloads\Godot Source\core\object\object.cpp:1206)
[23] Object::emit_signal<> (C:\Users\Matheus\Downloads\Godot Source\core\object\object.h:926)
[24] SceneTree::process (C:\Users\Matheus\Downloads\Godot Source\scene\main\scene_tree.cpp:574)
[25] Main::iteration (C:\Users\Matheus\Downloads\Godot Source\main\main.cpp:4493)
[26] OS_Windows::run (C:\Users\Matheus\Downloads\Godot Source\platform\windows\os_windows.cpp:2062)
[27] widechar_main (C:\Users\Matheus\Downloads\Godot Source\platform\windows\godot_windows.cpp:181)
[28] _main (C:\Users\Matheus\Downloads\Godot Source\platform\windows\godot_windows.cpp:206)
[29] main (C:\Users\Matheus\Downloads\Godot Source\platform\windows\godot_windows.cpp:220)
[30] WinMain (C:\Users\Matheus\Downloads\Godot Source\platform\windows\godot_windows.cpp:234)
[31] __scrt_common_main_seh (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
[32] <couldn't map PC to fn name>
-- END OF BACKTRACE --
================================================================
```
I did some extra tests today and seems is only file formats that generate the .import file triggers the bug:

Triggers the bug: bmp, jpg, mp3, png, svg, tga, wav, webp

Copy without issues: tscn, dds, gd, gdshader, tres, txt

<br>

When the engine crashes the copy is done with sucess so is something after the copy, also the normal way to copy (Right click -> Move/Duplicate To -> Copy) also triggers this bug in the same way.

Fix patch:
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index b1156f61a3d9..e29d7424c5f3 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -1959,18 +1959,12 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path, bool p_cop
 	}
 
 	if (p_copy) {
-		bool is_copied = false;
 		for (int i = 0; i < to_move.size(); i++) {
 			if (to_move[i].path != new_paths[i]) {
 				_try_duplicate_item(to_move[i], new_paths[i]);
 				select_after_scan = new_paths[i];
-				is_copied = true;
 			}
 		}
-
-		if (is_copied) {
-			_rescan();
-		}
 	} else {
 		// Check groups.
 		for (int i = 0; i < to_move.size(); i++) {


Test patch: