diff options
Diffstat (limited to 'sys-devel/binutils-config/files/binutils-config-3')
-rwxr-xr-x | sys-devel/binutils-config/files/binutils-config-3 | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/sys-devel/binutils-config/files/binutils-config-3 b/sys-devel/binutils-config/files/binutils-config-3 index 734b2d54e14e..725ae43aa6f3 100755 --- a/sys-devel/binutils-config/files/binutils-config-3 +++ b/sys-devel/binutils-config/files/binutils-config-3 @@ -1,7 +1,7 @@ #!/bin/bash # Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/sys-devel/binutils-config/files/binutils-config-3,v 1.4 2011/08/23 16:09:21 vapier Exp $ +# $Header: /var/cvsroot/gentoo-x86/sys-devel/binutils-config/files/binutils-config-3,v 1.5 2011/08/29 00:56:46 vapier Exp $ # Format of /etc/env.d/binutils/: # config-TARGET: CURRENT=version for TARGET @@ -59,6 +59,26 @@ mv_if_diff() { mv -f "$1" "$2" fi } +atomic_ln() { + local target=$1 linkdir=$2 linkname=$3 linktmp linkfull + linktmp="${linkdir}/.binutils-config.tmp.${linkname}" + linkfull="${linkdir}/${linkname}" + if [[ -d ${linkfull} ]] ; then + # if linking to a dir, we need a little magic to + # make it atomic since `mv -T` is not portable + rm -rf "${linktmp}" + mkdir -p "${linktmp}" + ln -sf "${target}" "${linktmp}/${linkname}" + mv "${linktmp}/${linkname}" "${linktmp}/../" + rmdir "${linktmp}" + else + # `ln` will expand into unlink();symlink(); which + # is not atomic for a small amount of time, but + # `mv` is a single rename() call + ln -sf "${target}" "${linktmp}" + mv "${linktmp}" "${linkfull}" + fi +} setup_env() { unset TARGET VER LIBPATH FAKE_TARGETS @@ -122,14 +142,14 @@ switch_profile() { cd "${ROOT}/${BINPATH}" || exit 1 mkdir -p "${ROOT}/${BINPATH_LINKS}" "${ROOT}/usr/bin" for x in * ; do - ln -sf "${BINPATH}/${x}" "${ROOT}/${BINPATH_LINKS}/${x}" - ln -sf "${BINPATH_LINKS}/${x}" "${ROOT}"/usr/bin/${TARGET}-${x} + atomic_ln "${BINPATH}/${x}" "${ROOT}/${BINPATH_LINKS}" "${x}" + atomic_ln "${BINPATH_LINKS}/${x}" "${ROOT}/usr/bin/" "${TARGET}-${x}" for fake in ${FAKE_TARGETS} ; do [[ -f ${ENV_D}/config-${fake} ]] && continue - ln -sf "${BINPATH_LINKS}/${x}" "${ROOT}"/usr/bin/${fake}-${x} + atomic_ln "${BINPATH_LINKS}/${x}" "${ROOT}/usr/bin" "${fake}-${x}" done if [[ ${TARGET} == ${HOST} ]] ; then - ln -sf ${TARGET}-${x} "${ROOT}"/usr/bin/${x} + atomic_ln "${TARGET}-${x}" "${ROOT}/usr/bin" "${x}" fi done @@ -147,12 +167,12 @@ switch_profile() { rmdir "${ROOT}"/usr/${TARGET}/lib >& /dev/null fi # When upgrading, we need to clean up ldscripts and libs - rm -rf "${dstlib}/ldscripts" "${ROOT}/${BINPATH_LINKS}"/ldscripts mkdir -p "${dstlib}" - ln -sf "${LIBPATH}/ldscripts" "${dstlib}"/ldscripts - find -L "${dstlib}" -type l -exec rm {} + + rm -rf "${ROOT}/${BINPATH_LINKS}"/ldscripts + atomic_ln "${LIBPATH}/ldscripts" "${dstlib}" "ldscripts" + find -L "${dstlib}" -type l -exec rm -v {} + for x in lib* ; do - ln -sf "${LIBPATH}/${x}" "${dstlib}/${x}" + atomic_ln "${LIBPATH}/${x}" "${dstlib}" "${x}" done # @@ -164,7 +184,7 @@ switch_profile() { if [[ ${HOST} == ${TARGET} ]] ; then mkdir -p "${ROOT}/usr/include" for x in * ; do - ln -sf "${INCPATH}/${x}" "${ROOT}/usr/include/${x}" + atomic_ln "${INCPATH}/${x}" "${ROOT}/usr/include" "${x}" done else # Clean out old path -- cannot use '-exec {} +' syntax here @@ -337,14 +357,14 @@ switch_linker() { setup_env || return 1 # does this binutils even support the requested linker ? - if [[ ! -e ${BINPATH}/ld.${ld} ]] ; then + if [[ ! -e ${ROOT}/${BINPATH}/ld.${ld} ]] ; then eerror "${argv0}: sorry, but ${PROFILE} doesn't support the ${ld} linker" exit 1 fi # switch it up ebegin "Setting default linker to ${ld} for ${PROFILE}" - ln -sf ld.${ld} "${BINPATH}"/ld + atomic_ln ld.${ld} "${ROOT}/${BINPATH}" ld eend $? } switch_linker_gold() { switch_linker gold ; } @@ -389,7 +409,7 @@ while [[ $# -gt 0 ]] ; do -h|--help) usage 0 ;; -V|--version) unset Header - cvsver="$Header: /var/cvsroot/gentoo-x86/sys-devel/binutils-config/files/binutils-config-3,v 1.4 2011/08/23 16:09:21 vapier Exp $" + cvsver="$Header: /var/cvsroot/gentoo-x86/sys-devel/binutils-config/files/binutils-config-3,v 1.5 2011/08/29 00:56:46 vapier Exp $" cvsver=${cvsver##*binutils-config-} bver=${cvsver%%,v *} cvsver=${cvsver#* } |