[Libguestfs] [PATCH 1/2] dpkg: do not always run dpkg_primary_arch

Pino Toscano ptoscano at redhat.com
Wed Mar 5 10:17:45 UTC 2014


Having dpkg_primary_arch as a top-level statement means it will be
evaluated at startup, which will fail if dpkg is not installed.

Turn it into a function so it can be run just when needed.
---
 src/dpkg.ml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/dpkg.ml b/src/dpkg.ml
index 147d0bc..71aa12c 100644
--- a/src/dpkg.ml
+++ b/src/dpkg.ml
@@ -29,7 +29,7 @@ let dpkg_detect () =
     Config.apt_get <> "no" &&
     file_exists "/etc/debian_version"
 
-let dpkg_primary_arch =
+let dpkg_primary_arch () =
   let cmd = sprintf "%s --print-architecture" Config.dpkg in
   let lines = run_command_get_lines cmd in
   match lines with
@@ -80,7 +80,7 @@ let dpkg_package_of_string str =
     (* On multiarch setups, only consider the primary architecture *)
     try
       List.find (fun pkg ->
-        pkg.arch = dpkg_primary_arch || pkg.arch = "all") pkgs
+        pkg.arch = dpkg_primary_arch () || pkg.arch = "all") pkgs
     with
       Not_found -> assert false
 
-- 
1.8.3.1




More information about the Libguestfs mailing list