summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2004-11-11 11:16:41 +0000
committerMarc Espie <espie@cvs.openbsd.org>2004-11-11 11:16:41 +0000
commit9a75ae2f447ba6fc84c5a0ec8444cdc0b3a650f0 (patch)
treef4d68f8f40fbe180d0eaceed7376127491ada8f4
parente31ed5bb4cbddf2694888868ba2244110075a89c (diff)
introduce shortcuts to read/write contents from_installation/to_installation
use these to simplify all those packing lists manipulations. demote non-root detection to a warning in -n mode: fix a couple of minor bugs, of stuff that was run in -n mode and should not. Namely, manpages were indexed/unindexed (ouch) and tempfiles were creating during updates.
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Add.pm3
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Delete.pm15
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageInfo.pm7
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackingList.pm21
-rw-r--r--usr.sbin/pkg_add/OpenBSD/SharedItems.pm5
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Update.pm38
-rw-r--r--usr.sbin/pkg_add/pkg_add31
-rw-r--r--usr.sbin/pkg_add/pkg_audit5
-rw-r--r--usr.sbin/pkg_add/pkg_delete15
-rw-r--r--usr.sbin/pkg_add/pkg_info5
10 files changed, 95 insertions, 50 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Add.pm b/usr.sbin/pkg_add/OpenBSD/Add.pm
index 6cf401eaab1..8169c5e2c74 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.9 2004/11/06 19:48:24 espie Exp $
+# $OpenBSD: Add.pm,v 1.10 2004/11/11 11:16:39 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -164,6 +164,7 @@ sub install
if ($state->{replacing}) {
+ return if $state->{not};
if (defined $self->{link}) {
link($destdir.$self->{link}, $destdir.$fullname);
} elsif (defined $self->{symlink}) {
diff --git a/usr.sbin/pkg_add/OpenBSD/Delete.pm b/usr.sbin/pkg_add/OpenBSD/Delete.pm
index ec064eea821..6acc7b6ffdb 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.6 2004/11/09 11:11:01 espie Exp $
+# $OpenBSD: Delete.pm,v 1.7 2004/11/11 11:16:39 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -31,9 +31,13 @@ sub manpages_unindex
while (my ($k, $v) = each %{$state->{mandirs}}) {
my @l = map { $destdir.$_ } @$v;
- eval { OpenBSD::Makewhatis::remove($destdir.$k, \@l); };
- if ($@) {
- print STDERR "Error in makewhatis: $@\n";
+ if ($state->{not}) {
+ print "Removing manpages in $destdir$k: ", join(@l), "\n";
+ } else {
+ eval { OpenBSD::Makewhatis::remove($destdir.$k, \@l); };
+ if ($@) {
+ print STDERR "Error in makewhatis: $@\n";
+ }
}
}
undef $state->{mandirs};
@@ -73,8 +77,7 @@ sub remove_packing_info
sub delete_package
{
my ($pkgname, $state) = @_;
- my $dir = installed_info($pkgname);
- my $plist = OpenBSD::PackingList->fromfile($dir.CONTENTS) or
+ my $plist = OpenBSD::PackingList->from_installation($pkgname) or
Fatal "Bad package";
if (!defined $plist->pkgname()) {
Fatal "Package $pkgname has no name";
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm b/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm
index 6ee56a1e512..84eec22a902 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackageInfo.pm,v 1.9 2004/10/11 10:30:34 espie Exp $
+# $OpenBSD: PackageInfo.pm,v 1.10 2004/11/11 11:16:39 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -109,6 +109,11 @@ sub installed_info($)
}
}
+sub installed_contents($)
+{
+ return installed_info(shift).CONTENTS;
+}
+
sub borked_package()
{
my $i = 1;
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingList.pm b/usr.sbin/pkg_add/OpenBSD/PackingList.pm
index 53e62485447..a1b963c920e 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackingList.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackingList.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackingList.pm,v 1.32 2004/11/10 09:55:43 espie Exp $
+# $OpenBSD: PackingList.pm,v 1.33 2004/11/11 11:16:40 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -299,4 +299,23 @@ sub visit
}
}
+sub from_installation
+{
+ my ($o, $name, @args) = @_;
+
+ require OpenBSD::PackageInfo;
+
+ return $o->fromfile(OpenBSD::PackageInfo::installed_contents($name),
+ @args);
+}
+
+sub to_installation
+{
+ my ($self) = @_;
+
+ require OpenBSD::PackageInfo;
+
+ $self->tofile(OpenBSD::PackageInfo::installed_contents($self->pkgname()));
+}
+
1;
diff --git a/usr.sbin/pkg_add/OpenBSD/SharedItems.pm b/usr.sbin/pkg_add/OpenBSD/SharedItems.pm
index 1d3b3face14..bfac3645fba 100644
--- a/usr.sbin/pkg_add/OpenBSD/SharedItems.pm
+++ b/usr.sbin/pkg_add/OpenBSD/SharedItems.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: SharedItems.pm,v 1.2 2004/10/26 17:25:36 espie Exp $
+# $OpenBSD: SharedItems.pm,v 1.3 2004/11/11 11:16:40 espie Exp $
#
# Copyright (c) 2004 Marc Espie <espie@openbsd.org>
#
@@ -33,7 +33,8 @@ sub record_all
my $done = 0;
for my $e (@list) {
OpenBSD::ProgressMeter::show($done, $total);
- my $plist = OpenBSD::PackingList->fromfile(installed_info($e).CONTENTS, \&OpenBSD::PackingList::SharedItemsOnly) or next;
+ my $plist = OpenBSD::PackingList->from_installation($e,
+ \&OpenBSD::PackingList::SharedItemsOnly) or next;
$plist->visit('record_shared_item', $e, $db);
$done++;
}
diff --git a/usr.sbin/pkg_add/OpenBSD/Update.pm b/usr.sbin/pkg_add/OpenBSD/Update.pm
index 554ab68a489..34120c68a86 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.20 2004/11/11 10:47:26 espie Exp $
+# $OpenBSD: Update.pm,v 1.21 2004/11/11 11:16:40 espie Exp $
#
# Copyright (c) 2004 Marc Espie <espie@openbsd.org>
#
@@ -73,13 +73,17 @@ sub extract
if (defined $self->{link} || defined $self->{symlink}) {
return;
}
- my ($fh, $tempname) = tempfile(DIR => dirname($file->{destdir}.$file->{name}));
-
- print "extracting $tempname\n" if $state->{very_verbose};
- $file->{name} = $tempname;
- $self->{tempname} = $tempname;
- return if $state->{not};
- $file->create();
+
+ if ($state->{not}) {
+ print "extracting tempfile under ", dirname($file->{destdir}.$file->{name}), "\n";
+ } else {
+ my ($fh, $tempname) = tempfile(DIR => dirname($file->{destdir}.$file->{name}));
+
+ print "extracting $tempname\n" if $state->{very_verbose};
+ $file->{name} = $tempname;
+ $self->{tempname} = $tempname;
+ $file->create();
+ }
}
package OpenBSD::PackingElement::Dir;
@@ -178,7 +182,7 @@ sub can_do
my $r = OpenBSD::RequiredBy->new($toreplace);
$state->{okay} = 1;
$state->{libs_to_check} = [];
- my $plist = OpenBSD::PackingList->fromfile(installed_info($toreplace).CONTENTS);
+ my $plist = OpenBSD::PackingList->from_installation($toreplace);
$plist->visit('can_update', $state);
if ($state->{okay} == 0) {
print "Old package contains impossible to update elements\n";
@@ -190,7 +194,7 @@ sub can_do
next if defined $done_wanted->{$wanting};
$done_wanted->{$wanting} = 1;
print "Verifying dependencies still match for $wanting\n" if $state->{verbose};
- my $p2 = OpenBSD::PackingList->fromfile(installed_info($wanting).CONTENTS,
+ my $p2 = OpenBSD::PackingList->from_installation($wanting,
\&OpenBSD::PackingList::DependOnly);
$p2->visit('validate_depend', $state, $wanting, $toreplace, $replacement);
}
@@ -256,10 +260,9 @@ sub walk_depends_closure
push(@todo, $pkg2);
print "\t$pkg2\n" if $state->{beverbose};
$write->add($pkg2) unless $state->{not};
- my $contents = installed_info($pkg2).CONTENTS;
- my $plist = OpenBSD::PackingList->fromfile($contents);
+ my $plist = OpenBSD::PackingList->from_installation($pkg2);
OpenBSD::PackingElement::PkgDep->add($plist, $name);
- $plist->tofile($contents) unless $state->{not};
+ $plist->to_installation() unless $state->{not};
$done->{$pkg2} = 1;
}
}
@@ -295,8 +298,8 @@ sub save_old_libraries
print $comment "Stub libraries for $oldname";
close $comment;
link($dest.COMMENT, $dest.DESC);
- $stub_list->tofile($dest.CONTENTS);
- $old_plist->tofile(installed_info($oldname).CONTENTS);
+ $stub_list->to_installation();
+ $old_plist->to_installation();
}
walk_depends_closure($old_plist->pkgname(), $stub_name, $state);
@@ -308,8 +311,7 @@ sub adjust_dependency
{
my ($dep, $from, $into) = @_;
- my $contents = installed_info($dep).CONTENTS;
- my $plist = OpenBSD::PackingList->fromfile($contents);
+ my $plist = OpenBSD::PackingList->from_installation($dep);
my $items = [];
for my $item (@{$plist->{pkgdep}}) {
next if $item->{'name'} eq $from;
@@ -317,6 +319,6 @@ sub adjust_dependency
}
$plist->{pkgdep} = $items;
OpenBSD::PackingElement::PkgDep->add($plist, $into);
- $plist->tofile($contents);
+ $plist->to_installation();
}
1;
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index 931961149f4..ed7b930d7d5 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.99 2004/11/11 10:47:26 espie Exp $
+# $OpenBSD: pkg_add,v 1.100 2004/11/11 11:16:39 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -43,8 +43,7 @@ sub fill_conflict_lists
my $state = shift;
# first, find all possible potential conflicts
for my $pkg (installed_packages()) {
- my $dir = installed_info($pkg);
- my $plist = OpenBSD::PackingList->fromfile($dir.CONTENTS,
+ my $plist = OpenBSD::PackingList->from_installation($pkg,
\&OpenBSD::PackingList::ConflictOnly);
next unless defined $plist;
$state->{conflict_list}->{$plist->pkgname()} =
@@ -245,7 +244,7 @@ sub register_installation
for my $i (info_names()) {
copy($dir.$i, $dest);
}
- $plist->tofile($dest.CONTENTS);
+ $plist->to_installation();
}
sub borked_installation
@@ -319,7 +318,8 @@ sub collision_report($)
for my $pkg (installed_packages()) {
- my $plist = OpenBSD::PackingList->fromfile(installed_info($pkg).CONTENTS, \&OpenBSD::PackingList::FilesOnly);
+ my $plist = OpenBSD::PackingList->from_installation($pkg,
+ \&OpenBSD::PackingList::FilesOnly);
for my $item (@{$plist->{items}}) {
next unless $item->IsFile();
my $name = $item->fullname();
@@ -404,9 +404,13 @@ sub manpages_index
while (my ($k, $v) = each %{$state->{mandirs}}) {
my @l = map { $destdir.$_ } @$v;
- eval { OpenBSD::Makewhatis::merge($destdir.$k, \@l); };
- if ($@) {
- print STDERR "Error in makewhatis: $@\n";
+ if ($state->{not}) {
+ print "Merging manpages in $destdir$k: ", join(@l), "\n";
+ } else {
+ eval { OpenBSD::Makewhatis::merge($destdir.$k, \@l); };
+ if ($@) {
+ print STDERR "Error in makewhatis: $@\n";
+ }
}
}
}
@@ -675,9 +679,6 @@ if (defined $state->{destdir}) {
$state->{destdir} = '';
}
-if ($< && !$forced{nonroot}) {
- Fatal "$0 must be run as root";
-}
$state->{conflict_list} = {};
$state->{not} = $opt_n;
@@ -690,6 +691,14 @@ if ($opt_x && !$state->{beverbose}) {
OpenBSD::ProgressMeter::enable();
}
+if ($< && !$forced{nonroot}) {
+ if ($state->{not}) {
+ print "$0 should be run as root\n";
+ } else {
+ Fatal "$0 must be run as root";
+ }
+}
+
fill_conflict_lists($state);
my @todo = (@ARGV);
diff --git a/usr.sbin/pkg_add/pkg_audit b/usr.sbin/pkg_add/pkg_audit
index ee2e11be94f..c75fcb71659 100644
--- a/usr.sbin/pkg_add/pkg_audit
+++ b/usr.sbin/pkg_add/pkg_audit
@@ -1,6 +1,6 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_audit,v 1.2 2004/08/06 07:51:17 espie Exp $
+# $OpenBSD: pkg_audit,v 1.3 2004/11/11 11:16:39 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -25,7 +25,8 @@ use File::Find;
my %found;
for my $pkg (installed_packages()) {
- my $plist = OpenBSD::PackingList->fromfile(installed_info($pkg).CONTENTS, \&OpenBSD::PackingList::FilesOnly);
+ my $plist = OpenBSD::PackingList->from_installation($pkg,
+ \&OpenBSD::PackingList::FilesOnly);
print "$pkg...\n";
for my $item (@{$plist->{items}}) {
next unless $item->IsFile();
diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete
index 2e4eb435780..740bf41ace1 100644
--- a/usr.sbin/pkg_add/pkg_delete
+++ b/usr.sbin/pkg_add/pkg_delete
@@ -1,6 +1,6 @@
#!/usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_delete,v 1.70 2004/11/11 10:47:26 espie Exp $
+# $OpenBSD: pkg_delete,v 1.71 2004/11/11 11:16:39 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -58,10 +58,6 @@ if ($opt_f) {
%forced = map {($_, 1)} split(/,/, $opt_f);
}
-if ($< && !$forced{nonroot}) {
- Fatal "$0 must be run as root";
-}
-
my %done;
my $removed;
@@ -79,6 +75,14 @@ if ($opt_x && $state->{beverbose}) {
OpenBSD::ProgressMeter::enable();
}
+if ($< && !$forced{nonroot}) {
+ if ($state->{not}) {
+ print "$0 should be run as root\n";
+ } else {
+ Fatal "$0 must be run as root";
+ }
+}
+
# First, resolve pkg names
my @realnames;
@@ -172,7 +176,6 @@ eval {
"$pkgname\n";
}
$state->set_pkgname($pkgname);
- $state->{pkgname_tolog} = $pkgname;
OpenBSD::Delete::delete_package($pkgname, $state);
delete_installed($pkgname);
$done{$pkgname} = 1;
diff --git a/usr.sbin/pkg_add/pkg_info b/usr.sbin/pkg_add/pkg_info
index 821855ed1ad..1cace9e325f 100644
--- a/usr.sbin/pkg_add/pkg_info
+++ b/usr.sbin/pkg_add/pkg_info
@@ -1,6 +1,6 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_info,v 1.14 2004/11/10 09:55:43 espie Exp $
+# $OpenBSD: pkg_info,v 1.15 2004/11/11 11:16:39 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -68,7 +68,8 @@ sub find_by_path
$all_plists = [];
for my $pkg (installed_packages()) {
push(@$all_plists,
- OpenBSD::PackingList->fromfile(installed_info($pkg).CONTENTS, \&OpenBSD::PackingList::ExtraInfoOnly));
+ OpenBSD::PackingList->from_installation($pkg,
+ \&OpenBSD::PackingList::ExtraInfoOnly);
}
}
my @result = ();