[PTRun][VSCode]Add path existence check for windows+wsl env (#30821)

This commit is contained in:
anderspk 2024-01-17 12:12:14 +01:00 committed by GitHub
parent 3802e91a05
commit 52e919925b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -46,6 +46,11 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
path = path[1..];
}
if (!DoesPathExist(path, workspaceEnv.Value, machineName))
{
return null;
}
var folderName = Path.GetFileName(path);
// Check we haven't returned '' if we have a path like C:\
@ -67,6 +72,24 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
};
}
private bool DoesPathExist(string path, WorkspaceEnvironment workspaceEnv, string machineName)
{
if (workspaceEnv == WorkspaceEnvironment.Local || workspaceEnv == WorkspaceEnvironment.RemoteWSL)
{
var resolvedPath = path;
if (workspaceEnv == WorkspaceEnvironment.RemoteWSL)
{
resolvedPath = $"\\\\wsl$\\{machineName}{resolvedPath.Replace('/', '\\')}";
}
return Directory.Exists(resolvedPath) || File.Exists(resolvedPath);
}
// If the workspace environment is not Local or WSL, assume the path exists
return true;
}
public List<VSCodeWorkspace> Workspaces
{
get