[Libguestfs] [PATCH 1/3] v2v: linux: add helper functions for pkg arch and extension

Richard W.M. Jones rjones at redhat.com
Wed Mar 27 10:40:42 UTC 2019


On Tue, Mar 26, 2019 at 06:02:40PM +0100, Pino Toscano wrote:
> Add helper functions to get the typical extension of binary packages
> for a package manager, and the string for an architecture.
> ---
>  v2v/linux.ml  | 21 +++++++++++++++++++++
>  v2v/linux.mli |  8 ++++++++
>  2 files changed, 29 insertions(+)
> 
> diff --git a/v2v/linux.ml b/v2v/linux.ml
> index 99b0e0e7b..4949c8e16 100644
> --- a/v2v/linux.ml
> +++ b/v2v/linux.ml
> @@ -179,3 +179,24 @@ let is_package_manager_save_file filename =
>    (* Recognized suffixes of package managers. *)
>    let suffixes = [ ".dpkg-old"; ".dpkg-new"; ".rpmsave"; ".rpmnew"; ] in
>    List.exists (Filename.check_suffix filename) suffixes
> +
> +let binary_package_extension { i_package_format = package_format } =
> +  match package_format with
> +  | "deb" -> "deb"
> +  | "rpm" -> "rpm"
> +  | format ->
> +    error (f_"don’t know what is the extension of binary packages using %s")
> +      format
> +
> +let architecture_string { i_package_format = package_format; i_arch = arch;
> +                          i_distro = distro } =
> +  match package_format, distro, arch with
> +  | "deb", _, "x86_64" -> "amd64"
> +  | "deb", _, a -> a
> +  | "rpm", ("sles"|"suse-based"|"opensuse"), "i386" -> "i586"
> +  | "rpm", ("sles"|"suse-based"|"opensuse"), a -> a
> +  | "rpm", _, "i386" -> "i686"
> +  | "rpm", _, a -> a
> +  | format, distro, arch ->
> +    error (f_"don’t know what is the architecture string of %s using %s on %s")
> +      arch format distro
> diff --git a/v2v/linux.mli b/v2v/linux.mli
> index 0a5991d12..30099745c 100644
> --- a/v2v/linux.mli
> +++ b/v2v/linux.mli
> @@ -38,3 +38,11 @@ val is_file_owned : Guestfs.guestfs -> Types.inspect -> string -> bool
>  val is_package_manager_save_file : string -> bool
>  (** Return true if the filename is something like [*.rpmsave], ie.
>      a package manager save-file. *)
> +
> +val binary_package_extension : Types.inspect -> string
> +(** Return the extension typically used for binary packages in the
> +    specified package format. *)
> +
> +val architecture_string : Types.inspect -> string
> +(** Return the architecture string typically used for binary packages
> +    in the specified package format, and for the specified distro. *)
> -- 
> 2.20.1

ACK.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/




More information about the Libguestfs mailing list