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