coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 6/6] realpath: let --relative-base work even as child of --re


From: Eric Blake
Subject: Re: [PATCH 6/6] realpath: let --relative-base work even as child of --relative-to
Date: Thu, 15 Mar 2012 13:38:36 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120216 Thunderbird/10.0.1

On 03/14/2012 02:38 PM, Eric Blake wrote:
> Consider: 'realpath --relative-base=$dir --relative-to=. $file'
> It seems reasonable to get a relative name to $file if file is under
> $dir, without regards to where '.' lives, but prior to this patch,
> if '.' is a parent of $dir, the output was absolute.
> 
> * src/realpath.c (relpath): Relax filtering of base.
> * doc/coreutils.texi (realpath invocation): Document this.
> * tests/misc/realpath (out): Adjust test to match.
> * NEWS: Document this.
> ---
>  NEWS                |    4 +++-
>  doc/coreutils.texi  |    6 +++---
>  src/realpath.c      |    8 ++------
>  tests/misc/realpath |    5 ++---
>  4 files changed, 10 insertions(+), 13 deletions(-)

Based on what I've pushed, the changes to realpath.c (if we decide to
take this patch) are now:

diff --git i/src/realpath.c w/src/realpath.c
index 206f800..a1453b0 100644
--- i/src/realpath.c
+++ w/src/realpath.c
@@ -341,21 +341,11 @@ main (int argc, char **argv)
     can_relative_base = can_relative_to;
   else if (relative_base)
     {
-      char *base = realpath_canon (relative_base, can_mode);
-      if (!base)
+      can_relative_base = realpath_canon (relative_base, can_mode);
+      if (!can_relative_base)
         error (EXIT_FAILURE, errno, "%s", quote (relative_base));
-      if (need_dir && !isdir (base))
+      if (need_dir && !isdir (can_relative_base))
         error (EXIT_FAILURE, ENOTDIR, "%s", quote (relative_base));
-      /* --relative-to is a no-op if it does not have --relative-base
-           as a prefix */
-      if (path_prefix (base, can_relative_to))
-        can_relative_base = base;
-      else
-        {
-          free (base);
-          can_relative_base = can_relative_to;
-          can_relative_to = NULL;
-        }
     }

   for (; optind < argc; ++optind)

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]