Bug#913655: grub-pc: id caching in postinst does not work

Héctor Orón Martínez hector.oron at gmail.com
Thu Dec 2 14:25:10 GMT 2021


Hello,

  Please find below an update from previous patch suggested

--- postinst    2021-10-06 17:16:32.966812000 -0400
+++ postinst.913655.patched       2021-10-27 09:03:25.324340000 -0400
@@ -73,7 +73,6 @@
 # This only works on a Linux system with udev running.  This is probably the
 # vast majority of systems where we need any of this, though, and we fall
 # back reasonably gracefully if we don't have it.
-cached_available_ids=
 available_ids()
 {
   local id path
@@ -84,19 +83,25 @@
   fi   [ -d /dev/disk/by-id ] || return
-  cached_available_ids="$(
-    for path in /dev/disk/by-id/*; do
-      [ -e "$path" ] || continue
-      printf '%s %s\n' "$path" "$(readlink -f "$path")"
-    done | sort -k2 -s -u | cut -d' ' -f1
-  )"
-  echo "$cached_available_ids"
+  for path in /dev/disk/by-id/*; do
+    [ -e "$path" ] || continue
+    printf '%s %s\n' "$path" "$(readlink -f "$path")"
+  done | sort -k2 -s -u | cut -d' ' -f1
 }
+cached_available_ids=$(available_ids) # Returns non-zero and no
output if no mapping can be found.
 device_to_id()
 {
   local id
+  # If it's already in /dev/disk/by-id, skip the expensive loop
+  # Using case to support glob matching with /bin/sh compatibility
+  case "$1" in
+    /dev/disk/by-id/*)
+      echo "$1"
+      return 0
+      ;;
+  esac
   for id in $(available_ids); do
     if [ "$(readlink -f "$id")" = "$(readlink -f "$1")" ]; then
       echo "$id"

Regards
-- 
 Héctor Orón  -.. . -... .. .- -.   -.. . ...- . .-.. --- .--. . .-.



More information about the Pkg-grub-devel mailing list