microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.36k stars 28.92k forks source link

Catch-all check for deletion of nameless folder #224138

Open TwoLeggedCat opened 2 months ago

TwoLeggedCat commented 2 months ago

Context

While I was developing over SSH, I lost the connection to the remote server just as I attempted to create a new folder. After reconnection, the file sidebar in Visual Studio Code still had the folder in it, but there was no name next to the icon; just the icon itself. In an effort to remove this "ghost" folder, I right-clicked the entry in the sidebar and chose "Delete Permanently." Just as I hit "Delete" in the confirmation dialog, I realized it was probably not a good idea, and my fears soon came true: the parent of the nameless folder, including ~80% of the project I had open, was deleted. Shortly thereafter, Visual Studio Code became unresponsive and had to be restarted. Luckily, external backups combined with Visual Studio Code's local history feature were enough to restore all but the last few minutes worth of code, but another person in a similar situation might not be quite so lucky.

Theory

Not knowing VSC's internals, I would imagine that, somewhere along the line, VSC concatenated the path to the parent folder (/parent" with the name of the child in an effort to get "/parent/child" and delete the child folder using that path; however, because VSC believed I had selected a folder with no name/an empty string for a name, the result of this concatenation was just "/parent", leading to the recursive deletion of the parent folder.

Suggestion

I understand the bug that led to this occurrence is far too specific and unreproducable for a proper bug report or fix to be possible. However, would it be feasible for a sort of "catch-all" check to be implemented in the UI code that would prevent deletion of a nameless folder brought about by any situation? (I would assume there are more ways this could occur than just the way it did in my instance). I acknowledge that this may be seen as an ideologically poor solution, but, given the catastrophic results it could prevent for what seems like little maintenance, I make this suggestion nonetheless.

System/installation info

Ubuntu 23.10 locally, 24.04 on server Local extensions enabled: None other than the official ones for development over SSH Server extensions: ESLint, Vue - Official

Detailed information
Version: 1.91.1
Commit: f1e16e1e6214d7c44d078b1f0607b2388f29d729
Date: 2024-07-09T22:08:12.169Z
Electron: 29.4.0
ElectronBuildId: 9728852
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Linux x64 6.5.0-44-generic
lramos15 commented 2 months ago

That's an interesting hypothesis. I'll take a look