diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2004-12-18 13:20:55 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2004-12-18 13:20:55 +0000 |
commit | 72221c1df53de3185949c350d7046bd41c0b75db (patch) | |
tree | 6f154bf6cfbf42e53d8ca95c3c56f651a681b20a | |
parent | d425c65ef5f82202acde49dd096f1e880d3614f1 (diff) |
basic code to handle legacy .libs-* packages: figure out what collisions
the new package actually has with old libs. If none is found, we can
proceed.
Prepare pkg_add to deal with it: switch into replacing mode as soon
as something fishy is going on.
Todo: code to actually delete replaced libraries.
Please note: if you don't play games such as going back to old packages
using replace, this code is enough.
If you update your whole system and remove old .libs-* package without
going back, this code isn't even needed...
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Update.pm | 66 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_add | 70 |
2 files changed, 115 insertions, 21 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Update.pm b/usr.sbin/pkg_add/OpenBSD/Update.pm index 9da4bba7e38..8598dd07b08 100644 --- a/usr.sbin/pkg_add/OpenBSD/Update.pm +++ b/usr.sbin/pkg_add/OpenBSD/Update.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Update.pm,v 1.40 2004/12/15 01:07:10 espie Exp $ +# $OpenBSD: Update.pm,v 1.41 2004/12/18 13:20:54 espie Exp $ # # Copyright (c) 2004 Marc Espie <espie@openbsd.org> # @@ -442,4 +442,68 @@ sub is_needed return join(',', sort keys %$new_context) ne join(',', sort keys %$old_context); } + +sub figure_out_libs +{ + my ($plist, $state, @libs) = @_; + + my $has = {}; + my $result = []; + + for my $item (@{$plist->{items}}) { + $has->{$item->fullname()} = 1; + } + + for my $oldlib (@libs) { + print "Checking for collisions with $oldlib... " + if $state->{verbose}; + +# require OpenBSD::RequiredBy; +# +# if (OpenBSD::RequiredBy->new($oldlib)->list() == 0) { +# require OpenBSD::Delete; +# +# OpenBSD::Delete::delete_package($oldlib, $state); +# delete_installed($oldlib); +# next; +# } + + my $p = OpenBSD::PackingList->from_installation($oldlib); + my $n = []; + my $delete = []; + my $empty = 1; + my $doit = 0; + for my $file (@{$p->{items}}) { + if ($file->IsFile()) { + if ($has->{$file->fullname()}) { + $doit = 1; + push(@$delete, $file); + next; + } else { + $empty = 0; + } + } + push(@$n, $file); + } + $p->{items} = $n; + if ($doit) { + print "some found\n" if $state->{verbose}; + my $dummy = {items => $delete}; + push(@$result, + { plist => $p, + todelete => $dummy, + empty => $empty}); + require OpenBSD::Delete; + OpenBSD::Delete::validate_plist($dummy, $state); + } else { + print "none found\n" if $state->{verbose}; + } + } + if (@$result) { + $plist->{old_libs} = $result; + return 0; + } + return 1; +} + 1; diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add index 72fdc502ed6..8f2ecbd3611 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.146 2004/12/17 11:30:28 espie Exp $ +# $OpenBSD: pkg_add,v 1.147 2004/12/18 13:20:53 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -95,15 +95,36 @@ sub can_install($$$) } } - @conflicts = keys %conflicts; - if (!$state->{replace} || @conflicts >= 2) { - print "Can't install $pkgname because of conflicts (",join(',', @conflicts), ")\n"; + my @libs = (); + @conflicts = (); + for my $k (keys %conflicts) { + if ($k =~ m/^\.libs\-/) { + push(@libs, $k); + } else { + push(@conflicts, $k); + } + } + + if (!$state->{replace}) { + print "Can't install $pkgname because of conflicts (",join(',', @conflicts, @libs), ")\n"; + $errors++; + return undef; + } + + if (@conflicts >= 2) { + print "Can't install $pkgname because of conflicts (",join(',', @conflicts, @libs), ")\n"; $errors++; return undef; } require OpenBSD::Update; + if (!OpenBSD::Update::figure_out_libs($plist, $state, @libs)) { + print "Can't update to $pkgname because of collision with old libs\n"; + $errors++; + return undef; + } + my $rplist = OpenBSD::Update::can_do($conflicts[0], $pkgname, $state); if ($rplist) { if (!OpenBSD::Update::is_safe($plist, $state)) { @@ -267,10 +288,12 @@ sub really_add($$) $state->{archive} = $handle; $plist->{dir} = $dir; $state->set_pkgname($pkgname); + $state->{replacing} = 0; if (defined $plist->{replacing}) { $state->{replacing} = 1; - } else { - $state->{replacing} = 0; + } + if (defined $plist->{old_libs}) { + $state->{replacing} = 1; } my $header = $pkgname; @@ -302,11 +325,15 @@ sub really_add($$) $interrupted = 1; }; - if (defined $plist->{replacing}) { + if ($state->{replacing} == 1) { require OpenBSD::Update; OpenBSD::ProgressMeter::set_header("$pkgname (extracting)"); - OpenBSD::Update::save_old_libraries($plist, $state); + + if (defined $plist->{replacing}) { + OpenBSD::Update::save_old_libraries($plist, $state); + } + my $donesize = 0; $plist->{done} = []; for my $item (@{$plist->{items}}) { @@ -329,19 +356,22 @@ sub really_add($$) "Installation of $pkgname failed"); } - OpenBSD::ProgressMeter::set_header($plist->{replacing}->pkgname()." (deleting)"); - $state->set_pkgname($plist->{replacing}->pkgname()); - require OpenBSD::Delete; - try { - OpenBSD::Delete::delete_plist($plist->{replacing}, $state); - } catchall { - Warn $_; - OpenBSD::Add::borked_installation($plist, $dir, - "Deinstallation of ", - $plist->{replacing}->pkgname(), " failed"); - }; + if (defined $plist->{replacing}) { + OpenBSD::ProgressMeter::set_header($plist->{replacing}->pkgname()." (deleting)"); + $state->set_pkgname($plist->{replacing}->pkgname()); + require OpenBSD::Delete; + try { + OpenBSD::Delete::delete_plist($plist->{replacing}, $state); + } catchall { + Warn $_; + OpenBSD::Add::borked_installation($plist, $dir, + "Deinstallation of ", + $plist->{replacing}->pkgname(), " failed"); + }; - delete_installed($plist->{replacing}->pkgname()); + delete_installed($plist->{replacing}->pkgname()); + } + # Here there should be code to handle old libs OpenBSD::ProgressMeter::set_header("$pkgname (installing)"); $state->set_pkgname($pkgname); |