From d279d602bee77e469c613ae45e591441f834060e Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 21 Sep 2017 13:32:09 +0100 Subject: [PATCH] v2v: linux: Properly ignore rpm/dpkg-move-aside kernels. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The old virt-v2v code ignored boot kernels with names like "/boot/vmlinuz-*.rpmsave". The transscribed code did not because the Str module requires ‘|’ to be escaped as ‘\|’. This changes the code to use a simpler test. Thanks: Pino Toscano --- v2v/linux.ml | 5 +++++ v2v/linux.mli | 4 ++++ v2v/linux_bootloaders.ml | 3 +-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/v2v/linux.ml b/v2v/linux.ml index a1c2c25a5..9c87c947f 100644 --- a/v2v/linux.ml +++ b/v2v/linux.ml @@ -157,3 +157,8 @@ let rec file_owner (g : G.guestfs) { i_package_format = package_format } path = and is_file_owned g inspect path = try ignore (file_owner g inspect path); true with Not_found -> false + +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 diff --git a/v2v/linux.mli b/v2v/linux.mli index 23c42f755..642c9ccce 100644 --- a/v2v/linux.mli +++ b/v2v/linux.mli @@ -35,3 +35,7 @@ val file_owner : Guestfs.guestfs -> Types.inspect -> string -> string val is_file_owned : Guestfs.guestfs -> Types.inspect -> string -> bool (** Returns true if the file is owned by an installed package. *) + +val is_package_manager_save_file : string -> bool +(** Return true if the filename is something like [*.rpmsave], ie. + a package manager save-file. *) diff --git a/v2v/linux_bootloaders.ml b/v2v/linux_bootloaders.ml index 210cce762..14cd18ad0 100644 --- a/v2v/linux_bootloaders.ml +++ b/v2v/linux_bootloaders.ml @@ -319,9 +319,8 @@ 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 vmlinuzes = List.filter ( - fun file -> not (Str.string_match rex file 0) + fun filename -> not (Linux.is_package_manager_save_file filename) ) vmlinuzes in vmlinuzes