summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Error.pm47
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackingElement.pm14
-rw-r--r--usr.sbin/pkg_add/pkg_add9
-rw-r--r--usr.sbin/pkg_add/pkg_delete8
4 files changed, 58 insertions, 20 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Error.pm b/usr.sbin/pkg_add/OpenBSD/Error.pm
index 227e56f1317..d5bee2f96c5 100644
--- a/usr.sbin/pkg_add/OpenBSD/Error.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Error.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Error.pm,v 1.2 2004/10/04 12:12:30 espie Exp $
+# $OpenBSD: Error.pm,v 1.3 2004/10/20 11:38:57 espie Exp $
#
# Copyright (c) 2004 Marc Espie <espie@openbsd.org>
#
@@ -68,4 +68,49 @@ sub Warn
print STDERR @_;
}
+sub new
+{
+ my $class = shift;
+ bless {messages=>{}}, $class;
+}
+
+sub set_pkgname
+{
+ my ($self, $pkgname) = @_;
+ $self->{pkgname} = $pkgname;
+ if (!defined $self->{messages}->{$pkgname}) {
+ $self->{messages}->{$pkgname} = [];
+ }
+ $self->{output} = $self->{messages}->{$pkgname};
+}
+
+sub warn
+{
+ &OpenBSD::Error::print;
+}
+
+sub fatal
+{
+ my $self = shift;
+ die ($self->{pkgname}, ':', @_);
+}
+
+sub print
+{
+ my $self = shift;
+ push(@{$self->{output}}, join('', @_));
+}
+
+sub delayed_output
+{
+ my $self = shift;
+ for my $pkg (sort keys %{$self->{messages}}) {
+ my $msgs = $self->{messages}->{$pkg};
+ if (@$msgs > 0) {
+ print "$pkg -------------------\n";
+ print @$msgs;
+ }
+ }
+}
+
1;
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm
index f24f006d705..7d967711c95 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackingElement.pm,v 1.57 2004/10/18 10:51:03 espie Exp $
+# $OpenBSD: PackingElement.pm,v 1.58 2004/10/20 11:38:57 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -1173,23 +1173,13 @@ use OpenBSD::Error;
sub prepare
{
my ($self, $state) = @_;
- unless (defined $state->{display}) {
- require OpenBSD::Temp;
- require File::Temp;
-
- ($state->{display}, $state->{displayname}) = File::Temp::tempfile("display.XXXXXXXXX", DIR => $OpenBSD::Temp::tempbase);
- }
my $fname = $state->{dir}.$self->{name};
open(my $src, '<', $fname) or Fatal "Can't open $fname: $!";
- my $dest = $state->{display};
- local $_;
- print $dest "+-------------- ", $state->{pkgname}, "\n";
while (<$src>) {
next if m/^\+\-+\s*$/;
s/^[+-] //;
- print $dest "| $_";
+ $state->print($_);
}
- print $dest "+-------------- ", $state->{pkgname}, "\n";
}
package OpenBSD::PackingElement::FDISPLAY;
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index fbe18a2c39c..08eaa687c25 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.83 2004/10/19 10:21:49 espie Exp $
+# $OpenBSD: pkg_add,v 1.84 2004/10/20 11:38:57 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -269,7 +269,7 @@ sub install
{
my ($self, $state) = @_;
$self->SUPER::install($state);
- print "You may wish to add ", $self->fullname(), " to /etc/man.conf\n";
+ $state->print("You may wish to add ", $self->fullname(), " to /etc/man.conf\n");
}
package OpenBSD::PackingElement::Manpage;
@@ -420,7 +420,7 @@ if ($opt_x) {
$opt_L = '/usr/local' unless defined $opt_L;
-my $state = {};
+my $state = new OpenBSD::Error;
$state->{cache} = {};
$state->{deptree} = {};
$state->{do_faked} = 0;
@@ -793,7 +793,7 @@ sub really_add($$)
my $pkgname = $plist->pkgname();
$state->{archive} = $handle;
$state->{dir} = $dir;
- $state->{pkgname} = $pkgname;
+ $state->set_pkgname($pkgname);
my $header = $pkgname;
@@ -979,6 +979,7 @@ if (defined $state->{display}) {
my $pager = $ENV{'PAGER'} || "/usr/bin/more";
System("$pager ".$state->{displayname});
}
+$state->delayed_output();
if ($dielater) {
die $dielater;
}
diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete
index 8c02032548b..2d4bf4bd013 100644
--- a/usr.sbin/pkg_add/pkg_delete
+++ b/usr.sbin/pkg_add/pkg_delete
@@ -1,6 +1,6 @@
#!/usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_delete,v 1.60 2004/10/19 09:43:40 espie Exp $
+# $OpenBSD: pkg_delete,v 1.61 2004/10/20 11:38:57 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -415,7 +415,7 @@ sub cleanup
{
my ($self, $state) = @_;
my $fullname = $state->{destdir}.$self->fullname();
- print "You may wish to remove ", $fullname, " from man.conf\n";
+ $state->print("You may wish to remove ", $fullname, " from man.conf\n");
unlink("$fullname/whatis.db");
}
@@ -637,7 +637,7 @@ if ($< && !$forced{nonroot}) {
my %done;
my $removed;
-my $state = {};
+my $state = new OpenBSD::Error;
$state->{not} = $opt_n;
$state->{quick} = $opt_q;
$state->{verbose} = $opt_v >= 2;
@@ -742,6 +742,7 @@ eval {
print $opt_n ? "Pretending to delete " : "Deleting ",
"$pkgname\n";
}
+ $state->set_pkgname($pkgname);
$state->{pkgname_tolog} = $pkgname;
delete_package($pkgname, $state);
delete_installed($pkgname);
@@ -769,6 +770,7 @@ my $logname = OpenBSD::Logger::logname();
if (defined $logname) {
print "Problems logged as $logname\n";
}
+$state->delayed_output();
if ($dielater) {
die $dielater;
}