public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: Strange behaviour with winsymlinks:native
Date: Thu, 15 Oct 2020 10:37:20 +0200	[thread overview]
Message-ID: <20201015083720.GF26704@calimero.vinschen.de> (raw)
In-Reply-To: <001001d6a23a$3d5ebc70$b81c3550$@cl.cam.ac.uk>

On Oct 14 15:56, David Allsopp via Cygwin wrote:
> I've been doing some working around the problems with Cygwin 3.1.5+ WSL
> junction points in Docker and found three unexpected pieces of behaviour
> with CYGWIN=winsymlinks:native
> 
> In all cases, these work as expected with the default symlink behaviour
> (i.e. CYGWIN unset or without a winsymlinks option).
> 
> 1. Relative paths get unnecessarily resolved
> 
>   mkdir -p foo/bar
>   cd foo/bar
>   touch baz
>   CYGWIN='winsymlinks:native' ln -s ../bar/baz link
>   readlink link
> 
> Result is baz, not ../bar/baz
> 
> 2a. Links in the magic mount directories (/usr/bin and /usr/lib) get extra
> bits added (source is a default mount):
> 
>   cd /usr/lib
>   CYGWIN='winsymlinks:native' ln -s ../share/terminfo terminfo2
>   readlink terminfo2
> 
> Result is ../usr/share/terminfo, which makes it valid from /lib (the "real"
> directory) but not in the virtual one
> 
> 2b. Same but where target is a default mount
> 
>   cd /usr/libexec/p11-kit
>   CYGWIN='winsymlinks:native' ln -s ../../bin/update-ca-trust
> trust-extract-compat2
>   readlink trust-extract-compat2
> 
> Result is ../../../bin/update-ca-trust, again it seems to be computing an
> extra level back to the "real" lib directory
> 
> Are these behaviours expected? I can create those symbolic links manually
> with mklink with no problem, so I'm wondering if it's an outright bug or an
> unexpected consequence of something else.

The difference between mklink and Cygwin creating native symlinks is that
Cygwin performs the additional POSIX -> Windows conversion.  Given that
Cygwin doesn't need native symlinks to do its job, the goal in creating
native symlinks is to make the target path understood by non-Cygwin tools.

This requires a bit of tweaking the path, especially if the path is
given as relative path.  Cygwin tries to keep the path relative, but
it's not foolproof:

1. After converting the POSIX path to Windows paths, the absolute
   symlink and target paths are compared to find the common prefix.  The
   resulting relative path skips all common directories.  Please keep in
   mind that the target path is relative to the symlink you're just
   creating, not relative to CWD.  Just checking the relative path for
   existence using a Windows function is not going to work, except in
   border cases.

2a. and 2b. are basically the same problem:
   The virtual mounts are not valid in Windows.  Cygwin has to resolve
   them using the underlying real path to make them work with native
   Windows tools.

Having said that, there's very likely still room for improvement.
You may want to take a look at the function creating native symlinks:

https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/path.cc;h=4f5f03a761d3839e10c77b4531855233ddf80d88;hb=HEAD#l1740

Feel free to provide patches to improve the situation in certain
scenarios.  But keep in mind that, ultimately, the native symlinks
should be usable by a non-Cygwin Windows tool.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer

      reply	other threads:[~2020-10-15  8:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-14 14:56 David Allsopp
2020-10-15  8:37 ` Corinna Vinschen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201015083720.GF26704@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).