diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2010-04-05 13:46:25 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2010-04-05 13:46:25 +0000 |
commit | 0b25817a9bd10b75fc763f9d06bd48fbcbc86bb3 (patch) | |
tree | 5224f859996f05a31a789e270c15631ba3d38540 /usr.sbin/pkg_add | |
parent | 06924fe447438779ac99f4ffb9ebbcce0207ff55 (diff) |
clean-up validate_plists a bit, so that it starts with a clean state.
new feature: if a normal updateset order does not fit, let the user decide
to do a "dangerous update", by deleting older packages first (if they fit).
tweak really_add to do so: move delete old packages out of the way, and add
a new state variable (extracted_first) to distinguish between both replace
modes.
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Add.pm | 4 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Delete.pm | 9 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/UpdateSet.pm | 12 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Vstat.pm | 9 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_add | 63 |
5 files changed, 66 insertions, 31 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Add.pm b/usr.sbin/pkg_add/OpenBSD/Add.pm index 4d81031db82..f65f8022127 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.105 2010/03/22 20:38:44 espie Exp $ +# $OpenBSD: Add.pm,v 1.106 2010/04/05 13:46:24 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -368,7 +368,7 @@ sub install my $fullname = $self->fullname; my $destdir = $state->{destdir}; - if ($state->{replacing}) { + if ($state->{extracted_first}) { if ($state->{not}) { $state->say("moving tempfile -> $destdir$fullname") if $state->verbose >= 5; return; diff --git a/usr.sbin/pkg_add/OpenBSD/Delete.pm b/usr.sbin/pkg_add/OpenBSD/Delete.pm index 20229c33cb7..9413a657db7 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.97 2010/03/22 20:38:44 espie Exp $ +# $OpenBSD: Delete.pm,v 1.98 2010/04/05 13:46:24 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -360,7 +360,12 @@ sub prepare_for_deletion my ($self, $state, $pkgname) = @_; my $fname = $state->{destdir}.$self->fullname; - my $s = $state->vstat->remove($fname, $self->{size}); + my $s; + if ($state->{delete_first}) { + $s = $state->vstat->remove_first($fname, $self->{size}); + } else { + $s = $state->vstat->remove($fname, $self->{size}); + } return unless defined $s; if ($s->ro) { $s->report_ro($state, $fname); diff --git a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm index 32a5de94d81..2cf190eb1b2 100644 --- a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm +++ b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: UpdateSet.pm,v 1.52 2010/03/22 20:38:44 espie Exp $ +# $OpenBSD: UpdateSet.pm,v 1.53 2010/04/05 13:46:24 espie Exp $ # # Copyright (c) 2007-2010 Marc Espie <espie@openbsd.org> # @@ -287,6 +287,7 @@ sub validate_plists { my ($self, $state) = @_; $state->{problems} = 0; + delete $state->{overflow}; for my $o ($self->older_to_do) { require OpenBSD::Delete; @@ -304,6 +305,15 @@ sub validate_plists } if (defined $state->{overflow}) { $state->vstat->tally; + # okay, let's retry the other way around if we haven't yet + if (!defined $state->{delete_first}) { + if ($state->{defines}->{deletefirst} || + $state->confirm("Delete older packages first", 0)) { + $state->{delete_first} = 1; + $state->vstat->drop_changes; + return $self->validate_plists($state); + } + } } if ($state->{problems}) { $state->vstat->drop_changes; diff --git a/usr.sbin/pkg_add/OpenBSD/Vstat.pm b/usr.sbin/pkg_add/OpenBSD/Vstat.pm index ad58d5c693f..efa2c70c7bf 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.56 2010/01/14 19:35:55 espie Exp $ +# $OpenBSD: Vstat.pm,v 1.57 2010/04/05 13:46:24 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -180,6 +180,13 @@ sub remove return defined($size) ? $self->account_later($name, -$size) : undef; } +sub remove_first +{ + my ($self, $name, $size) = @_; + $self->{v}[0]->{$name} = OpenBSD::Vstat::Object->none; + return defined($size) ? $self->account_for($name, -$size) : undef; +} + sub tally { my $self = shift; diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add index 9207b71f281..bec8d4d631f 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.474 2010/03/22 20:38:44 espie Exp $ +# $OpenBSD: pkg_add,v 1.475 2010/04/05 13:46:24 espie Exp $ # # Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org> # @@ -572,6 +572,35 @@ sub check_x509_signature } } +sub delete_old_packages +{ + my ($set, $state) = @_; + + build_before($set->older_to_do); + iterate($set->older_to_do, sub { + return if $state->{size_only}; + my $o = shift; + $set->setup_header($state, $o, "deleting"); + my $oldname = $o->pkgname; + $state->set_name_from_handle($o, '-'); + require OpenBSD::Delete; + try { + OpenBSD::Delete::delete_plist($o->plist, $state); + } catchall { + $state->errprint($_); + Fatal partial_install( + "Deinstallation of $oldname failed", + $set, $state); + }; + + if (defined $state->{updatedepends}) { + delete $state->{updatedepends}->{$oldname}; + } + OpenBSD::PkgCfl::unregister($o->plist, $state); + }); + # Here there should be code to handle old libs +} + sub really_add { my ($set, $state) = @_; @@ -615,7 +644,8 @@ sub really_add OpenBSD::OldLibs->save($set, $state); } - if ($replacing) { + if ($replacing && !$state->{delete_first}) { + $state->{extracted_first} = 1; for my $handle ($set->newer) { next if $state->{size_only}; $set->setup_header($state, $handle, "extracting"); @@ -634,30 +664,12 @@ sub really_add $handle->pkgname." failed", $set, $state); } } + } else { + $state->{extracted_first} = 0; + } - build_before($set->older_to_do); - iterate($set->older_to_do, sub { - return if $state->{size_only}; - my $o = shift; - $set->setup_header($state, $o, "deleting"); - my $oldname = $o->pkgname; - $state->set_name_from_handle($o, '-'); - require OpenBSD::Delete; - try { - OpenBSD::Delete::delete_plist($o->plist, $state); - } catchall { - $state->errprint($_); - Fatal partial_install( - "Deinstallation of $oldname failed", - $set, $state); - }; - - if (defined $state->{updatedepends}) { - delete $state->{updatedepends}->{$oldname}; - } - OpenBSD::PkgCfl::unregister($o->plist, $state); - }); - # Here there should be code to handle old libs + if ($replacing) { + delete_old_packages($set, $state); } iterate($set->newer, sub { @@ -713,6 +725,7 @@ sub really_add if ($state->{repairdependencies}) { $set->{solver}->repair_dependencies($state); } + delete $state->{delete_first}; } sub newer_has_errors |