Pino Toscano
2017-Oct-17 12:21 UTC
[Libguestfs] [PATCH] daemon: simplify usage of Chroot.f
Rely on currying, and avoid extra helper functions. No behaviour changes. --- daemon/inspect_fs_unix.ml | 20 ++++++++++---------- daemon/inspect_fs_windows.ml | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/daemon/inspect_fs_unix.ml b/daemon/inspect_fs_unix.ml index 59e26a05e..3ad119306 100644 --- a/daemon/inspect_fs_unix.ml +++ b/daemon/inspect_fs_unix.ml @@ -68,7 +68,7 @@ let arch_binaries *) let rec parse_os_release release_file data let chroot = Chroot.create ~name:"parse_os_release" () in - let lines = Chroot.f chroot (fun () -> read_small_file release_file) () in + let lines = Chroot.f chroot read_small_file release_file in match lines with | None -> false @@ -182,7 +182,7 @@ and distro_of_os_release_id = function *) and parse_lsb_release release_file data let chroot = Chroot.create ~name:"parse_lsb_release" () in - let lines = Chroot.f chroot (fun () -> read_small_file release_file) () in + let lines = Chroot.f chroot read_small_file release_file in match lines with | None -> false @@ -229,7 +229,7 @@ and distro_of_lsb_release_distrib_id = function and parse_suse_release release_file data let chroot = Chroot.create ~name:"parse_suse_release" () in - let lines = Chroot.f chroot (fun () -> read_small_file release_file) () in + let lines = Chroot.f chroot read_small_file release_file in match lines with | None @@ -297,14 +297,14 @@ and parse_generic ?rex distro release_file data let chroot = Chroot.create ~name:"parse_generic" () in let product_name Chroot.f chroot ( - fun () -> - if not (is_small_file release_file) then ( - eprintf "%s: not a regular file or too large\n" release_file; + fun file -> + if not (is_small_file file) then ( + eprintf "%s: not a regular file or too large\n" file; "" ) else - read_first_line_from_file release_file - ) () in + read_first_line_from_file file + ) release_file in if product_name = "" then false else ( @@ -530,7 +530,7 @@ and check_hostname_from_file filename let name = sprintf "check_hostname_from_file: %s" filename in Chroot.create ~name () in - let hostname = Chroot.f chroot (fun () -> read_small_file filename) () in + let hostname = Chroot.f chroot read_small_file filename in match hostname with | None | Some [] | Some [""] -> None | Some (hostname :: _) -> Some hostname @@ -629,7 +629,7 @@ and check_hostname_freebsd () let filename = "/etc/rc.conf" in try - let lines = Chroot.f chroot (fun () -> read_small_file filename) () in + let lines = Chroot.f chroot read_small_file filename in let lines match lines with None -> raise Not_found | Some lines -> lines in let rec loop = function diff --git a/daemon/inspect_fs_windows.ml b/daemon/inspect_fs_windows.ml index 78af7f048..c7b766dd0 100644 --- a/daemon/inspect_fs_windows.ml +++ b/daemon/inspect_fs_windows.ml @@ -84,7 +84,7 @@ and get_windows_systemroot () and get_windows_systemroot_from_boot_ini boot_ini_path let chroot = Chroot.create ~name:"get_windows_systemroot_from_boot_ini" () in - let lines = Chroot.f chroot (fun () -> read_small_file boot_ini_path) () in + let lines = Chroot.f chroot read_small_file boot_ini_path in match lines with | None -> None | Some lines -> -- 2.13.6
Richard W.M. Jones
2017-Oct-17 12:57 UTC
Re: [Libguestfs] [PATCH] daemon: simplify usage of Chroot.f
On Tue, Oct 17, 2017 at 02:21:59PM +0200, Pino Toscano wrote:> Rely on currying, and avoid extra helper functions. > > No behaviour changes. > --- > daemon/inspect_fs_unix.ml | 20 ++++++++++---------- > daemon/inspect_fs_windows.ml | 2 +- > 2 files changed, 11 insertions(+), 11 deletions(-) > > diff --git a/daemon/inspect_fs_unix.ml b/daemon/inspect_fs_unix.ml > index 59e26a05e..3ad119306 100644 > --- a/daemon/inspect_fs_unix.ml > +++ b/daemon/inspect_fs_unix.ml > @@ -68,7 +68,7 @@ let arch_binaries > *) > let rec parse_os_release release_file data > let chroot = Chroot.create ~name:"parse_os_release" () in > - let lines = Chroot.f chroot (fun () -> read_small_file release_file) () in > + let lines = Chroot.f chroot read_small_file release_file in > > match lines with > | None -> false > @@ -182,7 +182,7 @@ and distro_of_os_release_id = function > *) > and parse_lsb_release release_file data > let chroot = Chroot.create ~name:"parse_lsb_release" () in > - let lines = Chroot.f chroot (fun () -> read_small_file release_file) () in > + let lines = Chroot.f chroot read_small_file release_file in > > match lines with > | None -> false > @@ -229,7 +229,7 @@ and distro_of_lsb_release_distrib_id = function > > and parse_suse_release release_file data > let chroot = Chroot.create ~name:"parse_suse_release" () in > - let lines = Chroot.f chroot (fun () -> read_small_file release_file) () in > + let lines = Chroot.f chroot read_small_file release_file in > > match lines with > | None > @@ -297,14 +297,14 @@ and parse_generic ?rex distro release_file data > let chroot = Chroot.create ~name:"parse_generic" () in > let product_name > Chroot.f chroot ( > - fun () -> > - if not (is_small_file release_file) then ( > - eprintf "%s: not a regular file or too large\n" release_file; > + fun file -> > + if not (is_small_file file) then ( > + eprintf "%s: not a regular file or too large\n" file; > "" > ) > else > - read_first_line_from_file release_file > - ) () in > + read_first_line_from_file file > + ) release_file in > if product_name = "" then > false > else ( > @@ -530,7 +530,7 @@ and check_hostname_from_file filename > let name = sprintf "check_hostname_from_file: %s" filename in > Chroot.create ~name () in > > - let hostname = Chroot.f chroot (fun () -> read_small_file filename) () in > + let hostname = Chroot.f chroot read_small_file filename in > match hostname with > | None | Some [] | Some [""] -> None > | Some (hostname :: _) -> Some hostname > @@ -629,7 +629,7 @@ and check_hostname_freebsd () > let filename = "/etc/rc.conf" in > > try > - let lines = Chroot.f chroot (fun () -> read_small_file filename) () in > + let lines = Chroot.f chroot read_small_file filename in > let lines > match lines with None -> raise Not_found | Some lines -> lines in > let rec loop = function > diff --git a/daemon/inspect_fs_windows.ml b/daemon/inspect_fs_windows.ml > index 78af7f048..c7b766dd0 100644 > --- a/daemon/inspect_fs_windows.ml > +++ b/daemon/inspect_fs_windows.ml > @@ -84,7 +84,7 @@ and get_windows_systemroot () > > and get_windows_systemroot_from_boot_ini boot_ini_path > let chroot = Chroot.create ~name:"get_windows_systemroot_from_boot_ini" () in > - let lines = Chroot.f chroot (fun () -> read_small_file boot_ini_path) () in > + let lines = Chroot.f chroot read_small_file boot_ini_path in > match lines with > | None -> None > | Some lines -> > -- > 2.13.6 > > _______________________________________________ > Libguestfs mailing list > Libguestfs@redhat.com > https://www.redhat.com/mailman/listinfo/libguestfsLooks good, ACK Thanks, Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Maybe Matching Threads
- [PATCH v11 09/10] daemon: Implement inspection of Windows.
- [PATCH v12 09/11] daemon: Implement inspection of Linux and other Unix-like operating systems.
- [PATCH v3 0/2] daemon: add and use parse_key_value_strings helper
- [PATCH] UNFINISHED daemon: Reimplement most inspection APIs in the daemon.
- [PATCH 1/3] daemon: add split_key_value_strings helper