[Libguestfs] [rhel-9.2 v2v PATCH 1/2] detect_kernels: tighten "try" scope

Laszlo Ersek lersek at redhat.com
Wed Apr 5 15:08:28 UTC 2023


We want to catch Not_found from (our own implementation of)
"List.find_map". There's no need (and it makes no sense) to push the
"prefix_len" calculation down into the "try" scope. Keep the "try" scope
as narrow as possible.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2175703
Signed-off-by: Laszlo Ersek <lersek at redhat.com>
Tested-by: Vera Wu <vwu at redhat.com>
(ported from libguestfs-common commit 4003815a994944cab38d48cfc96f16382de62987)
---
 convert/linux_kernels.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/convert/linux_kernels.ml b/convert/linux_kernels.ml
index 6e9d2bdd89cc..75ab94c45551 100644
--- a/convert/linux_kernels.ml
+++ b/convert/linux_kernels.ml
@@ -122,8 +122,8 @@ let detect_kernels (g : G.guestfs) inspect family bootloader =
             *)
            let modpath, version =
              let prefix = "/lib/modules/" in
+             let prefix_len = String.length prefix in
              try
-               let prefix_len = String.length prefix in
                List.find_map (
                  fun filename ->
                    let filename_len = String.length filename in



More information about the Libguestfs mailing list