-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When launching wsl, promote the starting directory to --cd #9223
Conversation
This commit introduces a hack to ConptyConnection for launching WSL. When we detect that WSL is being launched (either "wsl" or "wsl.exe", unqialified or _specifically_ from the current OS's System32 directory), we will promote the startingDirectory specified at launch time into a commandline argument. Why do we want to switch to `--cd`? With the current design of ConptyConnection and WSL, there are some significant limitations: * `startingDirectory` cannot be a WSL path, which forces users to use weird tricks such as setting the starting directory to `\\wsl$\Distro\home\user`. * WSL occasionally fails to launch in time to handle a `\\wsl$` path, which makes us spawn in a strange location (or no location at all). (This fix will only address the second one until a WSL update is released that adds support for `--cd $LINUX_PATH`.) We will not do the promotion if any of the following are true: * the commandline contains `--cd` already * the commandline contains a bare `~` * This was a commonly-used workaround that forced wsl to start in the user's home directory. It conflicts with --cd. * wsl is not spelled properly (`WSL` and `WSL.EXE` are unacceptable) * an absolute path to wsl outside the system32 directory is provided We chose the do this trick in the connection layer, the latest possible point, because it captures the most use cases. We could have done it earlier, but the options were quite limiting. They are: * Generate WSL profiles with startingDirectory set to the home folder * We can't do this because we do not know the user's home folder path. * Generate WSL profiles with `--cd` in them. * This only works for unmodified profiles. * This only works for generated profiles. * Users cannot override the commandline without breaking it. * Users cannot specify a startingDirectory (!) since the one on the commandline wins. * Set a flag on generated WSL profiles to request this trick * This only works for generated profiles. Users who create their own WSL profiles couldn't set startingDirectory and have it work the same. Patching the commandline, hacky though it may be, seemed to be the most compatible option. Eventually, we can even support `wt -d ~ wsl`!
Misspellings found, please review:
To accept these changes, run the following commands from this repository on this branch
✏️ Contributor please read thisBy default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.
If the listed items are:
See the 🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉 🗜️ If you see a bunch of garbage and it relates to a binary-ish string, please add a file path to the File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
|
It sounds unlikely, but what'll happen if I have a different wsl.exe somewhere else in %PATH%? |
My official stance is, “it had better be compatible with wsl, because otherwise it should not be masquerading as wsl.” |
// We want to suppress --cd if they have added a bare ~ to their commandline (they conflict). | ||
break; | ||
} | ||
// Tilde followed by non-space should be okay (like, wsl -d Debian ~/blah.sh) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mildly worried this will bite us slightly but it's still worth trying as it SEEMS ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I'm mildly worried about someone doing some silly thing like wsl -- bash -c vim ~ ; ping whatever.com
(that's made up but you get the point)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good enough. Just get the typo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- this feels dangerous, but hey let's ship it to Preview and see what happens
- We should really really have connection tests with this kind of code getting added. That of course means another project (😢), but at least it's a project that's not dependent on WinUI?
@@ -56,6 +56,72 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation | |||
return S_OK; | |||
} | |||
|
|||
// Function Descrption: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Function Descrption: | |
// Function Description: |
do | ||
{ | ||
if (startingDirectory.size() > 0 && commandLine.size() >= 3) | ||
{ // "wsl" is three characters; this is a safe bet. no point in doing it if there's no starting directory though! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ // "wsl" is three characters; this is a safe bet. no point in doing it if there's no starting directory though! | |
{ | |
// "wsl" is three characters; this is a safe bet. no point in doing it if there's no starting directory though! |
// We want to suppress --cd if they have added a bare ~ to their commandline (they conflict). | ||
break; | ||
} | ||
// Tilde followed by non-space should be okay (like, wsl -d Debian ~/blah.sh) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I'm mildly worried about someone doing some silly thing like wsl -- bash -c vim ~ ; ping whatever.com
(that's made up but you get the point)
Hello @zadjii-msft! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
@DHowett fix the typo and yeet this for the bug bash this afternoon |
@zadjii-msft thx for the reminder. this is building in selfhost-1.9 right now. I'll merge after the bash :) |
Somebody else -- probably the connection directory validator -- is failing this and setting it to %USERPROFILE% lol It gets promoted perfectly. My commandline ends up being |
This is promarily being done to unblock #9223. Prior to this, we'd validate that the user's `startingDirectory` existed here. If it was invalid, we'd gracefully fall back to `%USERPROFILE%`. However, that could cause hangs when combined with WSL. When the WSL filesystem is slow to respond, we'll end up waiting indefinitely for their filesystem driver to respond. This can result in the whole terminal becoming unresponsive. Similarly, with #9223 we want users to be able to specify WSL paths in a profile, but this bit of validation logic totally prevents that from working, because it'll just replace the path with `%USERPROFILE%`. If the path is eventually invalid, we'll display warning in the `ConptyConnection`, when the process fails to launch. Closes #9541 Closes #9114
This is primarily being done to unblock #9223. Prior to this, we'd validate that the user's `startingDirectory` existed here. If it was invalid, we'd gracefully fall back to `%USERPROFILE%`. However, that could cause hangs when combined with WSL. When the WSL filesystem is slow to respond, we'll end up waiting indefinitely for their filesystem driver to respond. This can result in the whole terminal becoming unresponsive. Similarly, with #9223 we want users to be able to specify WSL paths in a profile, but this bit of validation logic totally prevents that from working, because it'll just replace the path with `%USERPROFILE%`. If the path is eventually invalid, we'll display warning in the `ConptyConnection`, when the process fails to launch. Closes #9541 Closes #9114 ![image](https://user-images.githubusercontent.com/18356694/117318675-426d2d00-ae50-11eb-9cc0-0b23c397472c.png)
This is primarily being done to unblock #9223. Prior to this, we'd validate that the user's `startingDirectory` existed here. If it was invalid, we'd gracefully fall back to `%USERPROFILE%`. However, that could cause hangs when combined with WSL. When the WSL filesystem is slow to respond, we'll end up waiting indefinitely for their filesystem driver to respond. This can result in the whole terminal becoming unresponsive. Similarly, with #9223 we want users to be able to specify WSL paths in a profile, but this bit of validation logic totally prevents that from working, because it'll just replace the path with `%USERPROFILE%`. If the path is eventually invalid, we'll display warning in the `ConptyConnection`, when the process fails to launch. Closes #9541 Closes #9114 ![image](https://user-images.githubusercontent.com/18356694/117318675-426d2d00-ae50-11eb-9cc0-0b23c397472c.png) (cherry picked from commit bfc4838)
@DHowett do we want to try this on for 1.11? maybe even behind velocity if we're nervous? |
We are still normalizing these somewhere.
|
… already checked operators
fixes a stray \0
🎉 Handy links: |
this change makes osc 9;9 work with linux paths but breaks |
…2102) This PR does two things, which are best viewed as atomic commits: * e64ae7d: Move the `MangleStartingDirectoryForWSL` to `types/utils`. It doesn't _really_ make sense in `types`, since it's only really being used in a single place in TerminalConnection. However, TerminalConnection doesn't have tests, and types does. So this commit move the function there, and adds tests from #9223 to the types tests. * 42036c5: This actually fixes the bug in #11994. Unfortunately, `wsl --cd` will try to treat paths starting with `//wsl$` as a linux-relative path, when the user almost certainly wanted a windows-relative one. So we'll mangle that back into a path that looks like `\\wsl$\foo\bar`. * [x] closes #11994 * [x] I work here * [x] tests added 🎉
…2102) This PR does two things, which are best viewed as atomic commits: * e64ae7d: Move the `MangleStartingDirectoryForWSL` to `types/utils`. It doesn't _really_ make sense in `types`, since it's only really being used in a single place in TerminalConnection. However, TerminalConnection doesn't have tests, and types does. So this commit move the function there, and adds tests from #9223 to the types tests. * 42036c5: This actually fixes the bug in #11994. Unfortunately, `wsl --cd` will try to treat paths starting with `//wsl$` as a linux-relative path, when the user almost certainly wanted a windows-relative one. So we'll mangle that back into a path that looks like `\\wsl$\foo\bar`. * [x] closes #11994 * [x] I work here * [x] tests added 🎉 (cherry picked from commit b87b809)
This commit introduces a hack to ConptyConnection for launching WSL.
When we detect that WSL is being launched (either "wsl" or "wsl.exe",
unqialified or specifically from the current OS's System32 directory),
we will promote the startingDirectory specified at launch time into a
commandline argument.
Why do we want to switch to
--cd
?With the current design of ConptyConnection and WSL, there are some
significant limitations:
startingDirectory
cannot be a WSL path, which forces users touse weird tricks such as setting the starting directory to
\\wsl$\Distro\home\user
.\\wsl$
path,which makes us spawn in a strange location (or no location at all).
(This fix will only address the second one until a WSL update is
released that adds support for
--cd $LINUX_PATH
.)We will not do the promotion if any of the following are true:
--cd
already~
user's home directory. It conflicts with --cd.
WSL
andWSL.EXE
are unacceptable)We chose the do this trick in the connection layer, the latest possible
point, because it captures the most use cases.
We could have done it earlier, but the options were quite limiting.
They are:
path.
--cd
in them.commandline wins.
WSL profiles couldn't set startingDirectory and have it work the
same.
Patching the commandline, hacky though it may be, seemed to be the most
compatible option. Eventually, we can even support
wt -d ~ wsl
!Validation Steps Performed
Manual validation for the following cases:
We don't have anywhere to put TerminalConnection unit tests :|
Closes #592.