X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 34807385AC2E
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1643888086;
	bh=OIzY3KMcaQK87ilol4Mr/5gKNW7eMcVfGk2uJPwUxQY=;
	h=Date:From:To:Subject:References:In-Reply-To:List-Id:
	 List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe:
	 Reply-To:From;
	b=EAA01KBPIE9GiFNXNr/3FWIXnBEkefWcxjAaQkfxI5QkK0cFPhTu3QmerM41TfJvN
	 KhYyd8gyS64p+AcXA8+nW1k+IrhzjSIpd0CyGnWWbjhGhNR8m1IMZBKX93FXmrvtAu
	 ccOLeT95aRlHGd86FnfKVbHj7LhW4dvoUv3Lj9N8=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EEE693858C39
Authentication-Results: sourceware.org;
 dmarc=fail (p=none dis=none) header.from=cygwin.com
Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=cygwin.com
Date: Thu, 3 Feb 2022 12:34:13 +0100
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: Cygwin 3.3.4 - cmd to symlinked path doesn't work
Message-ID: <Yfu9tTJ+BphJtjYJ@calimero.vinschen.de>
Mail-Followup-To: cygwin@cygwin.com
References: <VI1PR04MB41575EBC7E202ACC1249553186269@VI1PR04MB4157.eurprd04.prod.outlook.com>
 <1157721958.20220201154725@yandex.ru>
 <YflE5ljqQxvwdNZA@calimero.vinschen.de>
 <456680172.20220203135631@yandex.ru>
MIME-Version: 1.0
Content-Disposition: inline
In-Reply-To: <456680172.20220203135631@yandex.ru>
X-Provags-ID: V03:K1:FFXUHryqSmbS+dAgJQ1Qc8fQG4lLagJN6IOCc7IYcBfcxKjSx4u
 fZqMwcoFdQgdOetZAuO11bOKDXvtqeKWWQBK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IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_FAIL, SPF_HELO_NONE, TXREP,
 T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4
X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on
 server2.sourceware.org
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
Reply-To: cygwin@cygwin.com
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cygwin-bounces+archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>

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

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
