fix(dracut-functions): get_maj_min without get_maj_min_cache_file set

If `get_maj_min_cache_file` is unset `get_maj_min()` would error out.

Fix it to work without a cache file set.
master
Harald Hoyer 2021-05-21 12:19:32 +02:00 committed by Harald Hoyer
parent 0a6007bf4f
commit a277a5fc7a
1 changed files with 13 additions and 6 deletions

View File

@ -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
_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:?}"
local _out

if [[ $get_maj_min_cache_file ]]; then
_out="$(grep -m1 -oP "^$1 \K\S+$" "$get_maj_min_cache_file")"
fi
echo -n "$out"

if ! [[ "$_out" ]]; then
_majmin="$(stat -L -c '%t:%T' "$1" 2> /dev/null)"
_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"
}

# get_devpath_block <device>