Updating base branch errors with "Failed update workspace" when subfolder is used by another process on Windows #3412
Description
Using Version 0.5.389 (Nightly) for Windows
I seem to have run into an issue where updating the base branch deletes any uncommitted files the working directory if it contains a folder that is locked by another process and it's unable to apply the update properly.
I had just created a second branch to push up some changes and upon that PR being merged I clicked "Update" next to workspace. All files outside of the folder that was locked were seemingly deleted/unapplied but once it hit the locked folder it hit an error stopped applying the update and the files it had unapplied were completely lost.
For context I had a subfolder open in VS Code and that seems to be the process that prevented it from removing the folder.
Edit: I got this backwards initially but on further testing it seems it actually deletes any files it has processed up until it hits the locked file.
Steps to reproduce:
- Open a subfolder in an application that will open/lock a file within that directory (e.g. VS Code)
- Click Update next to Workspace to update the base branch
- 💥 Base branch is updated but any changes before it attempts to rm subfolder that were not commited get completely removed
Relevant logs:
2024-04-02T21:25:24.666309Z INFO update_base_branch: gitbutler-app\src\virtual_branches.rs:173: new �[3mproject_id�[0m�[2m=�[0m7f0bb1db-f10e-4505-a165-21a575981ccb
2024-04-02T21:25:24.867828Z INFO update_base_branch: gitbutler-app\src\virtual_branches.rs:173: close time.busy=201ms time.idle=29.7µs �[3mproject_id�[0m�[2m=�[0m7f0bb1db-f10e-4505-a165-21a575981ccb
2024-04-02T21:25:24.969143Z INFO gitbutler-app\src\watcher\dispatchers\file_change.rs:121: project file change project_id=7f0bb1db-f10e-4505-a165-21a575981ccb file_path=devtools-app\src\database.rs
2024-04-02T21:25:24.969278Z INFO gitbutler-app\src\watcher\dispatchers\file_change.rs:121: project file change project_id=7f0bb1db-f10e-4505-a165-21a575981ccb file_path=devtools-app\src\database
2024-04-02T21:25:24.969390Z INFO gitbutler-app\src\watcher\dispatchers\file_change.rs:121: project file change project_id=7f0bb1db-f10e-4505-a165-21a575981ccb file_path=devtools-app\src\id.rs
2024-04-02T21:25:24.969496Z INFO gitbutler-app\src\watcher\dispatchers\file_change.rs:121: project file change project_id=7f0bb1db-f10e-4505-a165-21a575981ccb file_path=devtools-app\src\main.rs
2024-04-02T21:25:24.969613Z INFO gitbutler-app\src\watcher\dispatchers\file_change.rs:121: project file change project_id=7f0bb1db-f10e-4505-a165-21a575981ccb file_path=devtools-app\src\scratches.rs
2024-04-02T21:25:24.969722Z INFO gitbutler-app\src\watcher\dispatchers\file_change.rs:121: project file change project_id=7f0bb1db-f10e-4505-a165-21a575981ccb file_path=devtools-app\src\scratches
2024-04-02T21:25:24.969825Z INFO gitbutler-app\src\watcher\dispatchers\file_change.rs:121: project file change project_id=7f0bb1db-f10e-4505-a165-21a575981ccb file_path=devtools-app\src
2024-04-02T21:25:24.969926Z INFO gitbutler-app\src\watcher\dispatchers\file_change.rs:121: project file change project_id=7f0bb1db-f10e-4505-a165-21a575981ccb file_path=devtools-app\tauri.conf.json
2024-04-02T21:25:24.970004Z INFO gitbutler-app\src\watcher\dispatchers\file_change.rs:121: project file change project_id=7f0bb1db-f10e-4505-a165-21a575981ccb file_path=devtools-app
2024-04-02T21:25:24.970147Z INFO gitbutler-app\src\watcher\dispatchers\file_change.rs:121: project file change project_id=7f0bb1db-f10e-4505-a165-21a575981ccb file_path=devtools-ui\.eslintrc.cjs
2024-04-02T21:25:24.970662Z INFO get_base_branch_data: gitbutler-app\src\virtual_branches.rs:132: new �[3mproject_id�[0m�[2m=�[0m7f0bb1db-f10e-4505-a165-21a575981ccb
2024-04-02T21:25:24.979642Z INFO get_base_branch_data: gitbutler-app\src\virtual_branches.rs:132: close time.busy=8.96ms time.idle=30.3µs �[3mproject_id�[0m�[2m=�[0m7f0bb1db-f10e-4505-a165-21a575981ccb
2024-04-02T21:25:24.981093Z INFO list_remote_branches: gitbutler-app\src\virtual_branches.rs:392: new �[3mproject_id�[0m�[2m=�[0m7f0bb1db-f10e-4505-a165-21a575981ccb
2024-04-02T21:25:24.990908Z INFO list_remote_branches: gitbutler-app\src\virtual_branches.rs:392: close time.busy=9.80ms time.idle=23.7µs �[3mproject_id�[0m�[2m=�[0m7f0bb1db-f10e-4505-a165-21a575981ccb
2024-04-02T21:25:25.094954Z INFO gitbutler-app\src\watcher\dispatchers\file_change.rs:121: project file change project_id=7f0bb1db-f10e-4505-a165-21a575981ccb file_path=devtools-ui
2024-04-02T21:25:25.103261Z ERROR gitbutler-app\src\watcher.rs:208: failed to handle event project_id="7f0bb1db-f10e-4505-a165-21a575981ccb" event=SessionProcessing(7f0bb1db-f10e-4505-a165-21a575981ccb, devtools-ui) error=failed to handle session processing event: "devtools-ui"
Caused by:
0: failed to get file content
1: io error: Access is denied. (os error 5)
2024-04-02T21:25:25.320464Z INFO can_apply_virtual_branch: gitbutler-app\src\virtual_branches.rs:303: new �[3mproject_id�[0m�[2m=�[0m7f0bb1db-f10e-4505-a165-21a575981ccb �[3mbranch_id�[0m�[2m=�[0me010a2f4-4c25-482c-96b5-a6cb6b98e68b
2024-04-02T21:25:25.321456Z INFO can_apply_virtual_branch: gitbutler-app\src\virtual_branches.rs:303: new �[3mproject_id�[0m�[2m=�[0m7f0bb1db-f10e-4505-a165-21a575981ccb �[3mbranch_id�[0m�[2m=�[0me010a2f4-4c25-482c-96b5-a6cb6b98e68b
2024-04-02T21:25:25.327897Z INFO can_apply_virtual_branch: gitbutler-app\src\virtual_branches.rs:303: close time.busy=7.41ms time.idle=27.9µs �[3mproject_id�[0m�[2m=�[0m7f0bb1db-f10e-4505-a165-21a575981ccb �[3mbranch_id�[0m�[2m=�[0me010a2f4-4c25-482c-96b5-a6cb6b98e68b
2024-04-02T21:25:25.328870Z INFO can_apply_virtual_branch: gitbutler-app\src\virtual_branches.rs:303: close time.busy=7.40ms time.idle=22.1µs �[3mproject_id�[0m�[2m=�[0m7f0bb1db-f10e-4505-a165-21a575981ccb �[3mbranch_id�[0m�[2m=�[0me010a2f4-4c25-482c-96b5-a6cb6b98e68b