From 06c92f2cf0084a06787229025d96282ebad9d1c3 Mon Sep 17 00:00:00 2001 From: Aurelien Lefebvre Date: Thu, 29 May 2008 14:35:03 +0200 Subject: [PATCH] Added remove-packages method to URPMI backend --- backends/urpmi/helpers/Makefile.am | 1 + backends/urpmi/helpers/remove-packages.pl | 90 +++++++++++++++++++++++ backends/urpmi/pk-backend-urpmi.c | 16 +++- 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100755 backends/urpmi/helpers/remove-packages.pl diff --git a/backends/urpmi/helpers/Makefile.am b/backends/urpmi/helpers/Makefile.am index 60d86413f..bd31cc5a9 100644 --- a/backends/urpmi/helpers/Makefile.am +++ b/backends/urpmi/helpers/Makefile.am @@ -13,6 +13,7 @@ dist_helper_DATA = \ get-update-detail.pl \ refresh-cache.pl \ install-packages.pl \ + remove-packages.pl \ $(NULL) install-data-hook: diff --git a/backends/urpmi/helpers/remove-packages.pl b/backends/urpmi/helpers/remove-packages.pl new file mode 100755 index 000000000..3be38ea99 --- /dev/null +++ b/backends/urpmi/helpers/remove-packages.pl @@ -0,0 +1,90 @@ +#!/usr/bin/perl + +use strict; + +use lib; +use File::Basename; + +BEGIN { + push @INC, dirname($0); +} + +use urpm; +use urpm::args; +use urpm::media; +use urpm::select; +use urpm::install; +use urpmi_backend::tools; +use perl_packagekit::enums; +use perl_packagekit::prints; + +my $notfound = 0; +my @breaking_pkgs = (); +my $allowdeps_option = 0; +my @pkgid; +my $state = {}; +my $notfound_callback = sub { + $notfound = 1; +}; + +# This script call only be called with two arguments (allow_deps (yes/no) and a package id) +exit if($#ARGV != 1); + +my $urpm = urpm->new_parse_cmdline; +my $urpmi_lock = urpm::lock::urpmi_db($urpm, 'exclusive', wait => 1); +urpm::media::configure($urpm); + +$allowdeps_option = 1 if($ARGV[0] eq "yes"); + +my @pkg_ids = split(/\|/, pop @ARGV); +my @names; +foreach(@pkg_ids) { + my @pkg_id = (split(/;/, $_)); + push @names, $pkg_id[0]; +} + +pk_print_status(PK_STATUS_ENUM_DEP_RESOLVE); + +my @to_remove = urpm::select::find_packages_to_remove($urpm, + $state, + \@names, + callback_notfound => $notfound_callback, + callback_fuzzy => $notfound_callback, + callback_base => sub { + my $urpm = shift @_; + push @breaking_pkgs, @_; + } +); + +if($notfound) { + # printf("Error: package %s not found\n", $pkgid[0]); + pk_print_error(PK_ERROR_ENUM_PACKAGE_NOT_INSTALLED, "Selected package isn't installed on your system"); +} +elsif(@breaking_pkgs) { + # printf("Error: These packages will break your system = \n\t%s\n", join("\n\t", @breaking_pkgs)); + pk_print_error(PK_ERROR_ENUM_CANNOT_REMOVE_SYSTEM_PACKAGE, "Removing selected packages will break your system"); +} +else { + # printf("It's ok, I will remove %s NOW !\n", $pkgid[0]); + # printf("To remove list = \n\t%s\n", join("\n\t", @to_remove)); + if(!$allowdeps_option && $#to_remove > 1) { + pk_print_error(PK_ERROR_ENUM_TRANSACTION_ERROR, "Packages can't be removed because dependencies remove is forbidden"); + # printf("I can't remove, because you don't allow deps remove :'(\n"); + } + else { + # printf("Let's go for removing ...\n"); + pk_print_status(PK_STATUS_ENUM_REMOVE); + urpm::install::install($urpm, + \@to_remove, {}, {}, + callback_report_uninst => sub { + my @return = split(/ /, $_[0]); + # printf("Package\tRemoving\t%s\n", fullname_to_package_id($return[$#return])); + pk_print_package(INFO_REMOVING, fullname_to_package_id($return[$#return]), ""); + } + ); + } +} + +$urpmi_lock->unlock; + +pk_print_status(PK_STATUS_ENUM_FINISHED); diff --git a/backends/urpmi/pk-backend-urpmi.c b/backends/urpmi/pk-backend-urpmi.c index 2ff4ab2f4..a4c1d4cf2 100644 --- a/backends/urpmi/pk-backend-urpmi.c +++ b/backends/urpmi/pk-backend-urpmi.c @@ -161,6 +161,20 @@ backend_install_packages (PkBackend *backend, gchar **package_ids) g_free (package_ids_temp); } +/** + * pk_backend_remove_packages: + */ +static void +backend_remove_packages (PkBackend *backend, gchar **package_ids, gboolean allow_deps, gboolean autoremove) +{ + gchar *package_ids_temp; + + /* send the complete list as stdin */ + package_ids_temp = pk_package_ids_to_text (package_ids, "|"); + pk_backend_spawn_helper (spawn, "remove-packages.pl", pk_backend_bool_to_text (allow_deps), package_ids_temp, NULL); + g_free (package_ids_temp); +} + PK_BACKEND_OPTIONS ( "URPMI", /* description */ @@ -182,7 +196,7 @@ PK_BACKEND_OPTIONS ( backend_install_packages, /* install_packages */ NULL, /* install_signature */ backend_refresh_cache, /* refresh_cache */ - NULL, /* remove_packages */ + backend_remove_packages, /* remove_packages */ NULL, /* repo_enable */ NULL, /* repo_set_data */ NULL, /* resolve */