v2v: linux: add helper functions for pkg arch and extension

Add helper functions to get the typical extension of binary packages
for a package manager, and the string for an architecture.
This commit is contained in:
Pino Toscano
2019-03-26 17:02:02 +01:00
parent ba7fa03923
commit 13ef175a7b
2 changed files with 29 additions and 0 deletions

View File

@@ -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_"dont 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_"dont know what is the architecture string of %s using %s on %s")
arch format distro

View File

@@ -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. *)