WSL icon indicating copy to clipboard operation
WSL copied to clipboard

Absolute path symlinks created in WSL are not accessible in Windows

Open realchrisolin opened this issue 7 years ago • 6 comments

Please fill out the below information:

  • Your Windows build number: (Type ver at a Windows Command Prompt) Windows 10 Pro Build 1809

  • What you're doing and what's happening: (Copy&paste the full set of specific command-line steps necessary to reproduce the behavior, and their output. Include screen shots if that helps demonstrate the problem.)

cd $WIN_HOME
echo 'asdf' > test.txt
ln -s $WIN_HOME/test.txt $WIN_HOME/test-fail.txt
ln -s test.txt test-success.txt
  • What's wrong / what should be happening instead: Trying to open WSL created symlinks using absolute paths in Windows fail consistently. For example, trying to open test-fail.txt outside of WSL will throw an error. The symlink should be resolved as an NTFS junction shortcut/symlink/whatever the proper term is like test-success.txt is. I'm aware that there are already several issues open related to symlink translation woes in WSL, but they didn't seem applicable to this specific issue.

  • Strace of the failing command, if applicable: (If some_command is failing, then run strace -o some_command.strace -f some_command some_args, and link the contents of some_command.strace in a gist here).

  • For WSL launch issues, please collect detailed logs.

realchrisolin avatar Apr 19 '19 16:04 realchrisolin

That looks like by design. Or a feature request ?

  • DrvFs creates NT symlinks when certain conditions are met. [GH 353, 1475, 2602]
    • The link target must be relative, must not cross any mount points or symlinks, and must exist.
    • The user must have SE_CREATE_SYMBOLIC_LINK_PRIVILEGE (this normally requires you to launch wsl.exe elevated), unless Developer Mode is turned on.
    • In all other situations, DrvFs still creates WSL symlinks.

https://docs.microsoft.com/en-us/windows/wsl/release-notes#build-17046

0xbadfca11 avatar Apr 24 '19 06:04 0xbadfca11

I'd posit that this is a discouraging design. I'm not a developer and won't pretend to understand the technical hurdles involved that resulted in this design, so it's hard to justify this as a "bug", but it feels very buggy.

As someone coming from Cygwin, this is very disruptive to my "personal environment" across platforms and doesn't play well with utilities such as https://github.com/TheLocehiliosan/yadm.

realchrisolin avatar Apr 24 '19 11:04 realchrisolin

If you really need that, you can create a wrapper around Windows mklink and then replace the ln by it.

fiedlerp avatar Nov 29 '19 11:11 fiedlerp

i'm having the same issues, some tools we are using create a bunch of symlinks around some folders, and none of them work when accessing them from Windows.

Chagui- avatar Dec 04 '19 16:12 Chagui-

I had thought that this was working at one point and it only worked if you creating the links under paths of /mnt/c/example etc (on windows and canonicalize) and that target was also on the windows path and was canonicalize. Either something has change or didn't alway use absolute paths.

Windows: Using mklink from windows command prompt creates symlinks that are both resolvable on Windows, WSL & WSL2. e.g. C:\temp\example>mklink /D mklink-d c:\temp\example\subdirectory and C:\temp\example>mklink file-mklink-relative subdirectory/file

WSL: Using ln -s from WSL & WSL2 only works if the path is relative - it creates a SYMLINKD However if the path is absolute it creates a JUNCTION that is unreasonable.

This one way functionality can't be by design and is a bug in drvfs or the kernel.

Results from windows command prompt

 Directory of C:\temp\example

08/12/2019  07:53 PM    <DIR>          .
08/12/2019  07:53 PM    <DIR>          ..
08/12/2019  07:31 PM    <JUNCTION>     dir-ln-s [...]
08/12/2019  07:36 PM    <SYMLINKD>     dir-ln-s-relative [subdirectory]
08/12/2019  07:38 PM    <SYMLINK>      file-ln-s [subdirectory\file]
08/12/2019  07:39 PM    <JUNCTION>     file-ln-s-full-path [...]
08/12/2019  07:40 PM    <SYMLINK>      file-mklink-relative [subdirectory\file]
08/12/2019  07:33 PM    <SYMLINKD>     mklink-d [c:\temp\example\subdirectory]
08/12/2019  07:33 PM    <SYMLINK>      mklink-f [c:\temp\example\subdirectory]
08/12/2019  07:31 PM    <DIR>          subdirectory
               5 File(s)              0 bytes
               5 Dir(s)  68,417,069,056 bytes free

Result from WSL (same for WSL2)

/mnt/c/temp/example$ ll
total 0
drwxr-xr-x 1 chris chris 512 Dec  8 19:53 ./
drwxr-xr-x 1 chris chris 512 Dec  8 19:29 ../
lrwxrwxrwx 1 chris chris  32 Dec  8 19:31 dir-ln-s -> /mnt/c/temp/example/subdirectory/
lrwxrwxrwx 1 chris chris  12 Dec  8 19:36 dir-ln-s-relative -> subdirectory/
lrwxrwxrwx 1 chris chris  17 Dec  8 19:38 file-ln-s -> subdirectory/file*
lrwxrwxrwx 1 chris chris  37 Dec  8 19:39 file-ln-s-full-path -> /mnt/c/temp/example/subdirectory/file*
lrwxrwxrwx 1 chris chris  17 Dec  8 19:40 file-mklink-relative -> subdirectory/file*
lrwxrwxrwx 1 chris chris  32 Dec  8 19:33 mklink-d -> /mnt/c/temp/example/subdirectory/
lrwxrwxrwx 1 chris chris  32 Dec  8 19:33 mklink-f -> /mnt/c/temp/example/subdirectory/
drwxr-xr-x 1 chris chris 512 Dec  8 19:31 subdirectory/

devgrok avatar Dec 08 '19 08:12 devgrok

This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.

Thank you!