delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2018/06/12/07:52:39

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:subject:to:references:from:message-id:date
:mime-version:in-reply-to:content-type
:content-transfer-encoding; q=dns; s=default; b=igmWMOsdFmk6Td60
eJk/jQ7iC7Kpzu0/j/II9AamfOCuA3gQMVoS552GqvAv/UjeKa8ACaedmkLVp1Pa
zdwzF7e2SpZhXOMgYP01uoz+wySPz/oO5dF/nx0uJs4JUTd0h79pfFsPhjOMzZjx
56I9n4zCbVBK0LC/LssAkzu65dk=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:subject:to:references:from:message-id:date
:mime-version:in-reply-to:content-type
:content-transfer-encoding; s=default; bh=128kQcBbv6xKfTLd/UsZ9u
9aacs=; b=BM23QB0fzLSBruqRuNoiz0KiI+AbawyVGHZH3pvYECyLaMDZaTsjRf
eYQrnKqgjgtd7i2jCYfeIBK11kdChFi5BAqpaPBu8GFy5r7/MqXo/0oTIzUG3oae
KLazqRnkSeLONAC4OWZ1QtpH6PljiDIERXNzSgeNwCMjR2/oF3Kik=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS autolearn=no version=3.3.2 spammy=ascertain, pleasant
X-HELO: mx1.redhat.com
Subject: Re: Problematic interpretion of paths starting with double slashes
To: cygwin AT cygwin DOT com, sven DOT eden AT gmx DOT de
References: <trinity-82173dac-d842-4a87-8d1f-bed9a958d178-1528793630066 AT 3c-app-gmx-bs08>
From: Eric Blake <eblake AT redhat DOT com>
Message-ID: <dc8418d2-2004-97f0-2d8c-ab438f007eba@redhat.com>
Date: Tue, 12 Jun 2018 06:52:25 -0500
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0
MIME-Version: 1.0
In-Reply-To: <trinity-82173dac-d842-4a87-8d1f-bed9a958d178-1528793630066@3c-app-gmx-bs08>
X-IsSubscribed: yes

On 06/12/2018 03:53 AM, Sven Eden wrote:
> Hello everybody,
>   
> I have a problem with a script that wants to copy a file,
> which has a variable paths build from various variables.
> 
> The first variable is a possible prefix, the second an
> absolute path. If no prefix is needed, the first consists of
> just a slash.

Then fix your script to provide 3 slashes instead of 2.  Only 2 slashes 
has the magic UNC behavior.

That is, if you have a script that is concatenating:

${prefix}/${dir}

where ${prefix} might be empty, you can always rewrite it to be:

${prefix}///${dir}

to get portable behavior that always resolves to the root dir instead of 
trying to dereference remote machines under //.

> 
> This puzzled me, because this works perfectly well on every
> GNU/Linux (plus WSL) system I tried.

Just because your script "works" on a number of systems doesn't mean it 
is portable.

> I am completely aware that §4.13 of the Open Group Base
> Specification Issue 7 (IEEE Std 1003.1-2017) reads:
>      "If a pathname begins with two successive <slash>
>       characters, the first component following the leading
>       <slash> characters may be interpreted in an
>       implementation-defined manner, although more than two
>       leading <slash> characters shall be treated as a single
>       <slash> character."

Yes, that's exactly why your script is not portable.  So even though 
Linux has chosen to make "/" and "//" synonymous, Cygwin has not.

> 
> My question therefore is, whether the behavior can be gotten
> nearer what every other GNU/Linux system does.
> Maybe, if said first component can not be resolved as an smb
> host, try an absolute path instead?

That won't work as nicely as you want, because you will introduce long 
timeouts for every time that Cygwin first has to ascertain that '//tmp' 
does not exist as a remote host.  Maybe we could indeed make '//tmp' 
resolve to '/tmp' if there is no remote '//tmp' available, but the speed 
penalties in doing so will not make it pleasant.  Better is to fix your 
script to not try accessing '//tmp' in the first place.

> I have searched the cygwin mailing list, but all I could find
> was some discussion about UNC paths from 1997.

Yes, we've had special support for // as UNC for a LOOONG time, and 
changing it now would break existing users that expect it to work as 
allowed by POSIX.

> P.S An example of a failing script line is:
> https://github.com/gentoo/gentoo/blob/331976f/eclass/toolchain.eclass#L2136

Well, then report that as a bug to the author of that script.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019