1 |
On 01 Jun 2015 02:34, Mike Frysinger wrote: |
2 |
> -source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh |
3 |
> +if [[ -z ${PORTAGE_BIN_PATH} ]] ; then |
4 |
> + PORTAGE_BIN_PATH=$(dirname "$(dirname "$(readlink -f "$0")")") |
5 |
> +fi |
6 |
> +source "${PORTAGE_BIN_PATH}"/isolated-functions.sh |
7 |
|
8 |
for people who don't want to scan this whole thing, basically every file gets a |
9 |
change like this. |
10 |
|
11 |
two things to note: |
12 |
|
13 |
(1) i did not retain the ${VAR:-def} form because bash evaluates the default |
14 |
value even if it doesn't use it. so when you do something like: |
15 |
VAR=val |
16 |
echo "${VAR:-$(rm -rf /some/path)}" |
17 |
it will first run the `rm` and then expand val for the echo. the form i used |
18 |
thus avoids the runtime overhead of doing dirname/readlink unnecessarily. |
19 |
|
20 |
(2) i avoided the bash string functions like ${VAR%/*} because it splits up |
21 |
into multiple statements and is not as readable imo: |
22 |
PORTAGE_BIN_PATH=$(readlink -f "$0") |
23 |
PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH%/*} |
24 |
PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH%/*} |
25 |
or even worse: |
26 |
PORTAGE_BIN_PATH=$(readlink -f "$0"); PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH%/*}; PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH%/*} |
27 |
or also bad imo as it's still not that readable: |
28 |
p=$(readlink -f "$0"); p=${p%/*}; p=${p%/*} |
29 |
PORTAGE_BIN_PATH=${p} |
30 |
the dirname version might be a bit slower, but i think that's acceptable |
31 |
considering this is the fallback case that should rarely be run (as the env |
32 |
var should normally be set). |
33 |
|
34 |
alternative crazy ideas: |
35 |
|
36 |
(a) just throw an error and exit when PORTAGE_BIN_PATH is not set ... |
37 |
considering the current portage code points to a path where it is no longer |
38 |
installed, maybe that's ok ? the recent changes to make portage install copies |
39 |
for each python version is what broke it i think. |
40 |
|
41 |
(b) add a tool alongside it that can be `eval`-ed, although you'd still need to |
42 |
do something like: |
43 |
if [[ -z ${PORTAGE_BIN_PATH} ]] ; then |
44 |
eval $("$(dirname "$(readlink -f "$0")")/some-tool") |
45 |
fi |
46 |
and i don't think that's an improvement relative to my patch (deal with quoting |
47 |
bs and such). |
48 |
|
49 |
(c) convert most things to python and use relative module imports to get at the |
50 |
bootstrap module. then that one would hold all the logic. |
51 |
|
52 |
(d) some other alternative ? |
53 |
-mike |