diff --git a/configure.ml b/configure.ml old mode 100755 new mode 100644 diff --git a/lib/inventory.ml b/lib/inventory.ml index ba1363b9f39..c6dc1697b6e 100644 --- a/lib/inventory.ml +++ b/lib/inventory.ml @@ -41,80 +41,80 @@ let inventory_m = Mutex.create () (* Compute the minimum necessary inventory file contents *) let minimum_default_entries () = - let host_uuid = Uuidm.to_string (Uuidm.create `V4) in - let dom0_uuid = Uuidm.to_string (Uuidm.create `V4) in - [ - _installation_uuid, host_uuid; - _control_domain_uuid, dom0_uuid; - _management_interface, ""; - _management_address_type, "IPv4"; - _build_number, "0" - ] + let host_uuid = Uuidm.to_string (Uuidm.create `V4) in + let dom0_uuid = Uuidm.to_string (Uuidm.create `V4) in + [ + _installation_uuid, host_uuid; + _control_domain_uuid, dom0_uuid; + _management_interface, ""; + _management_address_type, "IPv4"; + _build_number, "0" + ] (* trim any quotes off the ends *) let strip_quotes v = - if String.length v >= 2 - && v.[0] = '\'' - && v.[String.length v - 1] = '\'' - then String.sub v 1 (String.length v - 2) - else v + if String.length v >= 2 + && v.[0] = '\'' + && v.[String.length v - 1] = '\'' + then String.sub v 1 (String.length v - 2) + else v let parse_inventory_entry line = - match Astring.String.cuts ~empty:false ~sep:"=" line with - | [k; v] -> - (* trim whitespace *) - Some (k, v |> strip_quotes |> String.trim) - | _ -> None + match Astring.String.cuts ~empty:false ~sep:"=" line with + | [k; v] -> + (* trim whitespace *) + Some (k, v |> strip_quotes |> String.trim) + | _ -> None let string_of_table h = - let lines = List.fold_left (fun acc (k, v) -> - Printf.sprintf "%s='%s'\n" k v :: acc) [] h in - String.concat "" lines + let lines = List.fold_left (fun acc (k, v) -> + Printf.sprintf "%s='%s'\n" k v :: acc) [] h in + String.concat "" lines let read_inventory_contents () = - if not (Sys.file_exists !inventory_filename) then begin - Unixext.write_string_to_file !inventory_filename ( - string_of_table (minimum_default_entries ())) - end; - (* Perhaps we should blank the old inventory before we read the new one? - What is the desired behaviour? *) - Unixext.file_lines_iter (fun line -> - match parse_inventory_entry line with - | Some (k, v) -> Hashtbl.add inventory k v - | None -> ()) - !inventory_filename; - loaded_inventory := true + if not (Sys.file_exists !inventory_filename) then begin + Unixext.write_string_to_file !inventory_filename ( + string_of_table (minimum_default_entries ())) + end; + (* Perhaps we should blank the old inventory before we read the new one? + What is the desired behaviour? *) + Unixext.file_lines_iter (fun line -> + match parse_inventory_entry line with + | Some (k, v) -> Hashtbl.add inventory k v + | None -> ()) + !inventory_filename; + loaded_inventory := true let read_inventory () = Mutex.execute inventory_m read_inventory_contents let reread_inventory () = Mutex.execute inventory_m (fun () -> - Hashtbl.clear inventory; - read_inventory_contents ()) + Hashtbl.clear inventory; + read_inventory_contents ()) exception Missing_inventory_key of string let lookup ?default key = - Mutex.execute inventory_m (fun () -> - (if not (!loaded_inventory) then read_inventory_contents ()); - if (Hashtbl.mem inventory key) - then - Hashtbl.find inventory key - else - match default with - | None -> raise (Missing_inventory_key key) - | Some v -> v) + Mutex.execute inventory_m (fun () -> + (if not (!loaded_inventory) then read_inventory_contents ()); + if (Hashtbl.mem inventory key) + then + Hashtbl.find inventory key + else + match default with + | None -> raise (Missing_inventory_key key) + | Some v -> v) let flush_to_disk_locked () = - let h = Hashtbl.fold (fun k v acc -> (k, v) :: acc) inventory [] in - Unixext.write_string_to_file !inventory_filename (string_of_table h) + let h = Hashtbl.fold (fun k v acc -> (k, v) :: acc) inventory [] in + Unixext.write_string_to_file !inventory_filename (string_of_table h) let update key value = Mutex.execute inventory_m (fun () -> - Hashtbl.clear inventory; - read_inventory_contents (); - Hashtbl.replace inventory key value; - flush_to_disk_locked ()) + Hashtbl.clear inventory; + read_inventory_contents (); + Hashtbl.replace inventory key value; + flush_to_disk_locked ()) let remove key = Mutex.execute inventory_m (fun () -> - Hashtbl.clear inventory; - read_inventory_contents (); - Hashtbl.remove inventory key; - flush_to_disk_locked ()) + Hashtbl.clear inventory; + read_inventory_contents (); + Hashtbl.remove inventory key; + flush_to_disk_locked ())