From 75c30fe750595f89f310786ed802e3cad7f899d4 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 20 Feb 2023 12:01:21 +0000 Subject: [PATCH] Rework Std_utils.Option so it works like the OCaml stdlib module OCaml 4.08 introduces a stdlib Option module which looks a bit like ours but has a number of differences. In particular our functions Option.may and Option.default have no corresponding functions in stdlib, although there are close enough equivalents. This change was automated using this command: $ perl -pi.bak \ -e 's/Option.may/Option.iter/g; s/Option.default /Option.value ~default:/g' \ `git ls-files` Update common module to include: commit cffa077323fafcdfcf78e230c022afa891a6b3ff Author: Richard W.M. Jones Date: Mon Feb 20 12:11:51 2023 +0000 mlstdutils: Rework the Option module to be compatible with stdlib (cherry picked from commit 250ee85839979898d08cac2ebfcedfa36d50e608) --- common | 2 +- daemon/blkid.ml | 2 +- daemon/inspect_types.ml | 28 ++++++++++++++-------------- daemon/isoinfo.ml | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/common b/common index 53713420b..cffa07732 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 53713420b63dbc99d5ccc58e2a8c5fdf1ab941c3 +Subproject commit cffa077323fafcdfcf78e230c022afa891a6b3ff diff --git a/daemon/blkid.ml b/daemon/blkid.ml index 77586e293..b9e78d871 100644 --- a/daemon/blkid.ml +++ b/daemon/blkid.ml @@ -21,7 +21,7 @@ open Std_utils open Utils let rec vfs_type { Mountable.m_device = device } = - Option.default "" (get_blkid_tag device "TYPE") + Option.value ~default:"" (get_blkid_tag device "TYPE") and get_blkid_tag device tag = let r, out, err = diff --git a/daemon/inspect_types.ml b/daemon/inspect_types.ml index 84ae5f85e..cdf7d13ba 100644 --- a/daemon/inspect_types.ml +++ b/daemon/inspect_types.ml @@ -150,25 +150,25 @@ and string_of_root { root_location; inspection_data } = and string_of_inspection_data data = let b = Buffer.create 1024 in let bpf fs = bprintf b fs in - Option.may (fun v -> bpf " type: %s\n" (string_of_os_type v)) + Option.iter (fun v -> bpf " type: %s\n" (string_of_os_type v)) data.os_type; - Option.may (fun v -> bpf " distro: %s\n" (string_of_distro v)) + Option.iter (fun v -> bpf " distro: %s\n" (string_of_distro v)) data.distro; - Option.may (fun v -> bpf " package_format: %s\n" (string_of_package_format v)) + Option.iter (fun v -> bpf " package_format: %s\n" (string_of_package_format v)) data.package_format; - Option.may (fun v -> bpf " package_management: %s\n" (string_of_package_management v)) + Option.iter (fun v -> bpf " package_management: %s\n" (string_of_package_management v)) data.package_management; - Option.may (fun v -> bpf " product_name: %s\n" v) + Option.iter (fun v -> bpf " product_name: %s\n" v) data.product_name; - Option.may (fun v -> bpf " product_variant: %s\n" v) + Option.iter (fun v -> bpf " product_variant: %s\n" v) data.product_variant; - Option.may (fun (major, minor) -> bpf " version: %d.%d\n" major minor) + Option.iter (fun (major, minor) -> bpf " version: %d.%d\n" major minor) data.version; - Option.may (fun v -> bpf " arch: %s\n" v) + Option.iter (fun v -> bpf " arch: %s\n" v) data.arch; - Option.may (fun v -> bpf " hostname: %s\n" v) + Option.iter (fun v -> bpf " hostname: %s\n" v) data.hostname; - Option.may (fun v -> bpf " build ID: %s\n" v) + Option.iter (fun v -> bpf " build ID: %s\n" v) data.build_id; if data.fstab <> [] then ( let v = List.map ( @@ -176,13 +176,13 @@ and string_of_inspection_data data = ) data.fstab in bpf " fstab: [%s]\n" (String.concat ", " v) ); - Option.may (fun v -> bpf " windows_systemroot: %s\n" v) + Option.iter (fun v -> bpf " windows_systemroot: %s\n" v) data.windows_systemroot; - Option.may (fun v -> bpf " windows_software_hive: %s\n" v) + Option.iter (fun v -> bpf " windows_software_hive: %s\n" v) data.windows_software_hive; - Option.may (fun v -> bpf " windows_system_hive: %s\n" v) + Option.iter (fun v -> bpf " windows_system_hive: %s\n" v) data.windows_system_hive; - Option.may (fun v -> bpf " windows_current_control_set: %s\n" v) + Option.iter (fun v -> bpf " windows_current_control_set: %s\n" v) data.windows_current_control_set; if data.drive_mappings <> [] then ( let v = diff --git a/daemon/isoinfo.ml b/daemon/isoinfo.ml index 4d410a67a..8ccc4ea7e 100644 --- a/daemon/isoinfo.ml +++ b/daemon/isoinfo.ml @@ -61,7 +61,7 @@ let iso_parse_datetime str = let old_TZ = try Some (getenv "TZ") with Not_found -> None in putenv "TZ" "UTC"; let r = Int64.of_float (fst (mktime tm)) in - Option.may (putenv "TZ") old_TZ; + Option.iter (putenv "TZ") old_TZ; (* The final byte is a time zone offset from GMT. *