From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11406 invoked by alias); 16 Feb 2015 17:01:18 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34559 Received: (qmail 24859 invoked from network); 16 Feb 2015 17:01:16 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:message-id:date:from :mime-version:to:subject:references:in-reply-to:content-type :content-transfer-encoding; s=smtpout; bh=QSp4TbMqEqyZGnR/6vnLgv MDfVw=; b=poDJMTi4IBG/LzRnsDkwy4xz22XCNJZIlG4YY9b4mi4ovBJYq3yeX1 3Hws46piRHX96v7FHeFZG+WXN/FFAIWI6T/jZVMBJuv0ErHedDkzchTtGY3QSuVN bktOw/4f9M+DhbgAE5cEnu7bPp9yJlsGH8+NjcLz/F9NrNMz6E+jM= X-Sasl-enc: 8EBxSP7AvqyeknAt583MaXqNsTz9UHjoRu3VXZaL4WQg 1424106075 Message-ID: <54E22259.4030000@pobox.com> Date: Mon, 16 Feb 2015 12:01:13 -0500 From: Andrew Janke User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Bart Schaefer , zsh-workers@zsh.org Subject: Re: [BUG] cdpath=(.) breaks cd from / on Cygwin References: <54E0FF31.5040609@pobox.com> <150215145716.ZM11860@torch.brasslantern.com> In-Reply-To: <150215145716.ZM11860@torch.brasslantern.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Looks good to me. When I build with this patch, cd from / on Cygwin works as expected, even with an explicit '.' in $cdpath. Thanks! Andrew On 2/15/15 5:57 PM, Bart Schaefer wrote: > On Feb 15, 3:18pm, Andrew Janke wrote: > } > } In Src/builtin.c, function cd_try_chdir(), lines 1080-1093, there's some > } special case handling for Cygwin and the prefix '/'. But when the prefix > } is '.', it goes down a different code path. It constructs the path > } starting from pwd (which is '/' in this case), and then goes through the > } path normalization which elides '.' segments. But it doesn't have a > } special case check for Cygwin to check for leading '/' again. And I > } think the elision of the first '.' segment will result in a computed > } path starting with '//' but not further escaped. > > That's a pretty close analysis. The real problem is that when pwd is > "/", cd_try_chdir() unnecessarily inserts yet another "/" into the > path before appending a cdpath segment (the "pfix"). So the path has > already become "//./" before normalization even begins. This is a > waste of effort when pwd is "/" on any platform. > > I'm not sure why we bother compiling different branches for cygwin and > otherwise in cd_try_chdir(). Doesn't appear the cygwin variation would > be wrong anywhere else. But I won't mess with that here. > > Try this patch: > > > diff --git a/Src/builtin.c b/Src/builtin.c > index c4e4b94..614b17d 100644 > --- a/Src/builtin.c > +++ b/Src/builtin.c > @@ -1093,9 +1093,11 @@ cd_try_chdir(char *pfix, char *dest, int hard) > } else { > int pfl = strlen(pfix); > dlen = strlen(pwd); > - > + if (dlen == 1 && *pwd == '/') > + dlen = 0; > buf = zalloc(dlen + pfl + strlen(dest) + 3); > - strcpy(buf, pwd); > + if (dlen) > + strcpy(buf, pwd); > buf[dlen] = '/'; > strcpy(buf + dlen + 1, pfix); > buf[dlen + 1 + pfl] = '/';