v2v: linux: Properly ignore rpm/dpkg-move-aside kernels.

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
This commit is contained in:
Richard W.M. Jones
2017-09-21 13:32:09 +01:00
parent 3a4410000e
commit d279d602be
3 changed files with 10 additions and 2 deletions

View File

@@ -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

View File

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

View File

@@ -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