wslutilities / wslu

A collection of utilities for Windows Subsystem for Linux
https://wslutiliti.es/wslu
GNU General Public License v3.0
3.44k stars 155 forks source link

Inconsistent wslpath output for Windows drives that exist and those that don't exist #289

Closed DanKaplanSES closed 1 year ago

DanKaplanSES commented 1 year ago

Windows Version

Windows 10

Windows Build Number

19045.3448

WSL Version

WSL 2

Distro Version

Ubuntu 22.04.2 LTS

WSL Utilities Version

4.1.1-1ubuntu1~22.04

Describe the bug

When I use wslpath on Windows drives, I get different output when the drive exists than I do if the drive doesn't exist.

The Windows paths In these examples, I do have a C drive but don't have an X drive.

Steps to Reproduce

➜  ~ wslpath 'X:\does\not\exist' # `echo $?` reports an error
wslpath: X:\does\not\exist
➜  ~ wslpath -u 'C:\does\not\exist' # `echo $?` does not report an error
/mnt/c/does/not/exist
➜  ~ wslpath 'C:\does\not\exist' 
/mnt/c/does/not/exist
➜  ~ wslpath 'C:\'              
/mnt/c/
➜  ~ wslpath 'X:\'
wslpath: X:\
➜  ~ wslpath 'C:' 
C:
➜  ~ wslpath 'X:' 
X:
➜  ~ wslpath 'C:\Users'
/mnt/c/Users
➜  ~ wslpath 'X:\Users'
wslpath: X:\Users

Expected behavior

I would've expected this to work regardless. Even though I don't have an X drive, I would have expected it to behave as though I did:

➜  ~ wslpath 'X:\does\not\exist' # `echo $?`does not report an error
/mnt/x/does/not/exist
➜  ~ wslpath -u 'C:\does\not\exist' # `echo $?` does not report an error
/mnt/c/does/not/exist

Although that's my expectation, I'm not saying that's the best solution.

I can't imagine any specific scenarios, but depending on the context, it could be useful to run wslpath in "strict" mode or "lax" mode. Strict would error if the path doesn't exist; lax would always output as though the drive and path existed, unless garbage was passed in (e.g., passing in a UNIX path with -u).

Additional context

Technically, this inconsistency occurs if the drive does exist but it's not mounted in WSL.

Unrelated: In my opinion, the error messages should be more explicit. Instead of printing wslpath: X:\ on error, printing ERROR: wslpath: X:\ does not exist as a Windows path would provide more information for the user to troubleshoot their mistake. See the second paragraph of https://github.com/microsoft/WSL/issues/10084#issuecomment-1742239465 for an example of where it could have helped other users.

Code of Conduct

patrick330602 commented 1 year ago

wslpath is a Microsoft binary, but not by me though.

DanKaplanSES commented 1 year ago

wslpath is a Microsoft binary, but not by me though.

Oops.