Bug #239529 - When doins is called on a symlink to a directory, preserve the
authorZac Medico <zmedico@gentoo.org>
Sun, 5 Oct 2008 16:04:31 +0000 (16:04 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 5 Oct 2008 16:04:31 +0000 (16:04 -0000)
name of the symlink for the installed directory. This involves temporarily
renaming the directory and then renaming it back again.

svn path=/main/trunk/; revision=11629

bin/doins

index 11025250deb85ccdef51cf6a031e3d76f31b61ed..9831fba9501efc3346ac149ea92a12e2344a2707 100755 (executable)
--- a/bin/doins
+++ b/bin/doins
@@ -25,14 +25,17 @@ if [[ ${INSDESTTREE#${D}} != "${INSDESTTREE}" ]]; then
        exit 1
 fi
 
+TMP=$T/.doins_tmp
+mkdir "$TMP"
+
 [[ ! -d ${D}${INSDESTTREE} ]] && dodir "${INSDESTTREE}"
 
 _doins() {
        local mysrc="$1" mydir="$2" cleanup="" rval
 
        if [ -L "$mysrc" ] ; then
-               cp "$mysrc" "${T}"
-               mysrc="${T}/${mysrc##*/}"
+               cp "$mysrc" "$TMP"
+               mysrc="$TMP/${mysrc##*/}"
                cleanup=${mysrc}
        fi
 
@@ -65,6 +68,7 @@ for x in "$@" ; do
                        pushd "${x%/*}" >/dev/null
                fi
                x=${x##*/}
+               x_orig=$x
                # Follow any symlinks recursively until we've got
                # a normal directory for 'find' to traverse.
                while [ -L "$x" ] ; do
@@ -72,13 +76,21 @@ for x in "$@" ; do
                        x=${PWD##*/}
                        pushd "${PWD%/*}" >/dev/null
                done
-               find "$x" -type d -exec dodir "${INSDESTTREE}/{}" \;
-               find "$x" \( -type f -or -type l \) -print0 | _xdoins
+               if [[ $x != $x_orig ]] ; then
+                       mv "$x" "$TMP/$x_orig"
+                       pushd "$TMP" >/dev/null
+               fi
+               find "$x_orig" -type d -exec dodir "${INSDESTTREE}/{}" \;
+               find "$x_orig" \( -type f -or -type l \) -print0 | _xdoins
+               if [[ $x != $x_orig ]] ; then
+                       popd >/dev/null
+                       mv "$TMP/$x_orig" "$x"
+               fi
                while popd >/dev/null 2>&1 ; do true ; done
                ((++success))
        else
                _doins "${x}" && ((++success))
        fi
 done
-
+rm -rf "$TMP"
 [ $success -gt 0 ] && exit 0 || exit 1