diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2007-06-10 15:11:06 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2007-06-10 15:11:06 +0000 |
commit | 4366ccacdb906baa08223213087a3ffc7892ff35 (patch) | |
tree | dbcfc3ff22d8026f35920ed68a6be636816e2683 | |
parent | 221436f0af147f7497bd167cb6a164fce6120588 (diff) |
make the replacement check methods slightly clearer, avoid doing two
things at once, mostly.
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Replace.pm | 24 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_add | 19 |
2 files changed, 21 insertions, 22 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Replace.pm b/usr.sbin/pkg_add/OpenBSD/Replace.pm index b64aa60b27f..f31443359df 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.39 2007/06/09 11:16:54 espie Exp $ +# $OpenBSD: Replace.pm,v 1.40 2007/06/10 15:11:05 espie Exp $ # # Copyright (c) 2004-2006 Marc Espie <espie@openbsd.org> # @@ -285,19 +285,16 @@ sub perform_extraction $handle->{plist}->extract_and_progress($state, \$donesize, $totsize); } -sub can_do +sub can_old_package_be_replaced { - my ($toreplace, $replacement, $state, $ignore) = @_; + my ($old_plist, $new_pkgname, $state, $ignore) = @_; $state->{okay} = 1; - my $plist = OpenBSD::PackingList->from_installation($toreplace); - if (!defined $plist) { - Fatal "Couldn't find packing-list for $toreplace\n"; - } $state->{journal} = []; - $plist->can_update(0, $state); + $old_plist->can_update(0, $state); if ($state->{okay} == 0) { - Warn "Old package ", $plist->pkgname, " contains potentially unsafe operations\n"; + Warn "Old package ", $old_plist->pkgname, + " contains potentially unsafe operations\n"; for my $i (@{$state->{journal}}) { Warn "\t$i\n"; } @@ -311,7 +308,7 @@ sub can_do } } } - my @wantlist = OpenBSD::RequiredBy->new($toreplace)->list; + my @wantlist = OpenBSD::RequiredBy->new($old_plist->pkgname)->list; my @r = (); for my $wanting (@wantlist) { push(@r, $wanting) if !defined $ignore->{$wanting}; @@ -326,15 +323,14 @@ sub can_do Warn "Error: $wanting missing from installation\n" } else { $p2->validate_depend($state, $wanting, - $toreplace, $replacement); + $old_plist->pkgname, $new_pkgname); } } } - - return $state->{okay} ? $plist : 0; + return $state->{okay}; } -sub is_safe +sub is_new_package_safe { my ($plist, $state) = @_; $state->{okay} = 1; diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add index 87d0927159f..2d478072b07 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.317 2007/06/10 14:52:29 espie Exp $ +# $OpenBSD: pkg_add,v 1.318 2007/06/10 15:11:05 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -152,7 +152,7 @@ sub can_install require OpenBSD::Replace; - if (!OpenBSD::Replace::is_safe($plist, $state)) { + if (!OpenBSD::Replace::is_new_package_safe($plist, $state)) { print "Can't safely update to $pkgname (use -F update to force it)\n"; $handle->set_error(OpenBSD::Handle::CANT_INSTALL); return; @@ -165,9 +165,12 @@ sub can_install return; } - my $rplist = OpenBSD::Replace::can_do($toreplace, $pkgname, - $state, \%conflicts); - if (!$rplist) { + my $rplist = OpenBSD::PackingList->from_installation($toreplace); + if (!defined $rplist) { + Fatal "Couldn't find packing-list for $toreplace\n"; + } + if (!OpenBSD::Replace::can_old_package_be_replaced($rplist, + $pkgname, $state, \%conflicts)) { print "Can't update $toreplace into $pkgname\n"; $handle->set_error(OpenBSD::Handle::CANT_INSTALL); return; @@ -187,11 +190,10 @@ sub can_install sub create_handle { - my ($pkg, $state) = @_; + my $pkg = shift; my $handle = OpenBSD::Handle->new; $handle->{pkgname} = $pkg; $handle->{tweaked} = 0; - $handle->complete($state); return $handle; } @@ -200,8 +202,9 @@ sub prepare_to_add my ($pkg, $state) = @_; my $set = OpenBSD::UpdateSet->new; - my $handle = create_handle($pkg, $state); + my $handle = create_handle($pkg); $set->add_newer($handle); + $handle->complete($state); if ($handle->has_error) { return $set; } |