Vscode: Cleanup ExtensionContext.workspaceState when a workspace no longer exists

Created on 14 Aug 2017  路  16Comments  路  Source: microsoft/vscode

extensions feature-request

Most helpful comment

How about storing workspaceStorage in the workspace folder instead of the user folder? This way, deleting (or unmounting) the workspace folder will automatically clear the space.
[I had .config/Code/User/workspaceStorage/fbf0af652eb1ee45193948d8b9186f2d/ms-vscode.cpptools taking 18.3GB. Was it still useful? No way to know.]

All 16 comments

@dbaeumer how do we know that a workspace no longer exists? Imho just checking for existence of the path is not enough, there may be many users that work via a remote network drive or even a mounted disk where the connection is not always there. Just going by fs.exists imho can result in bad user experience for these users.

@bpasero the network drive case is an interesting case I never thought about. We could do the following: if it is a UNC path \...\ and it doesn't exist we leave the workspace storage. Same for a drive letter that doesn't exist. We could prompt the user with a list so that he could clean them manually.

@dbaeumer not sure it is that easy, for example VMs can map a folder into my macOS and this folder is not there if the VM is not started. The path itself does not indicate if it is from a VM/remote or not.

@bpasero I am not sure I fully understand that example. How would the storagePath and the workspace folder be layout in that case. Would the storagePath be inside the VM and the workspace folder location mounted into the VM?

@dbaeumer no, the extension storage will always be on the disk where VS Code is installed (e.g. %APPDATA%). I was trying to comment on your statement:

We could do the following: if it is a UNC path ...\ and it doesn't exist we leave the workspace storage. Same for a drive letter that doesn't exist.

On Linux and macOS there are no UNC paths and there are no drive letters. Paths can come and go depending on mounts (e.g. a parallels VM started or stopped), so by just looking at the path you will not be able to find out if the path was deleted or not mounted.

After taking @bpasero input into consideration it is clear that we can't simply delete workspace storage folders. So we need some UI affordance that point to large workspace storage folders and ask the user whether we should clean it up or not

//cc @egamma @kieferrm

