Blame 0043-dracut-lib-new-functions-listlist-and-are_lists_eq.patch

Harald Hoyer 12f6cc
From 5767201eaf7d2265066d17cd5b97691cbb191e3b Mon Sep 17 00:00:00 2001
Harald Hoyer 12f6cc
From: =?UTF-8?q?Amadeusz=20=C5=BBo=C5=82nowski?= <aidecoe@aidecoe.name>
Harald Hoyer 12f6cc
Date: Thu, 26 Jul 2012 15:05:25 +0200
Harald Hoyer 12f6cc
Subject: [PATCH] dracut-lib: new functions: listlist and are_lists_eq
Harald Hoyer 12f6cc
Harald Hoyer 12f6cc
listlist is like strstr for lists with specified separator and
Harald Hoyer 12f6cc
are_lists_eq uses listlist to check equality of specified lists.
Harald Hoyer 12f6cc
---
Harald Hoyer 12f6cc
 modules.d/99base/dracut-lib.sh | 38 ++++++++++++++++++++++++++++++++++++++
Harald Hoyer 12f6cc
 1 file changed, 38 insertions(+)
Harald Hoyer 12f6cc
Harald Hoyer 12f6cc
diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
Harald Hoyer 12f6cc
index 786661e..2eb1224 100755
Harald Hoyer 12f6cc
--- a/modules.d/99base/dracut-lib.sh
Harald Hoyer 12f6cc
+++ b/modules.d/99base/dracut-lib.sh
Harald Hoyer 12f6cc
@@ -906,3 +906,41 @@ export_n()
Harald Hoyer 12f6cc
         [ -n "$val" ] && eval $var=\"$val\"
Harald Hoyer 12f6cc
     done
Harald Hoyer 12f6cc
 }
Harald Hoyer 12f6cc
+
Harald Hoyer 12f6cc
+# returns OK if list1 contains all elements of list2, i.e. checks if list2 is a
Harald Hoyer 12f6cc
+# sublist of list1.  An order and a duplication doesn't matter.
Harald Hoyer 12f6cc
+#
Harald Hoyer 12f6cc
+# $1 = separator
Harald Hoyer 12f6cc
+# $2 = list1
Harald Hoyer 12f6cc
+# $3 = list2
Harald Hoyer 12f6cc
+# $4 = ignore values, separated by $1
Harald Hoyer 12f6cc
+listlist() {
Harald Hoyer 12f6cc
+    local _sep="$1"
Harald Hoyer 12f6cc
+    local _list="${_sep}${2}${_sep}"
Harald Hoyer 12f6cc
+    local _sublist="$3"
Harald Hoyer 12f6cc
+    [ -n "$4" ] && local _iglist="${_sep}${4}${_sep}"
Harald Hoyer 12f6cc
+    local IFS="$_sep"
Harald Hoyer 12f6cc
+    local _v
Harald Hoyer 12f6cc
+
Harald Hoyer 12f6cc
+    [ "$_list" = "$_sublist" ] && return 0
Harald Hoyer 12f6cc
+
Harald Hoyer 12f6cc
+    for _v in $_sublist; do
Harald Hoyer 12f6cc
+        if [ -n "$_v" ] && ! ( [ -n "$_iglist" ] && strstr "$_iglist" "$_v" )
Harald Hoyer 12f6cc
+        then
Harald Hoyer 12f6cc
+            strstr "$_list" "$_v" || return 1
Harald Hoyer 12f6cc
+        fi
Harald Hoyer 12f6cc
+    done
Harald Hoyer 12f6cc
+
Harald Hoyer 12f6cc
+    return 0
Harald Hoyer 12f6cc
+}
Harald Hoyer 12f6cc
+
Harald Hoyer 12f6cc
+# returns OK if both lists contain the same values.  An order and a duplication
Harald Hoyer 12f6cc
+# doesn't matter.
Harald Hoyer 12f6cc
+# 
Harald Hoyer 12f6cc
+# $1 = separator
Harald Hoyer 12f6cc
+# $2 = list1
Harald Hoyer 12f6cc
+# $3 = list2
Harald Hoyer 12f6cc
+# $4 = ignore values, separated by $1
Harald Hoyer 12f6cc
+are_lists_eq() {
Harald Hoyer 12f6cc
+    listlist "$1" "$2" "$3" "$4" && listlist "$1" "$3" "$2" "$4"
Harald Hoyer 12f6cc
+}