[Libguestfs] [PATCH v3 13/22] v2v: linux: Properly ignore rpm/dpkg-move-aside kernels.

Pino Toscano ptoscano at redhat.com
Wed Sep 27 12:38:28 UTC 2017


On Friday, 22 September 2017 09:36:14 CEST Richard W.M. Jones wrote:
> diff --git a/v2v/linux_bootloaders.ml b/v2v/linux_bootloaders.ml
> index 210cce762..00cb5cd19 100644
> --- a/v2v/linux_bootloaders.ml
> +++ b/v2v/linux_bootloaders.ml
> @@ -319,9 +319,9 @@ object (self)
>          Array.to_list (g#glob_expand "/boot/kernel-*") @
>          Array.to_list (g#glob_expand "/boot/vmlinuz-*") @
>          Array.to_list (g#glob_expand "/vmlinuz-*") in
> -    let rex = Str.regexp ".*\\.\\(dpkg-.*|rpmsave|rpmnew\\)$" in
> +    let rex = PCRE.compile "\\.(?:dpkg-.*|rpmsave|rpmnew)$" in
>      let vmlinuzes = List.filter (
> -      fun file -> not (Str.string_match rex file 0)
> +      fun file -> not (PCRE.matches rex file)
>      ) vmlinuzes in

TBH here I'd just drop the regexp usage, and use a static list of
suffixes (there are not that many, anyway) -- something like:

  let suffixes = [ ".dpkg-old"; ".dpkg-new"; ".rpmsave"; ".rpmnew"; ] in
  let vmlinuzes = List.filter (
    fun file -> not (List.exists (Filename.check_suffix file))
  ) vmlinuxes in

Even better, this can be moved to a separate function in the Linux
module, which is where (most of) the interaction with package managers
happen:

let is_package_manager_file file =
  (* Recognized suffixes of package managers. *)
  let suffixes = [ ".dpkg-old"; ".dpkg-new"; ".rpmsave"; ".rpmnew"; ] in
  List.exists (Filename.check_suffix file)

...

  let vmlinuzes = List.filter (
    fun file -> not (Linux.is_package_manager_file file)
  ) vmlinuxes in

(Of course with a better naming for the function.)

-- 
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20170927/77f5e38a/attachment.sig>


More information about the Libguestfs mailing list