gerardog/gsudo

Issue: gsudo from wsl defaults to Windows directory

59977 opened this issue · 6 comments

59977 commented

Issue Description

When running gsudo from wsl current directory is changed to my Windows folder /mnt/c/Windows.

Expected behavior: Remain in current directory.

Steps to Reproduce

  1. type gsudo and enter in bash shell
  2. Press yes in UAC prompt
  3. The error below is reported and my current directory is changed to /mnt/c/Windows
'\\wsl.localhost\Ubuntu\home\robin\repos'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.

The same happens if running any command, e.g. gsudo pwsh

Screenshots

image

Context:

  • Windows version:
    Win10 21H2 (English)
  • WSL distro:
    Ubuntu 20.04
    • gsudo version:
      gsudo v2.0.4 (Branch.tags-v2.0.4.Sha.506efa024af0cef6e4b0cfec42e0c8c5d0b1472c)

It seems you installed the WSL engine using the microsoft store.
Microsoft store apps use a custom token generated on createprocess. To workaround this custom token, gsudo does the workaround for MSStore, which is to wrap the call in a CMD.
But CMD does not supports UNC Paths...

So, you see this problem if WSL is installed thru the microsoft store. Could you go to start, write 'manage app execution aliases' and turn of WSL alias ? Crossing fingers that you would still be able to use WSL, and gsudo.

Hi @gerardog and @59977. I have the same issue.
I even try to uninstall MSStore WSL and install it from GitHub, but I still have the same issue.

Just follow up the last comment and add more info.

$ wsl.exe --version
WSL version: 1.2.5.0
Kernel version: 5.15.90.1
WSLg version: 1.0.51
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22624.1470
$ gsudo pwd
'\\wsl.localhost\Ubuntu\home\alan'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
/mnt/c/Windows
$ gsudo powershell.exe -c 'Install-Module -Name PSWindowsUpdate -Force;'
'\\wsl.localhost\Ubuntu\home\alan'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.

The tragedy is: Windows CMD not supporting how Windows works...

There is no elegant solution for this. Replacing 'cmd /c' with an alternative, like creating a 'gsudo startprocess' verb forces to implement all cmd logic, which should be out off scope. Stuff that breaks was like running a .bat file or using & to concat several commands...

I eventually did two things:

  • when invoking WSL I added --cd "path" argument to restore the previous....
  • also using CMD's push {path} to map the network drive so I can call CMD if that is still required.

Please test https://github.com/gerardog/gsudo/releases/tag/v2.0.9-FixWslPath and let me know.

Hi @gerardog. Your v2.0.9-FixWslPath worked for me. Many thanks.

So below a test from WSL,

$ gsudo pwd
/home/alan

Fix released in v2.0.9