From 157c9c0de811b64326ebf09cc95a59b34cbc0547 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 10 Mar 2012 22:57:43 -0500 Subject: etc-update: handle symlinked files If the config file is symlinked somewhere, then update the target rather then discarding the symlink and replacing it with a real file. URL: http://bugs.gentoo.org/330221 Reported-by: Jack Byer Signed-off-by: Mike Frysinger --- bin/etc-update | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'bin') diff --git a/bin/etc-update b/bin/etc-update index 7b05f1137..644512a96 100755 --- a/bin/etc-update +++ b/bin/etc-update @@ -43,6 +43,24 @@ diff_command() { ${cmd//%file2/$2} } +# Usage: do_mv_ln [options] +# Files have to be the last two args, and has to be +# files so we can handle symlinked target sanely. +do_mv_ln() { + local opts=( ${@:1:$(( $# - 2 ))} ) + local src=${@:$(( $# - 1 )):1} + local dst=${@:$(( $# - 0 )):1} + + if [[ -L ${dst} ]] ; then #330221 + local lfile=$(readlink "${dst}") + [[ ${lfile} == /* ]] || lfile="${dst%/*}/${lfile}" + echo " Target is a symlink; replacing ${lfile}" + dst=${lfile} + fi + + mv "${opts[@]}" "${src}" "${dst}" +} + scan() { echo "Scanning Configuration files..." rm -rf "${TMP}"/files > /dev/null 2>&1 @@ -121,7 +139,7 @@ scan() { if [[ ${MATCHES} == 1 ]] ; then echo "Automerging trivial changes in: ${live_file}" - mv "${cfg_file}" "${live_file}" + do_mv_ln "${cfg_file}" "${live_file}" continue else : $(( ++count )) @@ -404,12 +422,12 @@ do_cfg() { case ${my_input} in 1) echo "Replacing ${ofile} with ${file}" - mv ${mv_opts} ${file} ${ofile} + do_mv_ln ${mv_opts} "${file}" "${ofile}" [ -n "${OVERWRITE_ALL}" ] && my_input=-1 continue ;; 2) echo "Deleting ${file}" - rm ${rm_opts} ${file} + rm ${rm_opts} "${file}" [ -n "${DELETE_ALL}" ] && my_input=-1 continue ;; @@ -474,7 +492,7 @@ do_merge() { chown --reference="${ofile}" "${mfile}" chmod --reference="${ofile}" "${mfile}" fi - mv ${mv_opts} "${mfile}" "${ofile}" + do_mv_ln ${mv_opts} "${mfile}" "${ofile}" rm ${rm_opts} "${file}" return 255 ;; -- cgit v1.2.3-1-g7c22