On 01 Jun 2015 02:34, Mike Frysinger wrote: > -source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh > +if [[ -z ${PORTAGE_BIN_PATH} ]] ; then > + PORTAGE_BIN_PATH=$(dirname "$(dirname "$(readlink -f "$0")")") > +fi > +source "${PORTAGE_BIN_PATH}"/isolated-functions.sh
for people who don't want to scan this whole thing, basically every file gets a change like this. two things to note: (1) i did not retain the ${VAR:-def} form because bash evaluates the default value even if it doesn't use it. so when you do something like: VAR=val echo "${VAR:-$(rm -rf /some/path)}" it will first run the `rm` and then expand val for the echo. the form i used thus avoids the runtime overhead of doing dirname/readlink unnecessarily. (2) i avoided the bash string functions like ${VAR%/*} because it splits up into multiple statements and is not as readable imo: PORTAGE_BIN_PATH=$(readlink -f "$0") PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH%/*} PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH%/*} or even worse: PORTAGE_BIN_PATH=$(readlink -f "$0"); PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH%/*}; PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH%/*} or also bad imo as it's still not that readable: p=$(readlink -f "$0"); p=${p%/*}; p=${p%/*} PORTAGE_BIN_PATH=${p} the dirname version might be a bit slower, but i think that's acceptable considering this is the fallback case that should rarely be run (as the env var should normally be set). alternative crazy ideas: (a) just throw an error and exit when PORTAGE_BIN_PATH is not set ... considering the current portage code points to a path where it is no longer installed, maybe that's ok ? the recent changes to make portage install copies for each python version is what broke it i think. (b) add a tool alongside it that can be `eval`-ed, although you'd still need to do something like: if [[ -z ${PORTAGE_BIN_PATH} ]] ; then eval $("$(dirname "$(readlink -f "$0")")/some-tool") fi and i don't think that's an improvement relative to my patch (deal with quoting bs and such). (c) convert most things to python and use relative module imports to get at the bootstrap module. then that one would hold all the logic. (d) some other alternative ? -mike
signature.asc
Description: Digital signature