diff options
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/AddDelete.pm | 5 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Error.pm | 34 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackageLocator.pm | 15 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackageRepository.pm | 13 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm | 10 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Temp.pm | 46 |
6 files changed, 67 insertions, 56 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/AddDelete.pm b/usr.sbin/pkg_add/OpenBSD/AddDelete.pm index df8392d22f9..534ce67ac5d 100644 --- a/usr.sbin/pkg_add/OpenBSD/AddDelete.pm +++ b/usr.sbin/pkg_add/OpenBSD/AddDelete.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: AddDelete.pm,v 1.15 2010/01/03 09:34:22 espie Exp $ +# $OpenBSD: AddDelete.pm,v 1.16 2010/01/09 14:49:53 espie Exp $ # # Copyright (c) 2007-2009 Marc Espie <espie@openbsd.org> # @@ -67,7 +67,7 @@ sub do_the_main_work exit(1); } - my $handler = sub { my $sig = shift; die "Caught SIG$sig"; }; + my $handler = sub { my $sig = shift; Fatal "Caught SIG$sig"; }; local $SIG{'INT'} = $handler; local $SIG{'QUIT'} = $handler; local $SIG{'HUP'} = $handler; @@ -107,6 +107,7 @@ sub framework rethrow $dielater; } catch { print STDERR "$0: $_\n"; + OpenBSD::Handler->reset; if ($_ =~ m/^Caught SIG(\w+)/o) { kill $1, $$; } diff --git a/usr.sbin/pkg_add/OpenBSD/Error.pm b/usr.sbin/pkg_add/OpenBSD/Error.pm index 19cc928e51d..b6fba6d2817 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.20 2010/01/05 11:16:08 espie Exp $ +# $OpenBSD: Error.pm,v 1.21 2010/01/09 14:49:53 espie Exp $ # # Copyright (c) 2004-2010 Marc Espie <espie@openbsd.org> # @@ -33,6 +33,36 @@ sub cache(*&) *{$callpkg."::$sym"} = $actual; } +package OpenBSD::Handler; + +my $list = []; + +sub register +{ + my ($class, $code) = @_; + push(@$list, $code); +} + +my $handler = sub { + my $sig = shift; + for my $c (@$list) { + &$c($sig); + } + $SIG{$sig} = 'DEFAULT'; + kill $sig, $$; +}; + +sub reset +{ + $SIG{'INT'} = $handler; + $SIG{'QUIT'} = $handler; + $SIG{'HUP'} = $handler; + $SIG{'KILL'} = $handler; + $SIG{'TERM'} = $handler; +} + +__PACKAGE__->reset; + package OpenBSD::Error; require Exporter; our @ISA=qw(Exporter); @@ -256,7 +286,7 @@ sub dienow { my ($error, $handler) = @_; if ($error) { - if ($error =~ m/^(Expected:\s+)?(.*?)(?:\s+at\s+(.*)\s+line\s+(\d+)\.?)?$/o) { + if ($error =~ m/^(Expected\:\s+)?(.*?)(?:\s+at\s+(.*)\s+line\s+(\d+)\.?)?$/o) { local $_ = $2; $FileName = $3; $Line = $4; diff --git a/usr.sbin/pkg_add/OpenBSD/PackageLocator.pm b/usr.sbin/pkg_add/OpenBSD/PackageLocator.pm index acaa289c70c..f36af899c13 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackageLocator.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackageLocator.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackageLocator.pm,v 1.83 2010/01/09 13:44:57 espie Exp $ +# $OpenBSD: PackageLocator.pm,v 1.84 2010/01/09 14:49:53 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -23,6 +23,10 @@ package OpenBSD::PackageLocator; use OpenBSD::PackageRepositoryList; use OpenBSD::PackageRepository; +# this returns an archive handle from an uninstalled package name, currently +# There is a cache available. + +my %packages; my $pkgpath = OpenBSD::PackageRepositoryList->new; if (defined $ENV{PKG_PATH}) { @@ -53,6 +57,9 @@ sub find { my ($class, $_, $arch) = @_; + if (exists $packages{$_}) { + return $packages{$_}; + } my $package; if (m/[\/\:]/o) { my ($repository, undef, $pkgname) = path_parse($_); @@ -63,6 +70,7 @@ sub find } else { $package = $pkgpath->find($_, $arch); } + $packages{$_} = $package if defined($package); return $package; } @@ -83,11 +91,6 @@ sub grabPlist return $plist; } -sub cleanup -{ - $pkgpath->cleanup; -} - sub match_locations { my ($class, @search) = @_; diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm index e41e683b62d..0cf7f330b7c 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackageRepository.pm,v 1.76 2010/01/09 13:42:03 espie Exp $ +# $OpenBSD: PackageRepository.pm,v 1.77 2010/01/09 14:49:53 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -60,6 +60,17 @@ sub unique return $o; } +my $cleanup = sub { + for my $repo (values %$cache) { + $repo->cleanup; + } +}; +END { + &$cleanup; +} + +OpenBSD::Handler->register($cleanup); + sub parse_fullurl { my ($class, $r) = @_; diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm index 97a5f9f09e4..e5b72cfe3d6 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackageRepositoryList.pm,v 1.20 2010/01/09 13:43:14 espie Exp $ +# $OpenBSD: PackageRepositoryList.pm,v 1.21 2010/01/09 14:49:53 espie Exp $ # # Copyright (c) 2003-2006 Marc Espie <espie@openbsd.org> # @@ -73,14 +73,6 @@ sub match_locations return []; } -sub cleanup -{ - my $self = shift; - for my $repo (@$self) { - $repo->cleanup; - } -} - sub print_without_src { my $self = shift; diff --git a/usr.sbin/pkg_add/OpenBSD/Temp.pm b/usr.sbin/pkg_add/OpenBSD/Temp.pm index 796da4f194c..860b48431b2 100644 --- a/usr.sbin/pkg_add/OpenBSD/Temp.pm +++ b/usr.sbin/pkg_add/OpenBSD/Temp.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Temp.pm,v 1.15 2009/11/10 11:36:56 espie Exp $ +# $OpenBSD: Temp.pm,v 1.16 2010/01/09 14:49:53 espie Exp $ # # Copyright (c) 2003-2005 Marc Espie <espie@openbsd.org> # @@ -28,47 +28,21 @@ our $tempbase = $ENV{'PKG_TMPDIR'} || OpenBSD::Paths->vartmp; my $dirs = {}; my $files = {}; -sub cleanup -{ - my $caught; - my $h = sub { $caught = shift; }; - { - require File::Path; +my $cleanup = sub { + require File::Path; - local $SIG{'INT'} = $h; - local $SIG{'QUIT'} = $h; - local $SIG{'HUP'} = $h; - local $SIG{'KILL'} = $h; - local $SIG{'TERM'} = $h; - - while (my ($name, $pid) = each %$files) { - unlink($name) if $pid == $$; - } - while (my ($dir, $pid) = each %$dirs) { - File::Path::rmtree([$dir]) if $pid == $$; - } + while (my ($name, $pid) = each %$files) { + unlink($name) if $pid == $$; } - if (defined $caught) { - kill $caught, $$; + while (my ($dir, $pid) = each %$dirs) { + File::Path::rmtree([$dir]) if $pid == $$; } -} +}; END { - cleanup(); + &$cleanup; } - -my $handler = sub { - my ($sig) = @_; - cleanup(); - $SIG{$sig} = 'DEFAULT'; - kill $sig, $$; -}; - -$SIG{'INT'} = $handler; -$SIG{'QUIT'} = $handler; -$SIG{'HUP'} = $handler; -$SIG{'KILL'} = $handler; -$SIG{'TERM'} = $handler; +OpenBSD::Handler->register($cleanup); sub dir { |