public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: Cygwin 3.3.4 - cmd to symlinked path doesn't work
Date: Thu, 3 Feb 2022 12:34:13 +0100	[thread overview]
Message-ID: <Yfu9tTJ+BphJtjYJ@calimero.vinschen.de> (raw)
In-Reply-To: <456680172.20220203135631@yandex.ru>

On Feb  3 13:56, Andrey Repin wrote:
> Greetings, Corinna Vinschen!
> 
> > On Feb  1 15:47, Andrey Repin wrote:
> >> The interesting part is that the behavior is dependent on sequence of events.
> >> 
> >> `mintty bash -i` in a directory:
> >> 
> >> > $ pwd
> >> > /cygdrive/d/cygwin
> >> > $ cmd
> >> > Microsoft Windows [Version 6.1.7601]
> >> > Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
> >> >
> >> > D:\cygwin> exit
> 
> > Not sure how you did that,
> 
> Did what? Opened an interactive shell in a directory? Navigated into it in a
> different file manager and just used a command.

That's the trick!  I never use this functionality so I wasn't able to
reproduce.

> Opened CMD in an UNC path?
> 
> reg ADD "HKCU\\Software\\Microsoft\\Command Processor" /f /v "DisableUNCCheck" /t REG_DWORD /d 1
> 
> Not even required to re-login.
> Or globally for entire system in HKLM\SOFTWARE\Microsoft\Command Processor

Ahhh, thanks for this registry key setting.  I remembered vaguely that
such a setting exists, but my internet searches failed to uncover it, so
I thought I had imagined things :)

> > Reparse points created with mklink /d are evaluated as symlinks. This
> > reparse point contains an absolute UNC path.  If you cd to this dir in
> > Cygwin, Cygwin evaluates the path and reads the symlink content.  Given
> > the content is an absolute path, the symlink content replaces the
> > entire path.  Internally the CWD is stored twice, once in POSIX, once
> > in Windows syntax.  In short, what happens is this:
> 
> >   pwd           ->      POSIX(/cygdrive/d), WIN(D:)
> >   cd cygwin     ->      
> >     open reparse point "cygwin"
> >     read content == "\\server2\share\folder1"
> >     convert to POSIX == "//server2/share/folder1"
> >     restart path evaluation and check for further symlinks
> >     -> no further symlinks
> >     convert path to Windows == "\\server2\share\folder1"
> >     store both paths as new CWD
> >   pwd           ->      POSIX(//server2/share/folder1),
> >                         WIN(\\server2\share\folder1)
> 
> > So what happens in bash?
> 
> >   $ pwd
> >   /cygdrive/d
> >   $ cd cygwin
> >   $ pwd
> >   /cygdrive/d/cygwin
> >   $ /bin/pwd
> >   //server2/share/folder1
> 
> Except if you don't "cd", it uses whatever is given by the operating system.

Yeah, that's right and explains that this worked for you.  We could run
GetFinalPathNameByHandleW on the CWD if the Cygwin process is the root
of the process tree, but I'm not sure it's worth it.

> I though, by the time everybody had learned to suppress that stupid CMD
> behavior, but here it is once again.

Yeah, guilty as charged.  Thanks again for the registry key!


Corinna

      reply	other threads:[~2022-02-03 11:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-01 11:46 BRISLANE Mark
2022-02-01 12:47 ` Andrey Repin
2022-02-01 14:03   ` [EXTERNAL] " BRISLANE Mark
2022-02-01 14:34   ` Corinna Vinschen
2022-02-03 10:56     ` Andrey Repin
2022-02-03 11:34       ` 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=Yfu9tTJ+BphJtjYJ@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).