[Libguestfs] [PATCH] inspect: use check_tests also for detecting Hurd

Pino Toscano ptoscano at redhat.com
Wed Feb 14 14:23:23 UTC 2018


Even though the list of checks is very short, at least this migrates
from imperative checks to a "declarative" one.

There should be no behaviour change, other than using os-release if it
contains all the needed information.
---
 daemon/inspect_fs_unix.ml | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/daemon/inspect_fs_unix.ml b/daemon/inspect_fs_unix.ml
index 53c86e878..e2a7364bd 100644
--- a/daemon/inspect_fs_unix.ml
+++ b/daemon/inspect_fs_unix.ml
@@ -698,6 +698,17 @@ let rec check_openbsd_root mountable data =
 and check_hostname_openbsd () =
   check_hostname_from_file "/etc/myname"
 
+let hurd_root_tests : tests = [
+  (* Newer distros include /etc/os-release which is reasonably
+   * standardized.  This entry should be first.
+   *)
+  "/etc/os-release",     parse_os_release;
+  "/etc/debian_version", parse_generic DISTRO_DEBIAN;
+  (* Arch Hurd also exists, but inconveniently it doesn't have
+   * the normal /etc/arch-release file.  XXX
+   *)
+]
+
 (* The currently mounted device may be a Hurd root.  Hurd has distros
  * just like Linux.
  *)
@@ -705,13 +716,7 @@ let rec check_hurd_root mountable data =
   let os_type = OS_TYPE_HURD in
   data.os_type <- Some os_type;
 
-  if Is.is_file "/etc/debian_version" ~followsymlinks:true then (
-    let distro = DISTRO_DEBIAN in
-    ignore (parse_generic distro "/etc/debian_version" data)
-  );
-  (* Arch Hurd also exists, but inconveniently it doesn't have
-   * the normal /etc/arch-release file.  XXX
-   *)
+  check_tests data linux_root_tests;
 
   (* Determine the architecture. *)
   data.arch <- check_architecture ();
-- 
2.14.3




More information about the Libguestfs mailing list