Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH] ruby-ng.eclass: Replace unnecessary 'eval ls' with array fnexp
Date: Thu, 23 Feb 2017 19:15:54
Message-Id: 20170223191530.19046-1-mgorny@gentoo.org
1 Replace the unnecessary use of 'eval ls -d ...' with much simpler
2 and safer filename expansion via bash array. The 'eval' was completely
3 unnecessary in the original code; however, the late addition of quoting
4 would have broken it if eval did not implicitly discard the quotes.
5 The 'ls -d' was unnecessary as well since bash performs filename
6 expansion before passing the parameter to 'ls'.
7
8 Furthermore, a check for accidental multiple expansion has been added.
9 A complementary check for failed expansion can not be added since
10 the function is called in src_unpack() as well and the expansion fails
11 then.
12 ---
13 eclass/ruby-ng.eclass | 9 ++++++++-
14 1 file changed, 8 insertions(+), 1 deletion(-)
15
16 diff --git a/eclass/ruby-ng.eclass b/eclass/ruby-ng.eclass
17 index c83778de876a..ca3b42669289 100644
18 --- a/eclass/ruby-ng.eclass
19 +++ b/eclass/ruby-ng.eclass
20 @@ -319,7 +319,14 @@ _ruby_invoke_environment() {
21 ;;
22 esac
23 pushd "${WORKDIR}"/all &>/dev/null || die
24 - sub_S=$(eval ls -d "${sub_S}" 2>/dev/null)
25 + # use an array to trigger filename expansion
26 + # fun fact: this expansion fails in src_unpack() but the original
27 + # code did not have any checks for failed expansion, so we can't
28 + # really add one now without redesigning stuff hard.
29 + sub_S=( ${sub_S} )
30 + if [[ ${#sub_S[@]} -gt 1 ]]; then
31 + die "sub_S did expand to multiple paths: ${sub_S[*]}"
32 + fi
33 popd &>/dev/null || die
34 fi
35
36 --
37 2.11.1