VSCode如何确定给定工作空间的工作空间存储文件夹



注意:这篇SO文章提出了一个不同的问题:修改vscode"workspaceStorage"文件夹路径

VSCode为每个工作空间生成一个唯一的ID,然后使用文件夹~/.config/Code/User/workspaceStorage/<ID>来存储该工作空间的设置。

如何从外部脚本中找到此ID?最明显的方法似乎是扫描~/.config/Code/User/workspaceStorage/,直到找到正确的文件夹,但对于有很多工作区的计算机来说,这可能会很慢。

VSCode工作区文件夹的~/.config/Code/User/workspaceStorage/<ID>路径的<ID>部分的描述可在以下源中找到:VSCode/src/vs/platform/resource/note/resourceIdentityServiceImpl.ts

有趣的部分(对于Linux(是:

ctime = fileStat.ino;
// we use the ctime as extra salt to the ID so that we catch the case of a folder getting
// deleted and recreated. in that case we do not want to carry over previous state
return createHash('md5').update(resource.fsPath).update(ctime ? String(ctime) : '').digest('hex');

(注意:实际ctime或更确切地说,以毫秒为单位的出生时间在MacOS和Windows上使用(

在脚本中,您需要获得inode编号(如果不在Linux上,则为ctime(,然后通过md5sum发送路径和该编号。

Linux示例

$ stat -f "%i" /your/workspace/path/here
7501991
$ echo -n /your/workspace/path/here7501991 |md5sum
390bd26c245c78dd693b7c16b7cfe36a

MacOS示例

$ stat -f "%.3FB" /your/workspace/path/here
1684939372.000
$ echo -n /your/workspace/path/here1684939372000 |md5
ac4bb3fec841e74ea183d46ed53c3cf4

由于我还不能发表评论…

";示例Linux";来自@zany的回复包含一个小的拼写错误。应使用选项-c而不是-f调用stat

$ stat -c "%i" /your/workspace/path/here
1275310155

最新更新