# 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>