]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fix(dracut-functions): get_maj_min without get_maj_min_cache_file set
authorHarald Hoyer <harald@redhat.com>
Fri, 21 May 2021 10:19:32 +0000 (12:19 +0200)
committerHarald Hoyer <harald@hoyer.xyz>
Fri, 21 May 2021 12:17:07 +0000 (14:17 +0200)
If `get_maj_min_cache_file` is unset `get_maj_min()` would error out.

Fix it to work without a cache file set.

dracut-functions.sh

index 1991c62e0ec4a9da5d48d5789dd6201806ce4bd9..5206bd218b6e722fe19095446b0ba3c6154e26f7 100755 (executable)
@@ -234,13 +234,20 @@ get_fs_env() {
 # 8:2
 get_maj_min() {
     local _majmin
-    out="$(grep -m1 -oP "^$1 \K\S+$" "${get_maj_min_cache_file:?}")"
-    if [ -z "$out" ]; then
+    local _out
+
+    if [[ $get_maj_min_cache_file ]]; then
+        _out="$(grep -m1 -oP "^$1 \K\S+$" "$get_maj_min_cache_file")"
+    fi
+
+    if ! [[ "$_out" ]]; then
         _majmin="$(stat -L -c '%t:%T' "$1" 2> /dev/null)"
-        out="$(printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))")"
-        echo "$1 $out" >> "${get_maj_min_cache_file:?}"
+        _out="$(printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))")"
+        if [[ $get_maj_min_cache_file ]]; then
+            echo "$1 $_out" >> "$get_maj_min_cache_file"
+        fi
     fi
-    echo -n "$out"
+    echo -n "$_out"
 }
 
 # get_devpath_block <device>