linux-info.eclass: get_localversion, do not call 'ls'
authorMichał Górny <mgorny@gentoo.org>
Thu, 8 Mar 2018 15:48:39 +0000 (16:48 +0100)
committerMichał Górny <mgorny@gentoo.org>
Mon, 9 Jul 2018 16:54:45 +0000 (18:54 +0200)
Use bash array to perform a safe filename glob instead of calling 'ls'.
Also, use nullglob to cleanly handle no matches instead of silencing
errors.

eclass/linux-info.eclass

index dd62b26855d2dc9d802662fb34dc450203bba359..0eca5572587469ab60997e792025516343656511 100644 (file)
@@ -390,8 +390,13 @@ kernel_is() {
 get_localversion() {
        local lv_list i x
 
+       local shopt_save=$(shopt -p nullglob)
+       shopt -s nullglob
+       local files=( ${1}/localversion* )
+       ${shopt_save}
+
        # ignore files with ~ in it.
-       for i in $(ls ${1}/localversion* 2>/dev/null); do
+       for i in "${files[@]}"; do
                [[ -n ${i//*~*} ]] && lv_list="${lv_list} ${i}"
        done