summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2004-11-11 12:45:16 +0000
committerMarc Espie <espie@cvs.openbsd.org>2004-11-11 12:45:16 +0000
commit2a62eb499c829fdbae124416085181317df17ccd (patch)
treec1f0c5a31fe9245c2caa69acbffa56e2fa455703
parentc55a8c5166d490b1caac8a8fc09c84dfbcfb5e3c (diff)
symetry: updating a package means removing the old one and adding the new
one, tag unsafe operations accordingly...
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Update.pm42
-rw-r--r--usr.sbin/pkg_add/pkg_add11
2 files changed, 39 insertions, 14 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Update.pm b/usr.sbin/pkg_add/OpenBSD/Update.pm
index b70b3ec0a35..196cf1175d4 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.22 2004/11/11 12:15:28 espie Exp $
+# $OpenBSD: Update.pm,v 1.23 2004/11/11 12:45:15 espie Exp $
#
# Copyright (c) 2004 Marc Espie <espie@openbsd.org>
#
@@ -23,9 +23,9 @@ use OpenBSD::Delete;
package OpenBSD::PackingElement;
sub can_update
{
- my ($self, $state) = @_;
+ my ($self, $install, $state) = @_;
- if (!$self->updatable()) {
+ if (!$self->updatable($install)) {
$state->{okay} = 0;
}
}
@@ -34,7 +34,7 @@ sub validate_depend
{
}
-sub updatable() { 1 }
+sub updatable($) { 1 }
sub extract
{
@@ -109,13 +109,19 @@ sub extract
}
package OpenBSD::PackingElement::ScriptFile;
-sub updatable() { 0 }
+sub updatable($) { 0 }
package OpenBSD::PackingElement::FINSTALL;
-sub updatable() { 1 }
+sub updatable($) { !$_[0] }
+
+package OpenBSD::PackingElement::FDEINSTALL;
+sub updatable($) { $_[0] }
+
+package OpenBSD::PackingElement::Exec;
+sub updatable($) { !$_[0] }
package OpenBSD::PackingElement::Unexec;
-sub updatable() { 0 }
+sub updatable($) { $_[0] }
package OpenBSD::PackingElement::LibDepend;
use OpenBSD::Error;
@@ -183,18 +189,18 @@ use OpenBSD::Error;
sub can_do
{
- my ($toreplace, $replacement, $state, $forced) = @_;
+ my ($toreplace, $replacement, $state) = @_;
my $wantlist = [];
my $r = OpenBSD::RequiredBy->new($toreplace);
$state->{okay} = 1;
$state->{libs_to_check} = [];
my $plist = OpenBSD::PackingList->from_installation($toreplace);
- $plist->visit('can_update', $state);
+ $plist->visit('can_update', 0, $state);
if ($state->{okay} == 0) {
Warn "Old package contains impossible to update elements\n";
}
- if ($forced->{update}) {
+ if ($state->{forced}->{update}) {
$state->{okay} = 1;
}
if (-f $$r) {
@@ -210,13 +216,14 @@ sub can_do
}
}
- if ($forced->{updatedepends}) {
+ if ($state->{forced}->{updatedepends}) {
$state->{okay} = 1;
}
eval {
- OpenBSD::Delete::validate_plist($plist, $state->{destdir});
+ OpenBSD::Delete::validate_plist($plist, $state);
};
if ($@) {
+ Warn "$@";
return 0;
}
@@ -226,6 +233,17 @@ sub can_do
return $state->{okay} ? $plist : 0;
}
+sub is_safe
+{
+ my ($plist, $state) = @_;
+ $state->{okay} = 1;
+ $plist->visit('can_update', 1, $state);
+ if ($state->{okay} == 0) {
+ Warn "New package contains unsafe operations\n";
+ }
+ return $state->{okay} || $state->{forced}->{update};
+}
+
# create a packing-list with only the libraries we want to keep around.
sub split_libs
{
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index 0afcb391b3f..24000e7b37c 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.105 2004/11/11 12:29:20 espie Exp $
+# $OpenBSD: pkg_add,v 1.106 2004/11/11 12:45:15 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -82,7 +82,7 @@ sub can_install($$)
require OpenBSD::Update;
- my $plist = OpenBSD::Update::can_do($l[0], $pkgname, $state, \%forced);
+ my $plist = OpenBSD::Update::can_do($l[0], $pkgname, $state);
if ($plist) {
$plist->{dir} = installed_info($l[0]);
return $plist;
@@ -153,6 +153,13 @@ sub pre_add($$)
if ($toreplace ne '1') {
$plist->{replacing} = $toreplace;
$avoid = $toreplace->pkgname();
+
+ require OpenBSD::Update;
+
+ if (!OpenBSD::Update::is_safe($plist, $state)) {
+ print "Can't safely update $avoid to $pkgname\n";
+ $errors++;
+ }
}
# second handling of conflicts
my $l = OpenBSD::PkgCfl->make_conflict_list($plist);