From 7b3890b0ec079b57a610147b18404444ff4c0190 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 6 Oct 2012 10:25:18 -0400 Subject: convert autodetect cache to hash If mkinitcpio -s is run, we still flush this cache to disk before exiting. Signed-off-by: Dave Reisner --- functions | 8 ++++---- install/autodetect | 38 +++++++++++++++++++++----------------- mkinitcpio | 7 ++++--- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/functions b/functions index d077213..cc4509a 100644 --- a/functions +++ b/functions @@ -273,8 +273,8 @@ add_checked_modules() { local mod mods - if [[ -s $_f_autodetect_cache ]]; then - mapfile -t mods < <(all_modules "$@" | grep -xFf "$_f_autodetect_cache") + if (( ${#_autodetect_cache[*]} )); then + mapfile -t mods < <(all_modules "$@" | grep -xFf <(printf '%s\n' "${!_autodetect_cache[@]}")) else mapfile -t mods < <(all_modules "$@") fi @@ -293,8 +293,8 @@ checked_modules() { # DEPRECATED: Use add_checked_modules instead # - if [[ -s $_f_autodetect_cache ]]; then - grep -xFf "$_f_autodetect_cache" <(all_modules "$@") + if (( ${#_autodetect_cache[*]} )); then + all_modules "$@" | grep -xFf <(printf '%s\n' "${!_autodetect_cache[@]}") return 1 else all_modules "$@" diff --git a/install/autodetect b/install/autodetect index 4f1e4bb..907a85a 100644 --- a/install/autodetect +++ b/install/autodetect @@ -1,20 +1,19 @@ #!/bin/bash build() { - local -a md_devs - - _f_autodetect_cache=$_d_workdir/autodetect_modules + local m= + local -a md_devs mods add_if_avail() { - local resolved + local r= resolved= # treat this as an alias, since ext3 might be aliased to ext4. IFS=$'\n' read -rd '' -a resolved < \ <(modprobe -d "$_optmoduleroot" -S "$KERNELVERSION" -R "$1" 2>/dev/null) - if (( ${#resolved[*]} )); then - printf '%s\n' "${resolved[@]}" >>"$_f_autodetect_cache" - fi + for r in "${resolved[@]}"; do + _autodetect_cache["$r"]=1 + done } if [[ ! -d /sys/devices ]]; then @@ -22,7 +21,10 @@ build() { return 1 fi - auto_modules >"$_f_autodetect_cache" + mapfile -t mods < <(auto_modules) + for m in "${mods[@]}"; do + _autodetect_cache["$m"]=1 + done # detect filesystem for root if rootfstype=$(findmnt -uno fstype '/'); then @@ -41,22 +43,24 @@ build() { md_devs=(/sys/class/block/md*/md/level) if [[ -e $md_devs ]]; then quiet "found %d mdadm arrays to scan" "${#md_devs[*]}" - awk '{ gsub(/raid[456]/, "raid456"); print; }' "${md_devs[@]}" | - sort -u >>"$_f_autodetect_cache" + mapfile -t mods < <(awk '{ gsub(/raid[456]/, "raid456"); print; }' "${md_devs[@]}") + for m in "${mods[@]}"; do + _autodetect_cache["$m"]=1 + done fi - if [[ -s $_f_autodetect_cache ]]; then - quiet "caching %d modules" $(wc -l < "$_f_autodetect_cache") + if (( ${#_autodetect_cache[*]} )); then + quiet "caching %d modules" "${#_autodetect_cache[*]}" fi } help() { cat < "$_d_workdir/autodetect_modules" msg "build directory saved in %s" "$_d_workdir" else rm -rf "$_d_workdir" @@ -378,7 +379,7 @@ if (( _optshowautomods )); then _f_autodetect_hook=$(find_in_dirs 'autodetect' "${_d_install[@]}") . "$_f_autodetect_hook" build - cat "$_f_autodetect_cache" + printf '%s\n' "${!_autodetect_cache[@]}" | sort cleanup 0 fi -- cgit v1.2.3-24-g4f1b