zsh-workers
 help / color / mirror / code / Atom feed
* Cygwin/MSYS2: Trouble converting relative paths from / using :a or :A
@ 2021-11-12 19:19 agkozak
  2021-11-15  8:44 ` Jun T
  0 siblings, 1 reply; 3+ messages in thread
From: agkozak @ 2021-11-12 19:19 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 406 bytes --]

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

 

The //bin paths are unusable ("No such file or directory").

 

Alex


[-- Attachment #2: Type: text/html, Size: 2696 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Cygwin/MSYS2: Trouble converting relative paths from / using :a or :A
  2021-11-12 19:19 Cygwin/MSYS2: Trouble converting relative paths from / using :a or :A agkozak
@ 2021-11-15  8:44 ` Jun T
  2021-11-17  9:39   ` Jun T
  0 siblings, 1 reply; 3+ messages in thread
From: Jun T @ 2021-11-15  8:44 UTC (permalink / raw)
  To: zsh-workers


> 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;





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Cygwin/MSYS2: Trouble converting relative paths from / using :a or :A
  2021-11-15  8:44 ` Jun T
@ 2021-11-17  9:39   ` Jun T
  0 siblings, 0 replies; 3+ messages in thread
From: Jun T @ 2021-11-17  9:39 UTC (permalink / raw)
  To: zsh-workers


> 2021/11/15 17:44、I wrote:

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

> +	char *here = zgetcwd();
> +	if (here[strlen(here)-1] != '/')
> +	    *junkptr = zhtricat(metafy(here, -1, META_HEAPDUP), "/", *junkptr);
> +	else
> +	    *junkptr = dyncat(here, *junkptr);


Now I think that the return value of zgetcwd() ('here') can end with '/'
only if strlen(here)==1, so we need not metafy 'here'.
Am I correct?

The same code appears at lines 932 of hist.c, and line 4501 of subst.c.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-17  9:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-12 19:19 Cygwin/MSYS2: Trouble converting relative paths from / using :a or :A agkozak
2021-11-15  8:44 ` Jun T
2021-11-17  9:39   ` Jun T

Code repositories for project(s) associated with this 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).