public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH] ruby-ng.eclass: Replace unnecessary 'eval ls' with array fnexp
@ 2017-02-23 19:15 Michał Górny
  0 siblings, 0 replies; only message in thread
From: Michał Górny @ 2017-02-23 19:15 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

Replace the unnecessary use of 'eval ls -d ...' with much simpler
and safer filename expansion via bash array. The 'eval' was completely
unnecessary in the original code; however, the late addition of quoting
would have broken it if eval did not implicitly discard the quotes.
The 'ls -d' was unnecessary as well since bash performs filename
expansion before passing the parameter to 'ls'.

Furthermore, a check for accidental multiple expansion has been added.
A complementary check for failed expansion can not be added since
the function is called in src_unpack() as well and the expansion fails
then.
---
 eclass/ruby-ng.eclass | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/eclass/ruby-ng.eclass b/eclass/ruby-ng.eclass
index c83778de876a..ca3b42669289 100644
--- a/eclass/ruby-ng.eclass
+++ b/eclass/ruby-ng.eclass
@@ -319,7 +319,14 @@ _ruby_invoke_environment() {
 				;;
 		esac
 		pushd "${WORKDIR}"/all &>/dev/null || die
-		sub_S=$(eval ls -d "${sub_S}" 2>/dev/null)
+		# use an array to trigger filename expansion
+		# fun fact: this expansion fails in src_unpack() but the original
+		# code did not have any checks for failed expansion, so we can't
+		# really add one now without redesigning stuff hard.
+		sub_S=( ${sub_S} )
+		if [[ ${#sub_S[@]} -gt 1 ]]; then
+			die "sub_S did expand to multiple paths: ${sub_S[*]}"
+		fi
 		popd &>/dev/null || die
 	fi
 
-- 
2.11.1



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2017-02-23 19:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-23 19:15 [gentoo-dev] [PATCH] ruby-ng.eclass: Replace unnecessary 'eval ls' with array fnexp Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox