Skip to content

Commit b3268a1

Browse files
crobinsorwmjones
authored andcommitted
convert: Use yum/apt/... for package removals, not rpm/dpkg
Current package removal implementation uses `rpm -e`, which will fail if anything depends on the package we are trying to remove. Like when `spausedd` is dependent on `open-vm-tools`. Reuse the package uninstall logic from virt-customize, which will handle this no problem. Just print a warning when package removal goes sideways. Fixes: https://issues.redhat.com/browse/RHEL-71522 Signed-off-by: Cole Robinson <[email protected]>
1 parent 17610d1 commit b3268a1

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

convert/convert_linux.ml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,23 @@ let convert (g : G.guestfs) source inspect i_firmware _ keep_serial_console _ =
131131
(*----------------------------------------------------------------------*)
132132
(* Conversion step. *)
133133

134+
let uninstall_packages pkgs =
135+
if pkgs <> [] then (
136+
let cmd =
137+
try Guest_packages.uninstall_command pkgs inspect.i_package_management
138+
with
139+
| Guest_packages.Unknown_package_manager msg
140+
| Guest_packages.Unimplemented_package_manager msg ->
141+
error "%s" msg
142+
in
143+
(try ignore (g#sh cmd)
144+
with G.Error msg ->
145+
warning (f_"could not uninstall packages ‘%s’: %s (ignored)")
146+
(String.concat " " pkgs) msg
147+
)
148+
)
149+
in
150+
134151
let rec do_convert () =
135152
augeas_grub_configuration ();
136153

@@ -237,7 +254,7 @@ let convert (g : G.guestfs) source inspect i_firmware _ keep_serial_console _ =
237254
else
238255
None
239256
) inspect.i_apps in
240-
Linux.remove g inspect.i_root xenmods;
257+
uninstall_packages xenmods;
241258

242259
(* Undo related nastiness if kmod-xenpv was installed. *)
243260
if xenmods <> [] then (
@@ -310,7 +327,7 @@ let convert (g : G.guestfs) source inspect i_firmware _ keep_serial_console _ =
310327
fun { G.app2_name = name } -> name = package_name
311328
) inspect.i_apps in
312329
if has_guest_additions then
313-
Linux.remove g inspect.i_root [package_name];
330+
uninstall_packages [package_name];
314331

315332
(* Guest Additions might have been installed from a tarball. The
316333
* above code won't detect this case. Look for the uninstall tool
@@ -455,8 +472,7 @@ let convert (g : G.guestfs) source inspect i_firmware _ keep_serial_console _ =
455472
)
456473
);
457474

458-
let remove = !remove in
459-
Linux.remove g inspect.i_root remove;
475+
uninstall_packages !remove;
460476

461477
(* VMware Tools may have been installed from a tarball, so the
462478
* above code won't remove it. Look for the uninstall tool and run
@@ -503,7 +519,7 @@ let convert (g : G.guestfs) source inspect i_firmware _ keep_serial_console _ =
503519
let pkgs = List.map (fun { G.app2_name = name } -> name) pkgs in
504520

505521
if pkgs <> [] then (
506-
Linux.remove g inspect.i_root pkgs;
522+
uninstall_packages pkgs;
507523

508524
(* Installing these guest utilities automatically unconfigures
509525
* ttys in /etc/inittab if the system uses it. We need to put

0 commit comments

Comments
 (0)