I'd appreciate some options to choose clean up strategies, checking if it exists is fine if you don't use network paths (maybe you could detect if it's a network mount when creating the workspace files in the first place?). If it is a network mount, perhaps just cleaning up LRU (Least Recently Used) would be fine?

I just noticed this directory is 35GB on my laptop, with some of the oldest workspaces being nearly a year old and most of them no longer existing (I tend to a roll out a new workspace per feature branch on one project I work on).

cpptools takes 8GB space on my poor C disk.

Could ExtensionContext provide a list of an extension's storagePaths? For my use case I could clean up old data by looking at modtime on extension activation.

@bmewburn this is actually a good idea. However it could still lead to disk space consumption if an extension does nothing.

What approach should one take to even manually clean up ExtensionContext.workspaceState? From what I can see, there is no way to just clear it. It appears that assigning undefined works if you know the key, but there is no way to see what keys exists.

I removed a bunch of java plugins but I can still see these extension leftovers

/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/b7dc2c0ef964078613f7df57fca6c06b/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.runtime
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/b7dc2c0ef964078613f7df57fca6c06b/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.resources
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/b7dc2c0ef964078613f7df57fca6c06b/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.resources/.projects/jdt.ls-java-project/org.eclipse.jdt.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/b7dc2c0ef964078613f7df57fca6c06b/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.m2e.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/b7dc2c0ef964078613f7df57fca6c06b/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.debug.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/b7dc2c0ef964078613f7df57fca6c06b/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.jdt.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/b7dc2c0ef964078613f7df57fca6c06b/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.jdt.launching
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/b7dc2c0ef964078613f7df57fca6c06b/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.jdt.ls.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/b7dc2c0ef964078613f7df57fca6c06b/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.buildship.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/e4e256961bd10914f8744c86f7a9e113/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.runtime
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/e4e256961bd10914f8744c86f7a9e113/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.resources
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/e4e256961bd10914f8744c86f7a9e113/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.resources/.projects/jdt.ls-java-project/org.eclipse.jdt.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/e4e256961bd10914f8744c86f7a9e113/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.m2e.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/e4e256961bd10914f8744c86f7a9e113/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.debug.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/e4e256961bd10914f8744c86f7a9e113/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.jdt.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/e4e256961bd10914f8744c86f7a9e113/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.jdt.launching
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/e4e256961bd10914f8744c86f7a9e113/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.jdt.ls.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/e4e256961bd10914f8744c86f7a9e113/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.buildship.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/ea52923df5070fffee6594dcde143e14/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.runtime
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/ea52923df5070fffee6594dcde143e14/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.resources
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/ea52923df5070fffee6594dcde143e14/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.resources/.projects/jdt.ls-java-project/org.eclipse.jdt.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/ea52923df5070fffee6594dcde143e14/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.m2e.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/ea52923df5070fffee6594dcde143e14/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.debug.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/ea52923df5070fffee6594dcde143e14/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.jdt.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/ea52923df5070fffee6594dcde143e14/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.jdt.launching
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/ea52923df5070fffee6594dcde143e14/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.jdt.ls.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/ea52923df5070fffee6594dcde143e14/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.buildship.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/0a3063ce2c8672fecdfb338f799919e9/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.runtime
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/0a3063ce2c8672fecdfb338f799919e9/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.resources
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/0a3063ce2c8672fecdfb338f799919e9/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.resources/.projects/jdt.ls-java-project/org.eclipse.jdt.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/0a3063ce2c8672fecdfb338f799919e9/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.m2e.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/0a3063ce2c8672fecdfb338f799919e9/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.debug.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/0a3063ce2c8672fecdfb338f799919e9/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.jdt.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/0a3063ce2c8672fecdfb338f799919e9/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.jdt.launching
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/0a3063ce2c8672fecdfb338f799919e9/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.jdt.ls.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/0a3063ce2c8672fecdfb338f799919e9/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.buildship.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/4a03b7b375814febfae0ee6c47f7f545/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.runtime
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/4a03b7b375814febfae0ee6c47f7f545/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.resources
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/4a03b7b375814febfae0ee6c47f7f545/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.resources/.projects/jdt.ls-java-project/org.eclipse.jdt.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/4a03b7b375814febfae0ee6c47f7f545/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.m2e.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/4a03b7b375814febfae0ee6c47f7f545/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.debug.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/4a03b7b375814febfae0ee6c47f7f545/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.jdt.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/4a03b7b375814febfae0ee6c47f7f545/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.jdt.launching
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/4a03b7b375814febfae0ee6c47f7f545/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.jdt.ls.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/4a03b7b375814febfae0ee6c47f7f545/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.buildship.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/7f121031a7ce28a16f4ef61504239bf9/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.runtime
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/7f121031a7ce28a16f4ef61504239bf9/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.resources
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/7f121031a7ce28a16f4ef61504239bf9/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.resources/.projects/jdt.ls-java-project/org.eclipse.jdt.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/7f121031a7ce28a16f4ef61504239bf9/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.m2e.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/7f121031a7ce28a16f4ef61504239bf9/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.debug.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/7f121031a7ce28a16f4ef61504239bf9/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.jdt.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/7f121031a7ce28a16f4ef61504239bf9/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.jdt.launching
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/7f121031a7ce28a16f4ef61504239bf9/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.jdt.ls.core
/Users/gsieran/Library/Application Support/Code/User/workspaceStorage/7f121031a7ce28a16f4ef61504239bf9/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.buildship.core

Can I manually delete these folders? Will that cause any issues with Code?

I may be wrong but #35006 seems like something for extension authors? I'm curious since i already uninstalled the redhat.java plugins if I can manually delete the above without causing any issues in Vs Code. It does not seem that the redhat.java plugins fully cleaned themselves up after uninstall.

How about storing workspaceStorage in the workspace folder instead of the user folder? This way, deleting (or unmounting) the workspace folder will automatically clear the space.
[I had .config/Code/User/workspaceStorage/fbf0af652eb1ee45193948d8b9186f2d/ms-vscode.cpptools taking 18.3GB. Was it still useful? No way to know.]

FYI, under linux (and I suppose would work in OSX too) I'm cleaning up the workspace folders pointing non-existing locations with this inline script:

for i in ~/.config/Code/User/workspaceStorage/*; do if [ -f $i/workspace.json ]; then folder="$(python3 -c "import sys, json; print(json.load(open(sys.argv[1], 'r'))['folder'])" $i/workspace.json 2>/dev/null | sed 's#^file://##;s/+/ /g;s/%\(..\)/\\x\1/g;')"; if [ -n "$folder" ] && [ ! -d "$folder" ]; then echo "Removing workspace $(basename $i) for deleted folder $folder of size $(du -sh $i|cut -f1)"; rm -rfv "$i"; fi; fi; done

You can find it somewhat more readable in this gist.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

VitorLuizC picture VitorLuizC  路  3Comments

villiv picture villiv  路  3Comments

curtw picture curtw  路  3Comments

DovydasNavickas picture DovydasNavickas  路  3Comments

trstringer picture trstringer  路  3Comments