summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2008-06-21 14:01:11 +0000
committerMarc Espie <espie@cvs.openbsd.org>2008-06-21 14:01:11 +0000
commitba611d76d5d400a1020fe2602750c348f1adf039 (patch)
tree66b37b06b537244376b996a62524011caed870da
parentb1b7d5ce1db67cf7638bd86d79dd02b5ac64df57 (diff)
rework collisionreport to allow some limited repair capabilities:
assuming none of the files is registered, we can assume that the package registration fails, and then we remove the files, and install the package. Then we also walk installed packages to restore dependencies that would have been erased (this is fairly simple-minded and may fail in weird cases).
-rw-r--r--usr.sbin/pkg_add/OpenBSD/CollisionReport.pm117
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Dependencies.pm29
-rw-r--r--usr.sbin/pkg_add/pkg_add12
3 files changed, 115 insertions, 43 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/CollisionReport.pm b/usr.sbin/pkg_add/OpenBSD/CollisionReport.pm
index 3f4697d92ab..f0cf0969fb4 100644
--- a/usr.sbin/pkg_add/OpenBSD/CollisionReport.pm
+++ b/usr.sbin/pkg_add/OpenBSD/CollisionReport.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: CollisionReport.pm,v 1.17 2008/06/21 12:41:55 espie Exp $
+# $OpenBSD: CollisionReport.pm,v 1.18 2008/06/21 14:01:10 espie Exp $
#
# Copyright (c) 2003-2006 Marc Espie <espie@openbsd.org>
#
@@ -22,63 +22,73 @@ use OpenBSD::PackingList;
use OpenBSD::PackageInfo;
use OpenBSD::Vstat;
+sub find_collisions
+{
+ my ($todo, $verbose) = @_;
+ my $bypkg = {};
+ for my $name (keys %$todo) {
+ my $p = OpenBSD::Vstat::vexists $name;
+ if (ref $p) {
+ my $pkg = $$p;
+ push(@{$bypkg->{$pkg}}, $name);
+ delete $todo->{$name};
+ }
+ }
+
+
+ if (!%$todo) {
+ return $bypkg;
+ }
+ for my $pkg (installed_packages()) {
+ print "Looking for collisions in $pkg\n" if $verbose;
+ my $plist = OpenBSD::PackingList->from_installation($pkg,
+ \&OpenBSD::PackingList::FilesOnly);
+ next if !defined $plist;
+ for my $item (@{$plist->{items}}) {
+ next unless $item->IsFile;
+ my $name = $item->fullname;
+ if (defined $todo->{$name}) {
+ push(@{$bypkg->{$pkg}}, $name);
+ delete $todo->{$name};
+ return $bypkg;
+ }
+ }
+ }
+ return $bypkg;
+}
sub collision_report($$)
{
my ($list, $state) = @_;
if ($state->{defines}->{removecollisions}) {
+ require OpenBSD::Error;
for my $f (@$list) {
- print "rm ", $f->fullname, "\n";
- unlink($f->fullname);
+ OpenBSD::Error::Unlink(1, $f->fullname);
}
return;
}
my %todo = map {($_->fullname, $_->{md5})} @$list;
- my $bypkg = {};
my $clueless_bat;
my $clueless_bat2;
+ my $found = 0;
print "Collision: the following files already exist\n";
- for my $name (keys %todo) {
- my $p = OpenBSD::Vstat::vexists $name;
- if (ref $p) {
- my $pkg = $$p;
- push(@{$bypkg->{$pkg}}, $name);
- delete $todo{$name};
+ if (!$state->{defines}->{dontfindcollisions}) {
+ my $bypkg = find_collisions(\%todo, $state->{verbose});
+ for my $pkg (sort keys %$bypkg) {
+ for my $item (sort @{$bypkg->{$pkg}}) {
+ $found++;
+ print "\t$item ($pkg)\n";
+ }
+ if ($pkg =~ m/^(?:partial\-|borked\.\d+$)/o) {
+ $clueless_bat = $pkg;
+ }
+ if ($pkg =~ m/^\.libs\d*-*$/o) {
+ $clueless_bat2 = $pkg;
+ }
}
}
-
- if (%todo) {
- BIGLOOP: {
- for my $pkg (installed_packages()) {
- print "Looking for collisions in $pkg\n" if $state->{verbose};
- my $plist = OpenBSD::PackingList->from_installation($pkg,
- \&OpenBSD::PackingList::FilesOnly);
- next if !defined $plist;
- for my $item (@{$plist->{items}}) {
- next unless $item->IsFile;
- my $name = $item->fullname;
- if (defined $todo{$name}) {
- push(@{$bypkg->{$pkg}}, $name);
- delete $todo{$name};
- last BIGLOOP if !%todo;
- }
- }
- }
- }
- }
- for my $pkg (sort keys %$bypkg) {
- for my $item (sort @{$bypkg->{$pkg}}) {
- print "\t$item ($pkg)\n";
- }
- if ($pkg =~ m/^(?:partial\-|borked\.\d+$)/o) {
- $clueless_bat = $pkg;
- }
- if ($pkg =~ m/^\.libs\d*-*$/o) {
- $clueless_bat2 = $pkg;
- }
- }
if (%todo) {
require OpenBSD::md5;
my $destdir = $state->{destdir};
@@ -108,6 +118,31 @@ sub collision_report($$)
print "\tpkg_delete $clueless_bat2\n";
print "will solve the problem\n";
}
+ my $dorepair = 0;
+ if ($found == 0) {
+ if ($state->{defines}->{repair}) {
+ $dorepair = 1;
+ } elsif ($state->{interactive}) {
+ require OpenBSD::Interactive;
+ if (OpenBSD::Interactive::confirm(
+ "It seems to be a missing package registration\nRepair", 1, 0)) {
+ $dorepair = 1;
+ }
+ }
+ }
+ if ($dorepair == 1) {
+ require OpenBSD::Error;
+ for my $f (@$list) {
+
+ if (OpenBSD::Error::Unlink($state->{verbose},
+ $f->fullname)) {
+ $state->{problems}--;
+ } else {
+ return;
+ }
+ }
+ $state->{repairdependencies} = 1;
+ }
}
1;
diff --git a/usr.sbin/pkg_add/OpenBSD/Dependencies.pm b/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
index 8cf4115a1bf..70affdc1493 100644
--- a/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Dependencies.pm,v 1.63 2008/06/11 12:43:13 espie Exp $
+# $OpenBSD: Dependencies.pm,v 1.64 2008/06/21 14:01:10 espie Exp $
#
# Copyright (c) 2005-2007 Marc Espie <espie@openbsd.org>
#
@@ -402,6 +402,17 @@ sub adjust_old_dependencies
}
}
+sub repair_dependencies
+{
+ my ($self, $state) = @_;
+ my $pkgname = $self->{set}->handle->{pkgname};
+ for my $pkg (installed_packages(1)) {
+ my $plist = OpenBSD::PackingList->from_installation($pkg,
+ \&OpenBSD::PackingList::DependOnly);
+ $plist->repair_dependency($pkg, $pkgname);
+ }
+}
+
use OpenBSD::SharedLibs;
sub check_lib_spec
@@ -479,4 +490,20 @@ sub solve_tags
return $okay;
}
+package OpenBSD::PackingElement;
+sub repair_dependency
+{
+}
+
+package OpenBSD::PackingElement::Dependency;
+sub repair_dependency
+{
+ my ($self, $requiring, $required) = @_;
+ if ($self->spec->filter($required) == 1) {
+ require OpenBSD::RequiredBy;
+ OpenBSD::RequiredBy->new($required)->add($requiring);
+ OpenBSD::Requiring->new($requiring)->add($required);
+ }
+}
+
1;
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index 9cd31991335..5348530c3af 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.331 2008/03/08 12:07:45 espie Exp $
+# $OpenBSD: pkg_add,v 1.332 2008/06/21 14:01:10 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -401,6 +401,9 @@ sub really_add
$plist->get(DISPLAY)->prepare($state);
}
$set->{solver}->adjust_old_dependencies($state);
+ if ($state->{repairdependencies}) {
+ $set->{solver}->repair_dependencies($state);
+ }
}
sub install_set
@@ -470,6 +473,13 @@ sub install_set
return ();
}
}
+# if (!$set->{solver}->solve_tags($state)) {
+# $location->close_now;
+# if (!$defines{libdepends}) {
+# $bad++;
+# return ();
+# }
+# }
really_add($set, $state);
$location->wipe_info;
delete $handle->{plist};