简体   繁体   English

VSCode 在 WSL2 中以 root 而不是默认用户创建文件

[英]VSCode creates files in WSL2 as root rather than default user

I've been using WSL2 and VSCode for development for a while now with no issues.一段时间以来,我一直在使用 WSL2 和 VSCode 进行开发,没有任何问题。 However, after a recent rebuild and reinstall of Windows I've run into an issue where when a file is created from VSCode through code, then the owner is being set as root rather than the default user.但是,在最近重建并重新安装 Windows 之后,我遇到了一个问题,即当通过代码从 VSCode 创建文件时,所有者被设置为 root 而不是默认用户。 This means I'm unable to edit or save the file as I'm set as the default user and I get a permission error message from VSCode.这意味着我无法编辑或保存文件,因为我被设置为默认用户,并且我从 VSCode 收到了权限错误消息。

Example of file permissions when created by user copying vs created from VSCode用户复制创建的文件权限与从 VSCode 创建的文件权限示例

Example Error Message when trying to save a file created from VSCode尝试保存从 VSCode 创建的文件时的示例错误消息

The files I've been creating have been JSON files which I've created using:我一直在创建的文件是我使用创建的 JSON 文件:

with open("benchmark_results_words.json", "w") as bench:
        json.dump(benchmark, bench)

If I use chmod or chown then it sets the owner to the correct user and I've got no problems after that.如果我使用 chmod 或 chown 那么它将所有者设置为正确的用户,之后我就没有问题了。 I'm trying to figure out how to change the default user that VSCode uses to create files if anyone can help out.如果有人可以提供帮助,我正在尝试弄清楚如何更改 VSCode 用来创建文件的默认用户。

Cheers干杯

Encountered something similar this morning and reached out to some WSL folks.今天早上遇到了类似的事情,并联系了一些 WSL 人。

Filed an issue on VSCode here: https://github.com/microsoft/vscode-remote-release/issues/4170在此处提交了关于 VSCode 的问题: https://github.com/microsoft/vscode-remote-release/issues/4170

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM