summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2007-05-30 14:04:52 +0000
committerMarc Espie <espie@cvs.openbsd.org>2007-05-30 14:04:52 +0000
commite56a906b41f6a38ce9beeb3f0208dc449668f3ba (patch)
tree3380608fede29f19c94479b8dfbd94ad45d9dfdc /usr.sbin
parentba627c41a7bc412d55590a52ed12eab5be412606 (diff)
simplify really_add to use real visitors for extraction and installation.
Just do one single try {} catchall {} per-method, as this is enough. New methods: extract_and_progress, install_and_progress, that catch interrupts (die) deal with fake, and handle the progress meter. One single method: mark_progress, can be used for extraction, installation and deletion.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Add.pm30
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Delete.pm7
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Replace.pm27
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Vstat.pm17
-rw-r--r--usr.sbin/pkg_add/pkg_add73
5 files changed, 83 insertions, 71 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Add.pm b/usr.sbin/pkg_add/OpenBSD/Add.pm
index a8917d706b8..98075c365b9 100644
--- a/usr.sbin/pkg_add/OpenBSD/Add.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Add.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Add.pm,v 1.64 2007/05/30 13:03:54 espie Exp $
+# $OpenBSD: Add.pm,v 1.65 2007/05/30 14:04:51 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -98,6 +98,22 @@ sub record_partial_installation
return $borked;
}
+sub perform_installation
+{
+ my ($handle, $state) = @_;
+
+ my $totsize = $handle->{totsize};
+ $state->{archive} = $handle->{location};
+ my $donesize = 0;
+ $state->{end_faked} = 0;
+ if (!defined $handle->{partial}) {
+ $handle->{partial} = {};
+ }
+ $state->{partial} = $handle->{partial};
+ $handle->{plist}->install_and_progress($state, \$donesize, $totsize);
+ $handle->{location}->finish_and_close;
+}
+
# used by newuser/newgroup to deal with options.
package OpenBSD::PackingElement;
use OpenBSD::Error;
@@ -108,6 +124,18 @@ sub prepare_for_addition
{
}
+sub install_and_progress
+{
+ my ($self, $state, $donesize, $totsize) = @_;
+ unless ($state->{do_faked} && $state->{end_faked}) {
+ $self->install($state);
+ }
+ if ($state->{interrupted}) {
+ die "Interrupted";
+ }
+ $self->mark_progress($donesize, $totsize);
+}
+
sub install
{
my ($self, $state) = @_;
diff --git a/usr.sbin/pkg_add/OpenBSD/Delete.pm b/usr.sbin/pkg_add/OpenBSD/Delete.pm
index fa919e3cb7a..378b525dc87 100644
--- a/usr.sbin/pkg_add/OpenBSD/Delete.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Delete.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Delete.pm,v 1.52 2007/05/30 12:30:15 espie Exp $
+# $OpenBSD: Delete.pm,v 1.53 2007/05/30 14:04:51 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -145,10 +145,7 @@ sub delete_plist
my $donesize = 0;
for my $item (@{$plist->{groups}}, @{$plist->{users}}, @{$plist->{items}}) {
$item->delete($state);
- if (defined $item->{size}) {
- $donesize += $item->{size};
- OpenBSD::ProgressMeter::show($donesize, $totsize);
- }
+ $item->mark_progress(\$donesize, $totsize);
}
OpenBSD::ProgressMeter::next();
diff --git a/usr.sbin/pkg_add/OpenBSD/Replace.pm b/usr.sbin/pkg_add/OpenBSD/Replace.pm
index 43f50f9b527..7d026bf7b25 100644
--- a/usr.sbin/pkg_add/OpenBSD/Replace.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Replace.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Replace.pm,v 1.24 2007/05/30 13:03:54 espie Exp $
+# $OpenBSD: Replace.pm,v 1.25 2007/05/30 14:04:51 espie Exp $
#
# Copyright (c) 2004-2006 Marc Espie <espie@openbsd.org>
#
@@ -54,6 +54,18 @@ sub unmark_lib
{
}
+sub extract_and_progress
+{
+ require OpenBSD::ProgressMeter;
+
+ my ($self, $state, $donesize, $totsize) = @_;
+ $self->extract($state);
+ if ($state->{interrupted}) {
+ die "Interrupted";
+ }
+ $self->mark_progress($donesize, $totsize);
+}
+
package OpenBSD::PackingElement::FileBase;
use OpenBSD::Temp;
@@ -212,6 +224,19 @@ use OpenBSD::PackageInfo;
use OpenBSD::Error;
use OpenBSD::Interactive;
+sub perform_extraction
+{
+ my ($handle, $state) = @_;
+
+ $handle->{partial} = {};
+ $state->{partial} = $handle->{partial};
+ my $totsize = $handle->{totsize};
+ $state->{archive} = $handle->{location};
+ my $donesize = 0;
+ $state->{donesize} = 0;
+ $handle->{plist}->extract_and_progress($state, \$donesize, $totsize);
+}
+
sub can_do
{
my ($toreplace, $replacement, $state, $ignore) = @_;
diff --git a/usr.sbin/pkg_add/OpenBSD/Vstat.pm b/usr.sbin/pkg_add/OpenBSD/Vstat.pm
index 6ec2a02bc25..961d19c6cd0 100644
--- a/usr.sbin/pkg_add/OpenBSD/Vstat.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Vstat.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Vstat.pm,v 1.29 2007/05/29 10:40:20 espie Exp $
+# $OpenBSD: Vstat.pm,v 1.30 2007/05/30 14:04:51 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -398,4 +398,19 @@ sub handle
}
}
+package OpenBSD::PackingElement;
+sub mark_progress
+{
+}
+
+package OpenBSD::PackingElement::FileBase;
+sub mark_progress
+{
+ my ($self, $donesize, $totsize) = @_;
+ return unless defined $self->{size};
+ require OpenBSD::ProgressMeter;
+ $$donesize += $self->{size};
+ OpenBSD::ProgressMeter::show($$donesize, $totsize);
+}
+
1;
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index f00fd76de3a..0a63799ce94 100644
--- a/usr.sbin/pkg_add/pkg_add
+++ b/usr.sbin/pkg_add/pkg_add
@@ -1,7 +1,7 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_add,v 1.292 2007/05/30 12:52:06 espie Exp $
+# $OpenBSD: pkg_add,v 1.293 2007/05/30 14:04:51 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -383,24 +383,14 @@ sub really_add
OpenBSD::Replace::save_old_libraries($set, $state);
- my $donesize = 0;
- $handle->{partial} = {};
- $state->{partial} = $handle->{partial};
- my $totsize = $handle->{totsize};
- $state->{archive} = $handle->{location};
- for my $item (@{$plist->{items}}) {
- try {
- $item->extract($state);
- } catchall {
+ try {
+ OpenBSD::Replace::perform_extraction($handle, $state);
+ } catchall {
+ unless ($state->{interrupted}) {
Warn $_;
$errors++;
- };
- if (defined $item->{size}) {
- $donesize += $item->{size};
- OpenBSD::ProgressMeter::show($donesize, $totsize);
}
- last if $state->{interrupted} || $errors;
- }
+ };
OpenBSD::ProgressMeter::next();
if ($state->{interrupted} || $errors) {
Fatal partial_install("Installation of $pkgname failed",
@@ -439,58 +429,15 @@ sub really_add
$state->set_pkgname($pkgname);
}
- if ($replacing) {
- try {
- do_script($plist, REQUIRE, $state, "INSTALL");
- do_script($plist, INSTALL, $state, "PRE-INSTALL");
- } catchall {
- Warn $_;
- $errors++;
- };
-
- if ($state->{interrupted} || $errors) {
- # here we should remove links from the temp package
- Fatal partial_install("Installation of $pkgname failed",
- $set, $state);
- }
- } else {
+ try {
do_script($plist, REQUIRE, $state, "INSTALL");
do_script($plist, INSTALL, $state, "PRE-INSTALL");
- }
-
- my $totsize = $handle->{totsize};
- $state->{archive} = $handle->{location};
- my $donesize = 0;
- $state->{end_faked} = 0;
- if (!defined $handle->{partial}) {
- $handle->{partial} = {};
- }
- $state->{partial} = $handle->{partial};
- for my $item (@{$plist->{groups}}, @{$plist->{users}}, @{$plist->{items}}) {
- try {
- $item->install($state); }
- catchall {
+ OpenBSD::Add::perform_installation($handle, $state);
+ } catchall {
+ unless ($state->{interrupted}) {
Warn $_;
$errors++;
- };
- last if $errors;
- if (defined $item->{size}) {
- $donesize += $item->{size};
- OpenBSD::ProgressMeter::show($donesize, $totsize);
- }
-
- last if $state->{interrupted};
- # stop faked installation there...
- if ($state->{do_faked} && $state->{end_faked}) {
- last;
}
- }
-
- try {
- $handle->{location}->finish_and_close; }
- catchall {
- Warn $_;
- $errors++;
};
OpenBSD::ProgressMeter::next();