public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* cygpath and partial normalization of trailing /.
@ 2015-10-05 12:29 Poor Yorick
  2015-10-05 14:21 ` Jan Nijtmans
  2015-10-05 14:35 ` Andrey Repin
  0 siblings, 2 replies; 3+ messages in thread
From: Poor Yorick @ 2015-10-05 12:29 UTC (permalink / raw)
  To: cygwin

Currently, in a sh shell,

    cygpath 'c:\windows'

returns

     /cygdrive/c/windows

and

     cygpath 'c:\windows\.'

returns

    /cygdrive/c/windows/

.  With the -m switch, the same pattern is followed, and in the case of 
a
trailing, \. sequence, the dot is removed but the backslash is retained. 
  This
led to a bug (https://sourceforge.net/p/tkimg/bugs/84/) in a build 
process
where the  autoconf script looked something like this:

    TEA_ADD_INCLUDES([-I\"`\${CYGPATH} \${tkimg_SRC_PATH}`\"])

Because of the trailing backslash in the output of cygpath, the final 
double
quote ended up getting escaped.

Rather than normalizing half of it away and leaving half of it, Wouldn't 
it be
better to either not normalize the trailing slash-dot sequence at all, 
or to
completely normalize it away?  If that which is delimited is removed, it 
would
seem to make sense to removed the delimiter as well.

The case that the incoming pathname already has a trailing delimiter is 
one
that I think is already recognized and differentiated.

-- 
Poor Yorick


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

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

* Re: cygpath and partial normalization of trailing /.
  2015-10-05 12:29 cygpath and partial normalization of trailing / Poor Yorick
@ 2015-10-05 14:21 ` Jan Nijtmans
  2015-10-05 14:35 ` Andrey Repin
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Nijtmans @ 2015-10-05 14:21 UTC (permalink / raw)
  To: cygwin

2015-10-05 14:29 GMT+02:00 Poor Yorick:
> Rather than normalizing half of it away and leaving half of it, Wouldn't it
> be
> better to either not normalize the trailing slash-dot sequence at all, or to
> completely normalize it away?  If that which is delimited is removed, it
> would
> seem to make sense to removed the delimiter as well.

Here is a small test program, which shows that the
function cygwin_conv_path(CCP_POSIX_TO_WIN_A, ....)
does the stripping of the '.' and/or '/'. This function is
used by cygpath to do the actual conversion.

Output of the test program:
  /cygdrive/c/Windows -> C:\Windows
  /cygdrive/c/Windows/ -> C:\Windows     <-- (1)
  /cygdrive/c/Windows/. -> C:\Windows
  /home/foo -> C:\Users\foo
  /home/foo/ -> C:\Users\foo\
  /home/foo/. -> C:\Users\foo\                <-- (2)

It indeed makes sense to:
   - either strip both the '.' and the backslash
   - or keep both of them.
The arrows (<--) mark lines that give inconsistant
results, when the input ends with a separator
and the output doesn't (1), or reverse (2).

Thanks for the bug report. I'm not confident enough in
the Cygwin source code, but I hope someone else
can shine some light on it and give advise.

================ test.c =================
#include <sys/cygwin.h>
#include <stdio.h>

static const char *paths[] = {
    "/cygdrive/c/Windows",
    "/cygdrive/c/Windows/",
    "/cygdrive/c/Windows/.",
    "/home/foo",
    "/home/foo/",
    "/home/foo/.",
   0
};


void main() {
   char buf[320];
   const char **p = paths;

   do {
   cygwin_conv_path(CCP_POSIX_TO_WIN_A, *p, buf, sizeof(buf));
   printf("%s -> %s\n", *p, buf);
   } while (*++p);
}

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

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

* Re: cygpath and partial normalization of trailing /.
  2015-10-05 12:29 cygpath and partial normalization of trailing / Poor Yorick
  2015-10-05 14:21 ` Jan Nijtmans
@ 2015-10-05 14:35 ` Andrey Repin
  1 sibling, 0 replies; 3+ messages in thread
From: Andrey Repin @ 2015-10-05 14:35 UTC (permalink / raw)
  To: Poor Yorick, cygwin

Greetings, Poor Yorick!

> Currently, in a sh shell,

>     cygpath 'c:\windows'

> returns

>      /cygdrive/c/windows

> and

>      cygpath 'c:\windows\.'

> returns

>     /cygdrive/c/windows/

> .  With the -m switch, the same pattern is followed, and in the case of 
> a
> trailing, \. sequence, the dot is removed but the backslash is retained. 
>   This
> led to a bug (https://sourceforge.net/p/tkimg/bugs/84/) in a build 
> process
> where the  autoconf script looked something like this:

>     TEA_ADD_INCLUDES([-I\"`\${CYGPATH} \${tkimg_SRC_PATH}`\"])

cygpath is not a normalization tool. Use readlink, if you need normalized
paths.

> Because of the trailing backslash in the output of cygpath, the final 
> double
> quote ended up getting escaped.

> Rather than normalizing half of it away and leaving half of it, Wouldn't 
> it be
> better to either not normalize the trailing slash-dot sequence at all, 
> or to
> completely normalize it away?  If that which is delimited is removed, it 
> would
> seem to make sense to removed the delimiter as well.

> The case that the incoming pathname already has a trailing delimiter is 
> one
> that I think is already recognized and differentiated.



-- 
With best regards,
Andrey Repin
Monday, October 5, 2015 17:20:20

Sorry for my terrible english...


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

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

end of thread, other threads:[~2015-10-05 14:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-05 12:29 cygpath and partial normalization of trailing / Poor Yorick
2015-10-05 14:21 ` Jan Nijtmans
2015-10-05 14:35 ` Andrey Repin

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 read-only IMAP folder(s) and NNTP newsgroup(s).