Skip to content

Commit a277a5f

Browse files
committed
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.
1 parent 0a6007b commit a277a5f

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

dracut-functions.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,20 @@ get_fs_env() {
234234
# 8:2
235235
get_maj_min() {
236236
local _majmin
237-
out="$(grep -m1 -oP "^$1 \K\S+$" "${get_maj_min_cache_file:?}")"
238-
if [ -z "$out" ]; then
237+
local _out
238+
239+
if [[ $get_maj_min_cache_file ]]; then
240+
_out="$(grep -m1 -oP "^$1 \K\S+$" "$get_maj_min_cache_file")"
241+
fi
242+
243+
if ! [[ "$_out" ]]; then
239244
_majmin="$(stat -L -c '%t:%T' "$1" 2> /dev/null)"
240-
out="$(printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))")"
241-
echo "$1 $out" >> "${get_maj_min_cache_file:?}"
245+
_out="$(printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))")"
246+
if [[ $get_maj_min_cache_file ]]; then
247+
echo "$1 $_out" >> "$get_maj_min_cache_file"
248+
fi
242249
fi
243-
echo -n "$out"
250+
echo -n "$_out"
244251
}
245252
246253
# get_devpath_block <device>

0 commit comments

Comments
 (0)