Harald Hoyer 9f8738
From a277a5fc7acc0a9e8d853f09671495f9d27645c1 Mon Sep 17 00:00:00 2001
Harald Hoyer 9f8738
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 9f8738
Date: Fri, 21 May 2021 12:19:32 +0200
Harald Hoyer 9f8738
Subject: [PATCH] fix(dracut-functions): get_maj_min without
Harald Hoyer 9f8738
 get_maj_min_cache_file set
Harald Hoyer 9f8738
Harald Hoyer 9f8738
If `get_maj_min_cache_file` is unset `get_maj_min()` would error out.
Harald Hoyer 9f8738
Harald Hoyer 9f8738
Fix it to work without a cache file set.
Harald Hoyer 9f8738
---
Harald Hoyer 9f8738
 dracut-functions.sh | 17 ++++++++++++-----
Harald Hoyer 9f8738
 1 file changed, 12 insertions(+), 5 deletions(-)
Harald Hoyer 9f8738
Harald Hoyer 9f8738
diff --git a/dracut-functions.sh b/dracut-functions.sh
Harald Hoyer 9f8738
index 1991c62e..5206bd21 100755
Harald Hoyer 9f8738
--- a/dracut-functions.sh
Harald Hoyer 9f8738
+++ b/dracut-functions.sh
Harald Hoyer 9f8738
@@ -234,13 +234,20 @@ get_fs_env() {
Harald Hoyer 9f8738
 # 8:2
Harald Hoyer 9f8738
 get_maj_min() {
Harald Hoyer 9f8738
     local _majmin
Harald Hoyer 9f8738
-    out="$(grep -m1 -oP "^$1 \K\S+$" "${get_maj_min_cache_file:?}")"
Harald Hoyer 9f8738
-    if [ -z "$out" ]; then
Harald Hoyer 9f8738
+    local _out
Harald Hoyer 9f8738
+
Harald Hoyer 9f8738
+    if [[ $get_maj_min_cache_file ]]; then
Harald Hoyer 9f8738
+        _out="$(grep -m1 -oP "^$1 \K\S+$" "$get_maj_min_cache_file")"
Harald Hoyer 9f8738
+    fi
Harald Hoyer 9f8738
+
Harald Hoyer 9f8738
+    if ! [[ "$_out" ]]; then
Harald Hoyer 9f8738
         _majmin="$(stat -L -c '%t:%T' "$1" 2> /dev/null)"
Harald Hoyer 9f8738
-        out="$(printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))")"
Harald Hoyer 9f8738
-        echo "$1 $out" >> "${get_maj_min_cache_file:?}"
Harald Hoyer 9f8738
+        _out="$(printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))")"
Harald Hoyer 9f8738
+        if [[ $get_maj_min_cache_file ]]; then
Harald Hoyer 9f8738
+            echo "$1 $_out" >> "$get_maj_min_cache_file"
Harald Hoyer 9f8738
+        fi
Harald Hoyer 9f8738
     fi
Harald Hoyer 9f8738
-    echo -n "$out"
Harald Hoyer 9f8738
+    echo -n "$_out"
Harald Hoyer 9f8738
 }
Harald Hoyer 9f8738
 
Harald Hoyer 9f8738
 # get_devpath_block <device>