summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xgurpmi23
-rw-r--r--urpm.pm147
-rw-r--r--urpm/install.pm156
-rw-r--r--urpme3
-rwxr-xr-xurpmi7
5 files changed, 166 insertions, 150 deletions
diff --git a/gurpmi2 b/gurpmi2
index 90be7706..d1edcef3 100755
--- a/gurpmi2
+++ b/gurpmi2
@@ -12,6 +12,7 @@ BEGIN { #- set up a safe path and environment
}
use gurpmi;
+use urpm::install;
use Gtk2;
#- GUI globals
@@ -292,7 +293,7 @@ sub do_install_3 () {
}
sync();
};
- my @l = $urpm->install(
+ my @l = urpm::install::install($urpm,
$set->{remove} || [],
\%transaction_sources_install,
\%transaction_sources,
diff --git a/urpm.pm b/urpm.pm
index d708b755..e0c5a10d 100644
--- a/urpm.pm
+++ b/urpm.pm
@@ -2647,151 +2647,8 @@ sub extract_packages_to_install {
\%inst;
}
-# size of the installation progress bar
-my $progress_size = 45;
-eval {
- require Term::ReadKey;
- ($progress_size) = Term::ReadKey::GetTerminalSize();
- $progress_size -= 35;
- $progress_size < 5 and $progress_size = 5;
-};
-
-# install logger callback
-sub install_logger {
- my ($urpm, $type, $id, $subtype, $amount, $total) = @_;
- my $pkg = defined $id && $urpm->{depslist}[$id];
- my $total_pkg = $urpm->{nb_install};
- local $| = 1;
-
- if ($subtype eq 'start') {
- $urpm->{logger_progress} = 0;
- if ($type eq 'trans') {
- $urpm->{logger_id} ||= 0;
- $urpm->{logger_count} ||= 0;
- my $p = N("Preparing...");
- print $p, " " x (33 - length $p);
- } else {
- ++$urpm->{logger_id};
- my $pname = $pkg ? $pkg->name : '';
- ++$urpm->{logger_count} if $pname;
- my $cnt = $pname ? $urpm->{logger_count} : '-';
- $pname ||= N("[repackaging]");
- printf "%9s: %-22s", $cnt . "/" . $total_pkg, $pname;
- }
- } elsif ($subtype eq 'stop') {
- if ($urpm->{logger_progress} < $progress_size) {
- print '#' x ($progress_size - $urpm->{logger_progress}), "\n";
- $urpm->{logger_progress} = 0;
- }
- } elsif ($subtype eq 'progress') {
- my $new_progress = $total > 0 ? int($progress_size * $amount / $total) : $progress_size;
- if ($new_progress > $urpm->{logger_progress}) {
- print '#' x ($new_progress - $urpm->{logger_progress});
- $urpm->{logger_progress} = $new_progress;
- $urpm->{logger_progress} == $progress_size and print "\n";
- }
- }
-}
-
-#- install packages according to each hash (remove, install or upgrade).
-#- options:
-#- test, excludepath, nodeps, noorder (unused), delta,
-#- callback_open, callback_close, callback_inst, callback_trans, post_clean_cache
-#- (more options for trans->run)
-#- excludedocs, nosize, noscripts, oldpackage, repackage, ignorearch
-sub install {
- my ($urpm, $remove, $install, $upgrade, %options) = @_;
- my %readmes;
- $options{translate_message} = 1;
-
- my $db = db_open_or_die($urpm, $urpm->{root}, !$options{test}); #- open in read/write mode unless testing installation.
-
- my $trans = $db->create_transaction($urpm->{root});
- if ($trans) {
- sys_log("transaction on %s (remove=%d, install=%d, upgrade=%d)", $urpm->{root} || '/', scalar(@{$remove || []}), scalar(values %$install), scalar(values %$upgrade));
- $urpm->{log}(N("created transaction for installing on %s (remove=%d, install=%d, upgrade=%d)", $urpm->{root} || '/',
- scalar(@{$remove || []}), scalar(values %$install), scalar(values %$upgrade)));
- } else {
- return N("unable to create transaction");
- }
-
- my ($update, @l) = 0;
- my @produced_deltas;
-
- foreach (@$remove) {
- if ($trans->remove($_)) {
- $urpm->{log}(N("removing package %s", $_));
- } else {
- $urpm->{error}(N("unable to remove package %s", $_));
- }
- }
- foreach my $mode ($install, $upgrade) {
- foreach (keys %$mode) {
- my $pkg = $urpm->{depslist}[$_];
- $pkg->update_header($mode->{$_});
- if ($pkg->payload_format eq 'drpm') { #- handle deltarpms
- my $true_rpm = urpm::sys::apply_delta_rpm($mode->{$_}, "$urpm->{cachedir}/rpms", $pkg);
- if ($true_rpm) {
- push @produced_deltas, ($mode->{$_} = $true_rpm); #- fix path
- } else {
- $urpm->{error}(N("unable to extract rpm from delta-rpm package %s", $mode->{$_}));
- }
- }
- if ($trans->add($pkg, update => $update,
- $options{excludepath} ? (excludepath => [ split /,/, $options{excludepath} ]) : ()
- )) {
- $urpm->{log}(N("adding package %s (id=%d, eid=%d, update=%d, file=%s)", scalar($pkg->fullname),
- $_, $pkg->id, $update, $mode->{$_}));
- } else {
- $urpm->{error}(N("unable to install package %s", $mode->{$_}));
- }
- }
- ++$update;
- }
- if (($options{nodeps} || !(@l = $trans->check(%options))) && ($options{noorder} || !(@l = $trans->order))) {
- my $fh;
- #- assume default value for some parameter.
- $options{delta} ||= 1000;
- $options{callback_open} ||= sub {
- my ($_data, $_type, $id) = @_;
- $fh = urpm::sys::open_safe($urpm, '<', $install->{$id} || $upgrade->{$id});
- $fh ? fileno $fh : undef;
- };
- $options{callback_close} ||= sub {
- my ($urpm, undef, $pkgid) = @_;
- return unless defined $pkgid;
- my $pkg = $urpm->{depslist}[$pkgid];
- my $fullname = $pkg->fullname;
- my $trtype = (grep { /\Q$fullname\E/ } values %$install) ? 'install' : '(upgrade|update)';
- foreach ($pkg->files) { /\bREADME(\.$trtype)?\.urpmi$/ and $readmes{$_} = $fullname }
- close $fh if defined $fh;
- };
- if ($::verbose >= 0 && (scalar keys %$install || scalar keys %$upgrade)) {
- $options{callback_inst} ||= \&install_logger;
- $options{callback_trans} ||= \&install_logger;
- }
- @l = $trans->run($urpm, %options);
-
- #- don't clear cache if transaction failed. We might want to retry.
- if (@l == 0 && !$options{test} && $options{post_clean_cache}) {
- #- examine the local cache to delete packages which were part of this transaction
- foreach (keys %$install, keys %$upgrade) {
- my $pkg = $urpm->{depslist}[$_];
- unlink "$urpm->{cachedir}/rpms/" . $pkg->filename;
- }
- }
- }
- unlink @produced_deltas;
-
- if ($::verbose >= 0) {
- foreach (keys %readmes) {
- print "-" x 70, "\n", N("More information on package %s", $readmes{$_}), "\n";
- print cat_($_);
- print "-" x 70, "\n";
- }
- }
- @l;
-}
+#- deprecated
+sub install { require urpm::install; &urpm::install::install }
#- find packages to remove.
#- options:
diff --git a/urpm/install.pm b/urpm/install.pm
new file mode 100644
index 00000000..c17c72f6
--- /dev/null
+++ b/urpm/install.pm
@@ -0,0 +1,156 @@
+package urpm::install;
+
+# $Id$
+
+use urpm;
+use urpm::msg;
+use urpm::util;
+
+
+# size of the installation progress bar
+my $progress_size = 45;
+eval {
+ require Term::ReadKey;
+ ($progress_size) = Term::ReadKey::GetTerminalSize();
+ $progress_size -= 35;
+ $progress_size < 5 and $progress_size = 5;
+};
+
+# install logger callback
+sub install_logger {
+ my ($urpm, $type, $id, $subtype, $amount, $total) = @_;
+ my $pkg = defined $id && $urpm->{depslist}[$id];
+ my $total_pkg = $urpm->{nb_install};
+ local $| = 1;
+
+ if ($subtype eq 'start') {
+ $urpm->{logger_progress} = 0;
+ if ($type eq 'trans') {
+ $urpm->{logger_id} ||= 0;
+ $urpm->{logger_count} ||= 0;
+ my $p = N("Preparing...");
+ print $p, " " x (33 - length $p);
+ } else {
+ ++$urpm->{logger_id};
+ my $pname = $pkg ? $pkg->name : '';
+ ++$urpm->{logger_count} if $pname;
+ my $cnt = $pname ? $urpm->{logger_count} : '-';
+ $pname ||= N("[repackaging]");
+ printf "%9s: %-22s", $cnt . "/" . $total_pkg, $pname;
+ }
+ } elsif ($subtype eq 'stop') {
+ if ($urpm->{logger_progress} < $progress_size) {
+ print '#' x ($progress_size - $urpm->{logger_progress}), "\n";
+ $urpm->{logger_progress} = 0;
+ }
+ } elsif ($subtype eq 'progress') {
+ my $new_progress = $total > 0 ? int($progress_size * $amount / $total) : $progress_size;
+ if ($new_progress > $urpm->{logger_progress}) {
+ print '#' x ($new_progress - $urpm->{logger_progress});
+ $urpm->{logger_progress} = $new_progress;
+ $urpm->{logger_progress} == $progress_size and print "\n";
+ }
+ }
+}
+
+#- install packages according to each hash (remove, install or upgrade).
+#- options:
+#- test, excludepath, nodeps, noorder (unused), delta,
+#- callback_open, callback_close, callback_inst, callback_trans, post_clean_cache
+#- (more options for trans->run)
+#- excludedocs, nosize, noscripts, oldpackage, repackage, ignorearch
+sub install {
+ my ($urpm, $remove, $install, $upgrade, %options) = @_;
+ my %readmes;
+ $options{translate_message} = 1;
+
+ my $db = urpm::db_open_or_die($urpm, $urpm->{root}, !$options{test}); #- open in read/write mode unless testing installation.
+
+ my $trans = $db->create_transaction($urpm->{root});
+ if ($trans) {
+ sys_log("transaction on %s (remove=%d, install=%d, upgrade=%d)", $urpm->{root} || '/', scalar(@{$remove || []}), scalar(values %$install), scalar(values %$upgrade));
+ $urpm->{log}(N("created transaction for installing on %s (remove=%d, install=%d, upgrade=%d)", $urpm->{root} || '/',
+ scalar(@{$remove || []}), scalar(values %$install), scalar(values %$upgrade)));
+ } else {
+ return N("unable to create transaction");
+ }
+
+ my ($update, @l) = 0;
+ my @produced_deltas;
+
+ foreach (@$remove) {
+ if ($trans->remove($_)) {
+ $urpm->{log}(N("removing package %s", $_));
+ } else {
+ $urpm->{error}(N("unable to remove package %s", $_));
+ }
+ }
+ foreach my $mode ($install, $upgrade) {
+ foreach (keys %$mode) {
+ my $pkg = $urpm->{depslist}[$_];
+ $pkg->update_header($mode->{$_});
+ if ($pkg->payload_format eq 'drpm') { #- handle deltarpms
+ my $true_rpm = urpm::sys::apply_delta_rpm($mode->{$_}, "$urpm->{cachedir}/rpms", $pkg);
+ if ($true_rpm) {
+ push @produced_deltas, ($mode->{$_} = $true_rpm); #- fix path
+ } else {
+ $urpm->{error}(N("unable to extract rpm from delta-rpm package %s", $mode->{$_}));
+ }
+ }
+ if ($trans->add($pkg, update => $update,
+ $options{excludepath} ? (excludepath => [ split /,/, $options{excludepath} ]) : ()
+ )) {
+ $urpm->{log}(N("adding package %s (id=%d, eid=%d, update=%d, file=%s)", scalar($pkg->fullname),
+ $_, $pkg->id, $update, $mode->{$_}));
+ } else {
+ $urpm->{error}(N("unable to install package %s", $mode->{$_}));
+ }
+ }
+ ++$update;
+ }
+ if (($options{nodeps} || !(@l = $trans->check(%options))) && ($options{noorder} || !(@l = $trans->order))) {
+ my $fh;
+ #- assume default value for some parameter.
+ $options{delta} ||= 1000;
+ $options{callback_open} ||= sub {
+ my ($_data, $_type, $id) = @_;
+ $fh = urpm::sys::open_safe($urpm, '<', $install->{$id} || $upgrade->{$id});
+ $fh ? fileno $fh : undef;
+ };
+ $options{callback_close} ||= sub {
+ my ($urpm, undef, $pkgid) = @_;
+ return unless defined $pkgid;
+ my $pkg = $urpm->{depslist}[$pkgid];
+ my $fullname = $pkg->fullname;
+ my $trtype = (grep { /\Q$fullname\E/ } values %$install) ? 'install' : '(upgrade|update)';
+ foreach ($pkg->files) { /\bREADME(\.$trtype)?\.urpmi$/ and $readmes{$_} = $fullname }
+ close $fh if defined $fh;
+ };
+ if ($::verbose >= 0 && (scalar keys %$install || scalar keys %$upgrade)) {
+ $options{callback_inst} ||= \&install_logger;
+ $options{callback_trans} ||= \&install_logger;
+ }
+ @l = $trans->run($urpm, %options);
+
+ #- don't clear cache if transaction failed. We might want to retry.
+ if (@l == 0 && !$options{test} && $options{post_clean_cache}) {
+ #- examine the local cache to delete packages which were part of this transaction
+ foreach (keys %$install, keys %$upgrade) {
+ my $pkg = $urpm->{depslist}[$_];
+ unlink "$urpm->{cachedir}/rpms/" . $pkg->filename;
+ }
+ }
+ }
+ unlink @produced_deltas;
+
+ if ($::verbose >= 0) {
+ foreach (keys %readmes) {
+ print "-" x 70, "\n", N("More information on package %s", $readmes{$_}), "\n";
+ print cat_($_);
+ print "-" x 70, "\n";
+ }
+ }
+ @l;
+}
+
+1;
diff --git a/urpme b/urpme
index be067040..6cd94f03 100644
--- a/urpme
+++ b/urpme
@@ -23,6 +23,7 @@ use strict;
use urpm;
use urpm::args;
use urpm::msg;
+use urpm::install;
$ENV{PATH} = "/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin";
delete @ENV{qw(ENV BASH_ENV IFS CDPATH)};
@@ -137,7 +138,7 @@ print N("removing %s", join(' ', sort @toremove)) . "\n";
noscripts => $noscripts,
repackage => $repackage || $urpm->{options}{repackage},
)
- : $urpm->install(
+ : urpm::install::install($urpm,
\@toremove, {}, {},
test => $test,
force => $force,
diff --git a/urpmi b/urpmi
index 5a59197f..fb827a5f 100755
--- a/urpmi
+++ b/urpmi
@@ -23,6 +23,7 @@ use strict;
use urpm;
use urpm::args;
use urpm::msg;
+use urpm::install;
use urpm::util qw(untaint difference2 member);
#- contains informations to parse installed system.
@@ -722,7 +723,7 @@ foreach my $set (@{$state->{transaction} || []}) {
ignorearch => $urpm->{options}{ignorearch},
noscripts => $urpm->{options}{noscripts},
);
- my @l = $urpm->install(
+ my @l = urpm::install::install($urpm,
$to_remove,
\%transaction_sources_install, \%transaction_sources,
%install_options_common,
@@ -739,7 +740,7 @@ foreach my $set (@{$state->{transaction} || []}) {
message_input(N("Try installation without checking dependencies? (y/N) "),
$force && $yesexpr, boolean => 1) =~ /[$yesexpr]/ or ++$nok, next;
$urpm->{log}("starting installing packages without deps");
- @l = $urpm->install(
+ @l = urpm::install::install($urpm,
$to_remove,
\%transaction_sources_install, \%transaction_sources,
nodeps => 1,
@@ -756,7 +757,7 @@ foreach my $set (@{$state->{transaction} || []}) {
message_input(N("Try harder to install (--force)? (y/N) "),
$force && $yesexpr, boolean => 1) =~ /[$yesexpr]/ or ++$nok, next;
$urpm->{log}("starting force installing packages without deps");
- @l = $urpm->install(
+ @l = urpm::install::install($urpm,
$to_remove,
\%transaction_sources_install, \%transaction_sources,
nodeps => 1, force => 1,