From 30459fe101541698ec704acb224946d73676750e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 8 Jun 2017 15:09:31 +0200 Subject: [PATCH] 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. --- ChangeLog | 7 +++++++ gnulib-tool | 30 +++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7601a1c245..19707985dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2017-06-08 Bruno Haible + + 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. + 2017-06-08 Bruno Haible gnulib-tool: Fix bug in func_ln_s, from 2016-01-15. diff --git a/gnulib-tool b/gnulib-tool index e3364667c9..c78e68b813 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 } -- 2.39.5