zsh-workers
 help / color / mirror / code / Atom feed
From: Jun T <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: Re: Cygwin/MSYS2: Trouble converting relative paths from / using :a or :A
Date: Mon, 15 Nov 2021 17:44:40 +0900	[thread overview]
Message-ID: <BAFD27FA-63B9-4C93-8290-76073F1E1BA8@kba.biglobe.ne.jp> (raw)
In-Reply-To: <01fa01d7d7fa$33567960$9a036c20$@gmail.com>


> 2021/11/13 4:19, agkozak@gmail.com wrote:
> 
> In Cygwin or MSYS2, if I execute
>  
>     cd /
>     foo=bin
>     echo ${foo:a}
>     echo ${foo:A}
>     echo ${foo:P}
>  
> for the :a modifier I get
>  
>     //bin
>  
> for the :A modifier I get a long pause, followed by
>  
>     //bin
>  
> (Is it trying to access a network share?) But for the :P modifier I get the expected
>  
>     /bin

Confirmed.

The relative path "bin" is converted to the absolute path by chabspath() in hist.c.
It first convert "bin" to "$PWD/bin" = "//bin", and then, on systems other
than Cygwin, replace multiple slashes by just a single slash. But on Cygwin,
if the pathname starts with "//" then it is retained, probably to support the so
called UNC: //host/path_to_file.

In the following patch chabspath() is modified so that it does not add an extra '/'
if $PWD = "/". To be more precise, I have just copied the lines 932-936 of hist.c
(in function histsubchar(), for the :P modifier) to chabspath(). So the extra '/'
is not added if the result of zgetcwd() ends with '/'.

# When is it possible that the return value of zgetcwd() ends with '/' but is not
# equal to just "/"?



diff --git a/Src/hist.c b/Src/hist.c
index 6ac581fda..ea727d1f8 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -1861,7 +1861,11 @@ chabspath(char **junkptr)
 	return 1;
 
     if (**junkptr != '/') {
-	*junkptr = zhtricat(metafy(zgetcwd(), -1, META_HEAPDUP), "/", *junkptr);
+	char *here = zgetcwd();
+	if (here[strlen(here)-1] != '/')
+	    *junkptr = zhtricat(metafy(here, -1, META_HEAPDUP), "/", *junkptr);
+	else
+	    *junkptr = dyncat(here, *junkptr);
     }
 
     current = *junkptr;





  reply	other threads:[~2021-11-15  8:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-12 19:19 agkozak
2021-11-15  8:44 ` Jun T [this message]
2021-11-17  9:39   ` Jun T
2021-12-01  4:58     ` Daniel Shahaf
2021-12-05 14:10       ` Jun. T

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=BAFD27FA-63B9-4C93-8290-76073F1E1BA8@kba.biglobe.ne.jp \
    --to=takimoto-j@kba.biglobe.ne.jp \
    --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).