GNU bug report logs - #10472
`realpath --relative-to=<path> /` outputs inconsistent trailing slash

Previous Next

Package: coreutils;

Reported by: Mike Frysinger <vapier <at> gentoo.org>

Date: Tue, 10 Jan 2012 20:17:02 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


Message #67 received at 10472 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Eric Blake <eblake <at> redhat.com>
Cc: 10472 <at> debbugs.gnu.org
Subject: Re: bug#10472: [PATCH] realpath: fix problems with // handling
Date: Mon, 20 Feb 2012 15:21:28 +0000
On 02/04/2012 07:05 PM, Eric Blake wrote:
> On platforms like Cygwin where / and // are distinct, realpath was
> incorrectly collapsing // into /.  http://debbugs.gnu.org/10472.
> 
> * src/realpath.c (path_common_prefix): When // is special, treat /
> and // as having no common match.
> (relpath): Allow for no match even without --relative-base.
> ---
> 
> This is the coreutils side of the patch; for this to work, we also
> have to upgrade to the latest gnulib.
> 
> I'm not pushing this until we decide what to do about testing; I
> guess we've already figured out how to make basename and dirname
> tests conditional on whether they are on Linux or Cygwin (that is,
> whether // and / are the same or different), so I should do something
> similar to that for the realpath test.  But I can at least get a
> code review on realpath.c while figuring out the testing situation.
> 
>  src/realpath.c |    7 +++++++
>  1 files changed, 7 insertions(+), 0 deletions(-)
> 
> diff --git a/src/realpath.c b/src/realpath.c
> index 2dc5e11..f06fbcc 100644
> --- a/src/realpath.c
> +++ b/src/realpath.c
> @@ -131,6 +131,10 @@ path_common_prefix (const char *path1, const char *path2)
>    int i = 0;
>    int ret = 0;
> 
> +  if (DOUBLE_SLASH_IS_DISTINCT_ROOT && *path1 == '/' && *path2 == '/'
> +      && (path1[1] == '/') != (path2[1] == '/'))
> +    return 0;
> +
>    while (*path1 && *path2)
>      {
>        if (*path1 != *path2)
> @@ -168,6 +172,9 @@ relpath (const char *can_fname)
> 
>        /* Skip the prefix common to --relative-to and path.  */
>        int common_index = path_common_prefix (can_relative_to, can_fname);
> +      if (!common_index)
> +        return false;
> +
>        const char *relto_suffix = can_relative_to + common_index;
>        const char *fname_suffix = can_fname + common_index;
> 

is the DOUBLE_SLASH_IS_DISTINCT_ROOT check needed in realpath.c
I.E. if we get a leading // then that define is implicit?

Also doesn't path_prefix() need the same adjustment,
so as to verify --relative-base in the same way?

cheers,
Pádraig.




This bug report was last modified 13 years and 75 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.