zsh-workers
 help / color / mirror / code / Atom feed
From: Andrew Janke <janke@pobox.com>
To: Bart Schaefer <schaefer@brasslantern.com>, zsh-workers@zsh.org
Subject: Re: [BUG] cdpath=(.) breaks cd from / on Cygwin
Date: Mon, 16 Feb 2015 12:01:13 -0500	[thread overview]
Message-ID: <54E22259.4030000@pobox.com> (raw)
In-Reply-To: <150215145716.ZM11860@torch.brasslantern.com>

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] = '/';


      reply	other threads:[~2015-02-16 17:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-15 20:18 Andrew Janke
2015-02-15 22:57 ` Bart Schaefer
2015-02-16 17:01   ` Andrew Janke [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=54E22259.4030000@pobox.com \
    --to=janke@pobox.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).