bug-gnulib
[Top][All Lists]
Advanced

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

gnulib-tool: fix bug in func_symlink_if_changed


From: Bruno Haible
Subject: gnulib-tool: fix bug in func_symlink_if_changed
Date: Thu, 08 Jun 2017 15:11:18 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-79-generic; KDE/5.18.0; x86_64; ; )

In func_symlink_if_changed, the test whether it's already a symlink pointing
to the right location is wrong. Here's the fix:


2017-06-08  Bruno Haible  <address@hidden>

        gnulib-tool: Fix bug in func_symlink_if_changed, from 2006-11-13.
        * gnulib-tool (func_symlink_target): New function, extracted from
        func_symlink.
        (func_symlink, func_symlink_if_changed): Use it.

diff --git a/gnulib-tool b/gnulib-tool
index e336466..c78e68b 100755
--- a/gnulib-tool
+++ b/gnulib-tool
@@ -797,29 +797,40 @@ func_ln_s ()
   }
 }
 
-# func_symlink SRC DEST
-# Like func_ln_s, except that SRC is given relative to the current directory 
(or
-# absolute), not given relative to the directory of DEST.
-func_symlink ()
+# func_symlink_target SRC DEST
+# Determines LINK_TARGET such that "ln -s LINK_TARGET DEST" will create a
+# symbolic link DEST that points to SRC.
+# Output:
+# - link_target     link target, relative to the directory of DEST
+func_symlink_target ()
 {
   case "$1" in
     /* | ?:*)
-      func_ln_s "$1" "$2" ;;
+      link_target="$1" ;;
     *) # SRC is relative.
       case "$2" in
         /* | ?:*)
-          func_ln_s "`pwd`/$1" "$2" ;;
+          link_target="`pwd`/$1" ;;
         *) # DEST is relative too.
           ln_destdir=`echo "$2" | sed -e 's,[^/]*$,,'`
           test -n "$ln_destdir" || ln_destdir="."
           func_relativize "$ln_destdir" "$1"
-          func_ln_s "$reldir" "$2"
+          link_target="$reldir"
           ;;
       esac
       ;;
   esac
 }
 
+# func_symlink SRC DEST
+# Like func_ln_s, except that SRC is given relative to the current directory 
(or
+# absolute), not given relative to the directory of DEST.
+func_symlink ()
+{
+  func_symlink_target "$1" "$2"
+  func_ln_s "$link_target" "$2"
+}
+
 # func_symlink_if_changed SRC DEST
 # Like func_symlink, but avoids munging timestamps if the link is correct.
 # SRC is given relative to the current directory (or absolute).
@@ -828,12 +839,13 @@ func_symlink_if_changed ()
   if test $# -ne 2; then
     echo "usage: func_symlink_if_changed SRC DEST" >&2
   fi
+  func_symlink_target "$1" "$2"
   ln_target=`func_readlink "$2"`
-  if test -h "$2" && test "$1" = "$ln_target"; then
+  if test -h "$2" && test "$link_target" = "$ln_target"; then
     :
   else
     rm -f "$2"
-    func_symlink "$1" "$2"
+    func_ln_s "$link_target" "$2"
   fi
 }
 




reply via email to

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