summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2007-06-09 13:39:32 +0000
committerMarc Espie <espie@cvs.openbsd.org>2007-06-09 13:39:32 +0000
commit8c39d507ee7e0c3e06c96859e499f9390bea2ad7 (patch)
treeab721842c41bb57901d8bac07d54b87624a1905d /usr.sbin/pkg_add
parentb0f04183f9686e32b7d65c440f335b9fd9a2b60f (diff)
tag user installed packages.
- record what's on the command line. - adjust option depending on -a / !-a - report `manual-install' status when replacing stuff.
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Add.pm50
-rw-r--r--usr.sbin/pkg_add/pkg_add26
2 files changed, 70 insertions, 6 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Add.pm b/usr.sbin/pkg_add/OpenBSD/Add.pm
index 6e77e89e917..99ca49ef26b 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.75 2007/06/06 15:35:20 espie Exp $
+# $OpenBSD: Add.pm,v 1.76 2007/06/09 13:39:31 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -105,6 +105,54 @@ sub perform_installation
$handle->{location}->finish_and_close;
}
+my $user_tagged = {};
+
+sub extract_pkgname
+{
+ my $pkgname = shift;
+ $pkgname =~ s/^.*\///;
+ $pkgname =~ s/\.tgz$//;
+ return $pkgname;
+}
+
+sub tweak_package_status
+{
+ my ($pkgname, $state) = @_;
+
+ $pkgname = extract_pkgname($pkgname);
+ return 0 unless is_installed($pkgname);
+ return 0 unless $user_tagged->{$pkgname};
+ my $plist = OpenBSD::PackingList->from_installation($pkgname);
+ if ($plist->has('manual-installation') && $state->{automatic}) {
+ delete $plist->{'manual-installation'};
+ $plist->to_installation;
+ return 1;
+ } elsif (!$plist->has('manual-installation') && !$state->{automatic}) {
+ OpenBSD::PackingElement::ManualInstallation->add($plist);
+ $plist->to_installation;
+ return 1;
+ }
+ return 0;
+}
+
+sub tweak_plist_status
+{
+ my ($plist, $state) = @_;
+
+ my $pkgname = $plist->pkgname;
+ return 0 unless $user_tagged->{$pkgname};
+ if (!$plist->has('manual-installation') && !$state->{automatic}) {
+ OpenBSD::PackingElement::ManualInstallation->add($plist);
+ }
+}
+
+sub tag_user_packages
+{
+ for my $pkgname (@_) {
+ $user_tagged->{extract_pkgname($pkgname)} = 1;
+ }
+}
+
# used by newuser/newgroup to deal with options.
package OpenBSD::PackingElement;
use OpenBSD::Error;
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index 3164b6ea27c..19cba8a06c8 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.315 2007/06/09 11:16:54 espie Exp $
+# $OpenBSD: pkg_add,v 1.316 2007/06/09 13:39:31 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -176,6 +176,10 @@ sub can_install
$old_handle->{plist} = $rplist;
$old_handle->{pkgname} = $toreplace;
$set->add_older($old_handle);
+ if ($rplist->has('manual-installation') &&
+ !$plist->has('manual-installation')) {
+ OpenBSD::PackingElement::ManualInstallation->add($plist);
+ }
}
$set->{skipupdatedeps} = \%conflicts;
return 1;
@@ -186,11 +190,16 @@ sub create_handle
my ($pkg, $state) = @_;
my $handle = OpenBSD::Handle->new;
$handle->{pkgname} = $pkg;
+ $handle->{tweaked} = 0;
my $location = OpenBSD::PackageLocator->find($pkg, $state->{arch});
if (!$location) {
print $state->deptree_header($pkg);
- print "Can't find $pkg\n";
$handle->set_error(OpenBSD::Handle::NOT_FOUND);
+ $handle->{tweaked} =
+ OpenBSD::Add::tweak_package_status($pkg, $state);
+ if (!$handle->{tweaked}) {
+ print "Can't find $pkg\n";
+ }
return $handle;
}
$handle->{location} = $location;
@@ -222,7 +231,10 @@ sub create_handle
!$state->{forced}->{installed} &&
!$plist->has_new_sig($state) &&
!$plist->uses_old_libs)) {
- print "Not reinstalling $pkgname\n" if $state->{verbose};
+ $handle->{tweaked} =
+ OpenBSD::Add::tweak_package_status($pkgname, $state);
+ print "Not reinstalling $pkgname\n" if $state->{verbose} and
+ !$handle->{tweaked};
$state->mark_as_already_installed($pkgname);
$location->close_now;
$location->wipe_info;
@@ -424,6 +436,7 @@ sub really_add
$set, $state);
}
OpenBSD::SharedLibs::add_libs_from_plist($plist);
+ OpenBSD::Add::tweak_plist_status($plist, $state);
$plist->to_cache;
OpenBSD::Add::register_installation($plist);
$set->{solver}->register_dependencies($state);
@@ -451,8 +464,9 @@ sub install_package
return ();
}
if ($handle->has_error) {
- if (!$state->{forced}->{kitchensink} ||
- $handle->has_error(OpenBSD::Handle::BAD_PACKAGE)) {
+ if ((!$state->{forced}->{kitchensink} ||
+ $handle->has_error(OpenBSD::Handle::BAD_PACKAGE)) &&
+ !$handle->{tweaked}) {
$state->set_name_from_handle($handle);
$state->fatal("Fatal error");
} else {
@@ -632,6 +646,7 @@ $state->{not} = $opt_n;
$not = $opt_n;
$state->{quick} = $opt_q;
$state->{extra} = $opt_c;
+$state->{automatic} = $opt_a;
$state->{dont_run_scripts} = $opt_I;
$state->{very_verbose} = $opt_v >= 2;
$state->{verbose} = $opt_v;
@@ -684,6 +699,7 @@ if ($opt_u) {
}
} else {
find_truenames(\@ARGV, \@todo, $state);
+ OpenBSD::Add::tag_user_packages(@todo);
if (defined $state->{forced}->{kitchensink}) {
reorder(\@todo);
if (!$opt_r) {