Blame 0035-dracut-functions.sh-simplify-some-for-loops.patch

Harald Hoyer 0840a3
From 32de4eb5d30b728c2fb42f802e5104095a4bc74c Mon Sep 17 00:00:00 2001
Harald Hoyer 0840a3
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 0840a3
Date: Thu, 9 Jul 2015 15:34:47 +0200
Harald Hoyer 0840a3
Subject: [PATCH] dracut-functions.sh: simplify some for loops
Harald Hoyer 0840a3
Harald Hoyer 0840a3
continue early, if condition is not met
Harald Hoyer 0840a3
---
Harald Hoyer 0840a3
 dracut-functions.sh | 73 +++++++++++++++++++++++------------------------------
Harald Hoyer 0840a3
 1 file changed, 32 insertions(+), 41 deletions(-)
Harald Hoyer 0840a3
Harald Hoyer 0840a3
diff --git a/dracut-functions.sh b/dracut-functions.sh
Harald Hoyer 0840a3
index 3a0a5a2..d559903 100755
Harald Hoyer 0840a3
--- a/dracut-functions.sh
Harald Hoyer 0840a3
+++ b/dracut-functions.sh
Harald Hoyer 0840a3
@@ -937,26 +937,23 @@ inst_rules() {
Harald Hoyer 0840a3
     for _rule in "$@"; do
Harald Hoyer 0840a3
         if [ "${_rule#/}" = "$_rule" ]; then
Harald Hoyer 0840a3
             for r in ${udevdir}/rules.d ${hostonly:+/etc/udev/rules.d}; do
Harald Hoyer 0840a3
-                if [[ -e $r/$_rule ]]; then
Harald Hoyer 0840a3
-                    _found="$r/$_rule"
Harald Hoyer 0840a3
-                    inst_rule_programs "$_found"
Harald Hoyer 0840a3
-                    inst_rule_group_owner "$_found"
Harald Hoyer 0840a3
-                    inst_rule_initqueue "$_found"
Harald Hoyer 0840a3
-                    inst_simple "$_found"
Harald Hoyer 0840a3
-                fi
Harald Hoyer 0840a3
+                [[ -e $r/$_rule ]] || continue
Harald Hoyer 0840a3
+                _found="$r/$_rule"
Harald Hoyer 0840a3
+                inst_rule_programs "$_found"
Harald Hoyer 0840a3
+                inst_rule_group_owner "$_found"
Harald Hoyer 0840a3
+                inst_rule_initqueue "$_found"
Harald Hoyer 0840a3
+                inst_simple "$_found"
Harald Hoyer 0840a3
             done
Harald Hoyer 0840a3
         fi
Harald Hoyer 0840a3
         for r in '' $dracutbasedir/rules.d/; do
Harald Hoyer 0840a3
             # skip rules without an absolute path
Harald Hoyer 0840a3
             [[ "${r}$_rule" != /* ]] && continue
Harald Hoyer 0840a3
-
Harald Hoyer 0840a3
-            if [[ -f ${r}$_rule ]]; then
Harald Hoyer 0840a3
-                _found="${r}$_rule"
Harald Hoyer 0840a3
-                inst_rule_programs "$_found"
Harald Hoyer 0840a3
-                inst_rule_group_owner "$_found"
Harald Hoyer 0840a3
-                inst_rule_initqueue "$_found"
Harald Hoyer 0840a3
-                inst_simple "$_found" "$_target/${_found##*/}"
Harald Hoyer 0840a3
-            fi
Harald Hoyer 0840a3
+            [[ -f ${r}$_rule ]] || continue
Harald Hoyer 0840a3
+            _found="${r}$_rule"
Harald Hoyer 0840a3
+            inst_rule_programs "$_found"
Harald Hoyer 0840a3
+            inst_rule_group_owner "$_found"
Harald Hoyer 0840a3
+            inst_rule_initqueue "$_found"
Harald Hoyer 0840a3
+            inst_simple "$_found" "$_target/${_found##*/}"
Harald Hoyer 0840a3
         done
Harald Hoyer 0840a3
         [[ $_found ]] || dinfo "Skipping udev rule: $_rule"
Harald Hoyer 0840a3
     done
Harald Hoyer 0840a3
@@ -968,23 +965,21 @@ inst_rules_wildcard() {
Harald Hoyer 0840a3
     inst_dir "${udevdir}/rules.d"
Harald Hoyer 0840a3
     inst_dir "$_target"
Harald Hoyer 0840a3
     for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1 ; do
Harald Hoyer 0840a3
-        if [[ -e $_rule ]]; then
Harald Hoyer 0840a3
+        [[ -e $_rule ]] || continue
Harald Hoyer 0840a3
+        inst_rule_programs "$_rule"
Harald Hoyer 0840a3
+        inst_rule_group_owner "$_rule"
Harald Hoyer 0840a3
+        inst_rule_initqueue "$_rule"
Harald Hoyer 0840a3
+        inst_simple "$_rule"
Harald Hoyer 0840a3
+        _found=$_rule
Harald Hoyer 0840a3
+    done
Harald Hoyer 0840a3
+    if [[ -n ${hostonly} ]] ; then
Harald Hoyer 0840a3
+        for _rule in ${_target}/$1 ; do
Harald Hoyer 0840a3
+            [[ -f $_rule ]] || continue
Harald Hoyer 0840a3
             inst_rule_programs "$_rule"
Harald Hoyer 0840a3
             inst_rule_group_owner "$_rule"
Harald Hoyer 0840a3
             inst_rule_initqueue "$_rule"
Harald Hoyer 0840a3
             inst_simple "$_rule"
Harald Hoyer 0840a3
             _found=$_rule
Harald Hoyer 0840a3
-        fi
Harald Hoyer 0840a3
-    done
Harald Hoyer 0840a3
-    if [[ -n ${hostonly} ]] ; then
Harald Hoyer 0840a3
-        for _rule in ${_target}/$1 ; do
Harald Hoyer 0840a3
-            if [[ -f $_rule ]]; then
Harald Hoyer 0840a3
-                inst_rule_programs "$_rule"
Harald Hoyer 0840a3
-                inst_rule_group_owner "$_rule"
Harald Hoyer 0840a3
-                inst_rule_initqueue "$_rule"
Harald Hoyer 0840a3
-                inst_simple "$_rule"
Harald Hoyer 0840a3
-                _found=$_rule
Harald Hoyer 0840a3
-            fi
Harald Hoyer 0840a3
         done
Harald Hoyer 0840a3
     fi
Harald Hoyer 0840a3
     [[ $_found ]] || dinfo "Skipping udev rule: $_rule"
Harald Hoyer 0840a3
@@ -1051,10 +1046,9 @@ inst_any() {
Harald Hoyer 0840a3
     [[ $1 = '-d' ]] && to="$2" && shift 2
Harald Hoyer 0840a3
 
Harald Hoyer 0840a3
     for f in "$@"; do
Harald Hoyer 0840a3
-        if [[ -e $f ]]; then
Harald Hoyer 0840a3
-            [[ $to ]] && inst "$f" "$to" && return 0
Harald Hoyer 0840a3
-            inst "$f" && return 0
Harald Hoyer 0840a3
-        fi
Harald Hoyer 0840a3
+        [[ -e $f ]] || continue
Harald Hoyer 0840a3
+        [[ $to ]] && inst "$f" "$to" && return 0
Harald Hoyer 0840a3
+        inst "$f" && return 0
Harald Hoyer 0840a3
     done
Harald Hoyer 0840a3
 
Harald Hoyer 0840a3
     return 1
Harald Hoyer 0840a3
@@ -1118,8 +1112,7 @@ inst_decompress() {
Harald Hoyer 0840a3
 inst_opt_decompress() {
Harald Hoyer 0840a3
     local _src
Harald Hoyer 0840a3
 
Harald Hoyer 0840a3
-    for _src in $@
Harald Hoyer 0840a3
-    do
Harald Hoyer 0840a3
+    for _src in $@; do
Harald Hoyer 0840a3
         inst_decompress "${_src}" || inst "${_src}"
Harald Hoyer 0840a3
     done
Harald Hoyer 0840a3
 }
Harald Hoyer 0840a3
@@ -1482,10 +1475,9 @@ install_kmod_with_fw() {
Harald Hoyer 0840a3
     for _fw in $(modinfo -k $kernel -F firmware $1 2>/dev/null); do
Harald Hoyer 0840a3
         _found=''
Harald Hoyer 0840a3
         for _fwdir in $fw_dir; do
Harald Hoyer 0840a3
-            if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
Harald Hoyer 0840a3
-                inst_simple "$_fwdir/$_fw" "/lib/firmware/$_fw"
Harald Hoyer 0840a3
-                _found=yes
Harald Hoyer 0840a3
-            fi
Harald Hoyer 0840a3
+            [[ -d $_fwdir && -f $_fwdir/$_fw ]] || continue
Harald Hoyer 0840a3
+            inst_simple "$_fwdir/$_fw" "/lib/firmware/$_fw"
Harald Hoyer 0840a3
+            _found=yes
Harald Hoyer 0840a3
         done
Harald Hoyer 0840a3
         if [[ $_found != yes ]]; then
Harald Hoyer 0840a3
             if ! [[ -d $(echo /sys/module/${_modname//-/_}|{ read a b; echo $a; }) ]]; then
Harald Hoyer 0840a3
@@ -1557,10 +1549,9 @@ dracut_kernel_post() {
Harald Hoyer 0840a3
         else
Harald Hoyer 0840a3
             for _fw in $(xargs -r modinfo -k $kernel -F firmware < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
Harald Hoyer 0840a3
                 for _fwdir in $fw_dir; do
Harald Hoyer 0840a3
-                    if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
Harald Hoyer 0840a3
-                        inst_simple "$_fwdir/$_fw" "/lib/firmware/$_fw"
Harald Hoyer 0840a3
-                        break
Harald Hoyer 0840a3
-                    fi
Harald Hoyer 0840a3
+                    [[ -d $_fwdir && -f $_fwdir/$_fw ]] || continue
Harald Hoyer 0840a3
+                    inst_simple "$_fwdir/$_fw" "/lib/firmware/$_fw"
Harald Hoyer 0840a3
+                    break
Harald Hoyer 0840a3
                 done
Harald Hoyer 0840a3
             done
Harald Hoyer 0840a3
         fi