summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2004-11-07 12:19:21 +0000
committerMarc Espie <espie@cvs.openbsd.org>2004-11-07 12:19:21 +0000
commit26c9b8ad4b09430d9b4b38a9dc5be2b133a24cbb (patch)
tree5d8b3ae3d123a83014712353657905a049b9e36f /usr.sbin/pkg_add
parenta42eb0a3c0dfa1df88a1797e17eae79531281257 (diff)
shared libraries, preliminary work, a simpler scheme:
compare replaced package with replacing package, mark all changed shared libraries. split_old_libs knows how to cobble a new plist off the old one with the shared libraries. print_depends_closure knows how to walk the RequiredBy objects to build a complete list of packages that may depend upon those libraries. Todo: actually split off the libraries, write a COMMENT/CONTENTS files too, and register all those dependencies.
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Update.pm91
-rw-r--r--usr.sbin/pkg_add/pkg_add9
2 files changed, 95 insertions, 5 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Update.pm b/usr.sbin/pkg_add/OpenBSD/Update.pm
index 8d125fef743..24038ad6242 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.10 2004/11/06 12:19:17 espie Exp $
+# $OpenBSD: Update.pm,v 1.11 2004/11/07 12:19:20 espie Exp $
#
# Copyright (c) 2004 Marc Espie <espie@openbsd.org>
#
@@ -44,6 +44,14 @@ sub extract
{
}
+sub mark_lib
+{
+}
+
+sub unmark_lib
+{
+}
+
package OpenBSD::PackingElement::FileBase;
use File::Temp qw/tempfile/;
@@ -119,6 +127,20 @@ sub register_libs
}
}
+sub mark_lib
+{
+ my ($self, $libs) = @_;
+ my $libname = $self->fullname();
+ $libs->{"$libname"} = 1;
+}
+
+sub unmark_lib
+{
+ my ($self, $libs) = @_;
+ my $libname = $self->fullname();
+ delete $libs->{"$libname"};
+}
+
package OpenBSD::PackingElement::NewDepend;
sub validate_depend
{
@@ -174,6 +196,73 @@ sub can_do
return $state->{okay} ? $plist : 0;
}
+# create a packing-list with only the libraries we want to keep around.
+sub split_libs
+{
+ my ($plist, $to_split) = @_;
+
+ my $items = [];
+
+ my $splitted = OpenBSD::PackingList->new();
+ OpenBSD::PackingElement::Name->add($splitted, "_libs-".$plist->pkgname());
+ # we conflict with the package we just removed...
+ OpenBSD::PackingElement::Conflict->add($splitted, $plist->pkgname());
+
+ for my $item (@{$plist->{items}}) {
+ if ($item->isa("OpenBSD::PackingElement::Lib") &&
+ defined $to_split->{$item->fullname()}) {
+ OpenBSD::PackingElement::Lib->add($splitted, $item->{name});
+ } elsif ($item->isa("OpenBSD::PackingElement::Cwd")) {
+ OpenBSD::PackingElement::Cwd->add($splitted, $item->{name});
+ } else {
+ push(@$items, $item);
+ }
+ }
+ $plist->{items} = $items;
+ return $splitted;
+}
+
+sub print_depends_closure
+{
+ my @todo = @_;
+ my $done = {};
+
+ while (my $pkg = shift @todo) {
+ $done->{$pkg} = 1;
+ my $r = OpenBSD::RequiredBy->new($pkg);
+ if (-f $$r) {
+ my $list = $r->list();
+ for my $pkg2 (@$list) {
+ next if $done->{$pkg2};
+ push(@todo, $pkg2);
+ print $pkg2, "\n";
+ $done->{$pkg2} = 1;
+ }
+ }
+ }
+}
+
+
+
+sub save_old_libraries
+{
+ my ($new_plist, $state) = @_;
+
+ my $old_plist = $new_plist->{replacing};
+ my $libs = {};
+
+ $old_plist->visit('mark_lib', $libs);
+ $new_plist->visit('unmark_lib', $libs);
+
+ if (%$libs) {
+ my $stub_list = split_libs($old_plist, $libs);
+ print_depends_closure($old_plist->pkgname());
+ $stub_list->write(\*STDOUT);
+ exit(1);
+ }
+}
+
+
sub verify_libs
{
my ($plist, $state) = @_;
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index 3c0b814ef8d..bfdb78f28bc 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.94 2004/11/06 12:19:16 espie Exp $
+# $OpenBSD: pkg_add,v 1.95 2004/11/07 12:19:20 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -155,9 +155,9 @@ sub pre_add($$)
if ($toreplace ne '1') {
$plist->{replacing} = $toreplace;
$avoid = $toreplace->pkgname();
- if (!OpenBSD::Update::verify_libs($plist, $state)) {
- return undef;
- }
+# if (!OpenBSD::Update::verify_libs($plist, $state)) {
+# return undef;
+# }
}
# second handling of conflicts
my $l = OpenBSD::PkgCfl->make_conflict_list($plist);
@@ -462,6 +462,7 @@ sub really_add($$)
if (defined $plist->{replacing}) {
require OpenBSD::Update;
+ OpenBSD::Update::save_old_libraries($plist, $state);
$plist->visit('extract', $state);
require OpenBSD::Delete;