Discussion:
gnulib-tool: fix bug in func_symlink_if_changed
(too old to reply)
Bruno Haible
2017-06-08 13:11:18 UTC
Permalink
Raw Message
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 <***@clisp.org>

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
}

Loading...