summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2010-06-05 16:21:36 +0000
committerMarc Espie <espie@cvs.openbsd.org>2010-06-05 16:21:36 +0000
commitb1e5163534a4aad68464881ef3de6e23ce0fdfcb (patch)
tree2bf220d23e2f2bf36a095b59c9167262b4be1897 /usr.sbin/pkg_add
parent03a8b3d6bceb1215c4679acab05f2c5ebb49536f (diff)
roughly halfway through dependencies check (really need to handle
wantlib so that depends closures work...) also handle destdir, more or less.
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PkgFsck.pm136
1 files changed, 123 insertions, 13 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PkgFsck.pm b/usr.sbin/pkg_add/OpenBSD/PkgFsck.pm
index 53ed5f7e069..7a1dd6ce3d5 100644
--- a/usr.sbin/pkg_add/OpenBSD/PkgFsck.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PkgFsck.pm
@@ -1,7 +1,7 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: PkgFsck.pm,v 1.2 2010/06/05 12:35:32 espie Exp $
+# $OpenBSD: PkgFsck.pm,v 1.3 2010/06/05 16:21:35 espie Exp $
#
# Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
#
@@ -33,6 +33,10 @@ sub basic_check
{
}
+sub find_dependencies
+{
+}
+
package OpenBSD::PackingElement::FileBase;
use File::Basename;
@@ -40,7 +44,7 @@ sub basic_check
{
my ($self, $state) = @_;
- my $name = $self->fullname;
+ my $name = $state->{destdir}.$self->fullname;
$state->{known}{dirname($name)}{basename($name)} = 1;
if (!-e $name) {
$state->log("$name should exist\n");
@@ -59,15 +63,16 @@ sub basic_check
sub thorough_check
{
my ($self, $state) = @_;
+ my $name = $state->{destdir}.$self->fullname;
$self->basic_check($state);
return if $self->{link} or $self->{symlink} or $self->{nochecksum};
- if (!-r $self->fullname) {
- $state->log("can't read ", $self->fullname, "\n");
+ if (!-r $name) {
+ $state->log("can't read $name\n");
return;
}
- my $d = $self->compute_digest($self->fullname);
+ my $d = $self->compute_digest($name);
if (!$d->equals($self->{d})) {
- $state->log("checksum for ", $self->fullname, " does not match", "\n");
+ $state->log("checksum for $name does not match", "\n");
}
}
@@ -86,7 +91,7 @@ package OpenBSD::PackingElement::DirlikeObject;
sub basic_check
{
my ($self, $state) = @_;
- my $name = $self->fullname;
+ my $name = $state->{destdir}.$self->fullname;
$state->{known}{$name} //= {};
if (!-e $name) {
$state->log("$name should exist\n");
@@ -101,7 +106,8 @@ sub basic_check
{
my ($self, $state) = @_;
$self->SUPER::basic_check($state);
- $state->{known}{$self->fullname}{'whatis.db'} = 1;
+ my $name = $state->{destdir}.$self->fullname;
+ $state->{known}{$name}{'whatis.db'} = 1;
}
package OpenBSD::PackingElement::Fontdir;
@@ -109,8 +115,9 @@ sub basic_check
{
my ($self, $state) = @_;
$self->SUPER::basic_check($state);
+ my $name = $state->{destdir}.$self->fullname;
for my $i (qw(fonts.alias fonts.scale fonts.dir)) {
- $state->{known}{$self->fullname}{$i} = 1;
+ $state->{known}{$name}{$i} = 1;
}
}
@@ -119,7 +126,35 @@ sub basic_check
{
my ($self, $state) = @_;
$self->SUPER::basic_check($state);
- $state->{known}{$self->fullname}{'dir'} = 1;
+ my $name = $state->{destdir}.$self->fullname;
+ $state->{known}{$name}{'dir'} = 1;
+}
+
+package OpenBSD::PackingElement::Dependency;
+sub find_dependencies
+{
+ my ($self, $state, $l, $not_yet, $possible, $others) = @_;
+ # several ways to failure
+ if (!$self->spec->is_valid) {
+ $state->log("invalid \@", $self->keyword, " ",
+ $self->stringize);
+ return;
+ }
+ my @deps = $self->spec->filter(@$l);
+ if (@deps == 0) {
+ $state->log("dependency ", $self->stringize, " does not match any installed package");
+ return;
+ }
+ my $okay = 0;
+ for my $i (@deps) {
+ if ($possible->{$i}) {
+ delete $not_yet->{$i};
+ $okay = 1;
+ }
+ }
+ if (!$okay) {
+ $others->{$deps[0]} = 1;
+ }
}
package OpenBSD::Log;
@@ -164,6 +199,7 @@ use OpenBSD::PackingList;
use File::Find;
use OpenBSD::Paths;
use OpenBSD::Mtree;
+use OpenBSD::RequiredBy;
sub remove
{
@@ -213,6 +249,32 @@ sub may_remove
}
}
+sub ask_delete_deps
+{
+ my ($self, $state, $name, $l, $req) = @_;
+ if ($state->{force}) {
+ $req->delete(@$l);
+ } elsif ($state->{interactive}) {
+ require OpenBSD::Interactive;
+ if (OpenBSD::Interactive("Remove missing deps ?")) {
+ $req->delete(@$l);
+ }
+ }
+}
+
+sub ask_add_deps
+{
+ my ($self, $state, $name, $l, $req) = @_;
+ if ($state->{force}) {
+ $req->add(@$l);
+ } elsif ($state->{interactive}) {
+ require OpenBSD::Interactive;
+ if (OpenBSD::Interactive("Add missing deps ?")) {
+ $req->add(@$l);
+ }
+ }
+}
+
sub sanity_check
{
my ($self, $state, $l) = @_;
@@ -254,6 +316,36 @@ sub sanity_check
}
}
+sub dependencies_check
+{
+ my ($self, $state, $l) = @_;
+ $state->progress->set_header("Dependencies");
+ my $i = 0;
+ for my $name (@$l) {
+ $state->progress->show(++$i, scalar @$l);
+ my $plist = OpenBSD::PackingList->from_installation($name,
+ \&OpenBSD::PackingList::DependOnly);
+ my $req = OpenBSD::Requiring->new($name);
+ my @known = $req->list;
+ my %not_yet =map {($_, 1)} @known;
+ my %possible = map {($_, 1)} @known;
+ my %other = ();
+ $plist->find_dependencies($state, $l, \%not_yet, \%possible,
+ \%other);
+ if (keys %not_yet > 0) {
+ my @todo = sort keys %not_yet;
+ $state->errsay("$name is having too many dependencies: ", join(' ', @todo));
+ $self->ask_delete_deps($state, $name, \@todo, $req);
+ }
+ if (keys %other > 0) {
+ my @todo = sort keys %other;
+ $state->errsay("$name is missing dependencies: ",
+ join(' ', @todo));
+ $self->ask_add_deps($state, $name, \@todo, $req);
+ }
+ }
+}
+
sub package_files_check
{
my ($self, $state, $l) = @_;
@@ -277,7 +369,8 @@ sub localbase_check
my ($self, $state) = @_;
$state->{known} //= {};
# XXX
- OpenBSD::Mtree::parse($state->{known}, OpenBSD::Paths->localbase,
+ OpenBSD::Mtree::parse($state->{known},
+ $state->{destdir}.OpenBSD::Paths->localbase,
"/etc/mtree/BSD.local.dist", 1);
$state->progress->set_header("Other files");
find(sub {
@@ -297,7 +390,10 @@ sub run
my @list = installed_packages(1);
$self->sanity_check($state, \@list);
+# $self->dependencies_check($state, \@list);
+# $state->log->dump;
$self->package_files_check($state, \@list);
+ $state->log->dump;
$self->localbase_check($state);
}
@@ -307,13 +403,27 @@ sub parse_and_run
my $state = OpenBSD::PkgFsck::State->new;
$self->handle_options('fiq', $state,
- 'pkg_fsck [-fimnqvx] [-D value]');
+ 'pkg_fsck [-fimnqvx] [-B pkg-destdir] [-D value]');
+ if (@ARGV != 0) {
+ Usage();
+ }
$state->{interactive} = $state->opt('i');
$state->{force} = $state->opt('f');
$state->{quick} = $state->opt('q');
+ if (defined $state->opt('B')) {
+ $state->{destdir} = $state->opt('B');
+ } elsif (defined $ENV{'PKG_PREFIX'}) {
+ $state->{destdir} = $ENV{'PKG_PREFIX'};
+ }
+ if (defined $state->{destdir}) {
+ $state->{destdir} .= '/';
+ $ENV{'PKG_DESTDIR'} = $state->{destdir};
+ } else {
+ $state->{destdir} = '';
+ delete $ENV{'PKG_DESTDIR'};
+ }
lock_db(0) unless $state->{subst}->value('nolock');
$self->run($state);
- $state->log->dump;
}
1;