summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2007-06-30 11:38:39 +0000
committerMarc Espie <espie@cvs.openbsd.org>2007-06-30 11:38:39 +0000
commit7de263dcbb38a1ead80c94b1123691570895b643 (patch)
tree5760deec42157860fce4e98eaeee81d5b06a9064
parent3122dc440b58cab55adb963ab72d87398264304d (diff)
move the UpdateSet stuff into its separate file, leaving Vstat much cleaner.
-rw-r--r--usr.sbin/pkg_add/OpenBSD/UpdateSet.pm313
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Vstat.pm315
-rw-r--r--usr.sbin/pkg_add/pkg_add4
-rw-r--r--usr.sbin/pkg_add/pkg_delete4
4 files changed, 317 insertions, 319 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm
index afe23105410..761584438f0 100644
--- a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm
+++ b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: UpdateSet.pm,v 1.1 2007/06/25 12:21:08 espie Exp $
+# $OpenBSD: UpdateSet.pm,v 1.2 2007/06/30 11:38:38 espie Exp $
#
# Copyright (c) 2007 Marc Espie <espie@openbsd.org>
#
@@ -15,4 +15,315 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+package OpenBSD::SharedItemsRecorder;
+sub new
+{
+ my $class = shift;
+ return bless {}, $class;
+}
+
+sub is_empty
+{
+ my $self = shift;
+ return !(defined $self->{dirs} or defined $self->{users} or
+ defined $self->{groups});
+}
+
+sub cleanup
+{
+ my ($self, $state) = @_;
+ return if $self->is_empty or $state->{not};
+
+ require OpenBSD::SharedItems;
+ OpenBSD::SharedItems::cleanup($self, $state);
+}
+
+package OpenBSD::pkg_foo::State;
+use OpenBSD::Error;
+our @ISA=(qw(OpenBSD::Error));
+
+sub progress
+{
+ my $self = shift;
+ return $self->{progressmeter};
+}
+
+sub setup_progressmeter
+{
+ my ($self, $opt_x) = @_;
+ if (!$opt_x && !$self->{beverbose}) {
+ require OpenBSD::ProgressMeter;
+ $self->{progressmeter} = OpenBSD::ProgressMeter->new;
+ } else {
+ $self->{progressmeter} = bless {}, "OpenBSD::StubProgress";
+ }
+}
+
+sub check_root
+{
+ my $state = shift;
+ if ($< && !$state->{forced}->{nonroot}) {
+ if ($state->{not}) {
+ Warn "$0 should be run as root\n";
+ } else {
+ Fatal "$0 must be run as root";
+ }
+ }
+}
+
+package OpenBSD::StubProgress;
+sub clear {}
+
+sub show {}
+
+sub message {}
+
+sub next {}
+
+sub set_header {}
+
+# fairly non-descriptive name. Used to store various package information
+# during installs and updates.
+package OpenBSD::Handle;
+
+use constant {
+ BAD_PACKAGE => 1,
+ CANT_INSTALL => 2,
+ ALREADY_INSTALLED => 3,
+ NOT_FOUND => 4
+};
+
+sub new
+{
+ my $class = shift;
+ return bless {}, $class;
+}
+
+sub set_error
+{
+ my ($self, $error) = @_;
+ $self->{error} = $error;
+}
+
+sub has_error
+{
+ my ($self, $error) = @_;
+ if (!defined $self->{error}) {
+ return undef;
+ }
+ if (defined $error) {
+ return $self->{error} eq $error;
+ }
+ return $self->{error};
+}
+
+sub create_old
+{
+
+ my ($class, $pkgname, $state) = @_;
+ my $self= $class->new;
+ $self->{pkgname} = $pkgname;
+
+ require OpenBSD::PackageRepository::Installed;
+
+ my $location = OpenBSD::PackageRepository::Installed->new->find($pkgname, $state->{arch});
+ if (!defined $location) {
+ $self->set_error(NOT_FOUND);
+ } else {
+ $self->{location} = $location;
+ my $plist = $location->plist;
+ if (!defined $plist) {
+ $self->set_error(BAD_PACKAGE);
+ } else {
+ $self->{plist} = $plist;
+ }
+ }
+ return $self;
+}
+
+sub create_new
+{
+ my ($class, $pkg) = @_;
+ my $handle = $class->new;
+ $handle->{pkgname} = $pkg;
+ $handle->{tweaked} = 0;
+ return $handle;
+}
+
+sub from_location
+{
+ my ($class, $location) = @_;
+ my $handle = $class->new;
+ $handle->{pkgname} = $location->{name};
+ $handle->{location} = $location;
+ $handle->{tweaked} = 0;
+ return $handle;
+}
+
+package OpenBSD::UpdateSet;
+sub new
+{
+ my $class = shift;
+ return bless {newer => [], older => []}, $class;
+}
+
+sub add_newer
+{
+ my ($self, @handles) = @_;
+ push(@{$self->{newer}}, @handles);
+}
+
+sub add_older
+{
+ my ($self, @handles) = @_;
+ push(@{$self->{older}}, @handles);
+}
+
+sub newer
+{
+ my $self =shift;
+ return @{$self->{newer}};
+}
+
+sub older
+{
+ my $self = shift;
+ return @{$self->{older}};
+}
+
+sub older_to_do
+{
+ my $self = shift;
+ # XXX in `combined' updates, some dependencies may remove extra
+ # packages, so we do a double-take on the list of packages we
+ # are actually replacing... for now, until we merge update sets.
+ require OpenBSD::PackageInfo;
+ my @l = ();
+ for my $h ($self->older) {
+ if (OpenBSD::PackageInfo::is_installed($h->{pkgname})) {
+ push(@l, $h);
+ }
+ }
+ return @l;
+}
+
+sub print
+{
+ my $self = shift;
+ my @l = ();
+ if (defined $self->{newer}) {
+ push(@l, "installing", map {$_->{pkgname}} $self->newer);
+ }
+ if (defined $self->{older} && @{$self->{older}} > 0) {
+ push(@l, "deinstalling", map {$_->{pkgname}} $self->older);
+ }
+ return join(' ', @l);
+}
+
+sub validate_plists
+{
+ my ($self, $state) = @_;
+ $state->{problems} = 0;
+
+ for my $o ($self->older_to_do) {
+ require OpenBSD::Delete;
+ OpenBSD::Delete::validate_plist($o->{plist}, $state);
+ }
+ $state->{colliding} = [];
+ for my $n ($self->newer) {
+ require OpenBSD::Add;
+ OpenBSD::Add::validate_plist($n->{plist}, $state);
+ }
+ if (@{$state->{colliding}} > 0) {
+ require OpenBSD::CollisionReport;
+
+ OpenBSD::CollisionReport::collision_report($state->{colliding}, $state);
+ }
+ if (defined $state->{overflow}) {
+ OpenBSD::Vstat::tally();
+ }
+ if ($state->{problems}) {
+ require OpenBSD::Error;
+ OpenBSD::Error::Fatal "fatal issues in ", $self->print;
+ }
+ OpenBSD::Vstat::synchronize();
+}
+
+sub compute_size
+{
+ my ($self, $state) = @_;
+ for my $h ($self->older_to_do, $self->newer) {
+ $h->{totsize} = $h->{plist}->compute_size;
+ }
+}
+
+# temporary shortcut
+sub handle
+{
+ my $self = shift;
+ if (defined $self->{newer}) {
+ return $self->{newer}[0];
+ } else {
+ return undef;
+ }
+}
+
+# temporary creator
+sub create_new
+{
+ my ($class, $pkgname) = @_;
+ my $set = $class->new;
+ $set->add_newer(OpenBSD::Handle->create_new($pkgname));
+ return $set;
+}
+
+sub from_location
+{
+ my ($class, $location) = @_;
+ my $set = $class->new;
+ $set->add_newer(OpenBSD::Handle->from_location($location));
+ return $set;
+}
+
+package OpenBSD::PackingList;
+sub compute_size
+{
+ my $plist = shift;
+ my $totsize = 0;
+ $plist->visit('compute_size', \$totsize);
+ $totsize = 1 if $totsize == 0;
+ $plist->{totsize} = $totsize;
+}
+
+package OpenBSD::PackingElement;
+sub mark_progress
+{
+}
+
+sub compute_size
+{
+}
+
+package OpenBSD::PackingElement::FileBase;
+sub mark_progress
+{
+ my ($self, $progress, $donesize, $totsize) = @_;
+ return unless defined $self->{size};
+ $$donesize += $self->{size};
+ $progress->show($$donesize, $totsize);
+}
+
+sub compute_size
+{
+ my ($self, $totsize) = @_;
+
+ $$totsize += $self->{size} if defined $self->{size};
+}
+
+package OpenBSD::PackingElement::Sample;
+sub compute_size
+{
+ &OpenBSD::PackingElement::FileBase::compute_size;
+}
+
1;
diff --git a/usr.sbin/pkg_add/OpenBSD/Vstat.pm b/usr.sbin/pkg_add/OpenBSD/Vstat.pm
index 9bf195b6284..8774492ff97 100644
--- a/usr.sbin/pkg_add/OpenBSD/Vstat.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Vstat.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Vstat.pm,v 1.42 2007/06/26 14:40:25 espie Exp $
+# $OpenBSD: Vstat.pm,v 1.43 2007/06/30 11:38:38 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -243,317 +243,4 @@ sub avail
return 1;
}
-# Here we stuff things common to pkg_add and pkg_delete which do not warrant
-# their own file yet.
-package OpenBSD::SharedItemsRecorder;
-sub new
-{
- my $class = shift;
- return bless {}, $class;
-}
-
-sub is_empty
-{
- my $self = shift;
- return !(defined $self->{dirs} or defined $self->{users} or
- defined $self->{groups});
-}
-
-sub cleanup
-{
- my ($self, $state) = @_;
- return if $self->is_empty or $state->{not};
-
- require OpenBSD::SharedItems;
- OpenBSD::SharedItems::cleanup($self, $state);
-}
-
-package OpenBSD::pkg_foo::State;
-use OpenBSD::Error;
-our @ISA=(qw(OpenBSD::Error));
-
-sub progress
-{
- my $self = shift;
- return $self->{progressmeter};
-}
-
-sub setup_progressmeter
-{
- my ($self, $opt_x) = @_;
- if (!$opt_x && !$self->{beverbose}) {
- require OpenBSD::ProgressMeter;
- $self->{progressmeter} = OpenBSD::ProgressMeter->new;
- } else {
- $self->{progressmeter} = bless {}, "OpenBSD::StubProgress";
- }
-}
-
-sub check_root
-{
- my $state = shift;
- if ($< && !$state->{forced}->{nonroot}) {
- if ($state->{not}) {
- Warn "$0 should be run as root\n";
- } else {
- Fatal "$0 must be run as root";
- }
- }
-}
-
-package OpenBSD::StubProgress;
-sub clear {}
-
-sub show {}
-
-sub message {}
-
-sub next {}
-
-sub set_header {}
-
-# fairly non-descriptive name. Used to store various package information
-# during installs and updates.
-package OpenBSD::Handle;
-
-use constant {
- BAD_PACKAGE => 1,
- CANT_INSTALL => 2,
- ALREADY_INSTALLED => 3,
- NOT_FOUND => 4
-};
-
-sub new
-{
- my $class = shift;
- return bless {}, $class;
-}
-
-sub set_error
-{
- my ($self, $error) = @_;
- $self->{error} = $error;
-}
-
-sub has_error
-{
- my ($self, $error) = @_;
- if (!defined $self->{error}) {
- return undef;
- }
- if (defined $error) {
- return $self->{error} eq $error;
- }
- return $self->{error};
-}
-
-sub create_old
-{
-
- my ($class, $pkgname, $state) = @_;
- my $self= $class->new;
- $self->{pkgname} = $pkgname;
-
- require OpenBSD::PackageRepository::Installed;
-
- my $location = OpenBSD::PackageRepository::Installed->new->find($pkgname, $state->{arch});
- if (!defined $location) {
- $self->set_error(NOT_FOUND);
- } else {
- $self->{location} = $location;
- my $plist = $location->plist;
- if (!defined $plist) {
- $self->set_error(BAD_PACKAGE);
- } else {
- $self->{plist} = $plist;
- }
- }
- return $self;
-}
-
-sub create_new
-{
- my ($class, $pkg) = @_;
- my $handle = $class->new;
- $handle->{pkgname} = $pkg;
- $handle->{tweaked} = 0;
- return $handle;
-}
-
-sub from_location
-{
- my ($class, $location) = @_;
- my $handle = $class->new;
- $handle->{pkgname} = $location->{name};
- $handle->{location} = $location;
- $handle->{tweaked} = 0;
- return $handle;
-}
-
-package OpenBSD::UpdateSet;
-sub new
-{
- my $class = shift;
- return bless {newer => [], older => []}, $class;
-}
-
-sub add_newer
-{
- my ($self, @handles) = @_;
- push(@{$self->{newer}}, @handles);
-}
-
-sub add_older
-{
- my ($self, @handles) = @_;
- push(@{$self->{older}}, @handles);
-}
-
-sub newer
-{
- my $self =shift;
- return @{$self->{newer}};
-}
-
-sub older
-{
- my $self = shift;
- return @{$self->{older}};
-}
-
-sub older_to_do
-{
- my $self = shift;
- # XXX in `combined' updates, some dependencies may remove extra
- # packages, so we do a double-take on the list of packages we
- # are actually replacing... for now, until we merge update sets.
- require OpenBSD::PackageInfo;
- my @l = ();
- for my $h ($self->older) {
- if (OpenBSD::PackageInfo::is_installed($h->{pkgname})) {
- push(@l, $h);
- }
- }
- return @l;
-}
-
-sub print
-{
- my $self = shift;
- my @l = ();
- if (defined $self->{newer}) {
- push(@l, "installing", map {$_->{pkgname}} $self->newer);
- }
- if (defined $self->{older} && @{$self->{older}} > 0) {
- push(@l, "deinstalling", map {$_->{pkgname}} $self->older);
- }
- return join(' ', @l);
-}
-
-sub validate_plists
-{
- my ($self, $state) = @_;
- $state->{problems} = 0;
-
- for my $o ($self->older_to_do) {
- require OpenBSD::Delete;
- OpenBSD::Delete::validate_plist($o->{plist}, $state);
- }
- $state->{colliding} = [];
- for my $n ($self->newer) {
- require OpenBSD::Add;
- OpenBSD::Add::validate_plist($n->{plist}, $state);
- }
- if (@{$state->{colliding}} > 0) {
- require OpenBSD::CollisionReport;
-
- OpenBSD::CollisionReport::collision_report($state->{colliding}, $state);
- }
- if (defined $state->{overflow}) {
- OpenBSD::Vstat::tally();
- }
- if ($state->{problems}) {
- require OpenBSD::Error;
- OpenBSD::Error::Fatal "fatal issues in ", $self->print;
- }
- OpenBSD::Vstat::synchronize();
-}
-
-sub compute_size
-{
- my ($self, $state) = @_;
- for my $h ($self->older_to_do, $self->newer) {
- $h->{totsize} = $h->{plist}->compute_size;
- }
-}
-
-# temporary shortcut
-sub handle
-{
- my $self = shift;
- if (defined $self->{newer}) {
- return $self->{newer}[0];
- } else {
- return undef;
- }
-}
-
-# temporary creator
-sub create_new
-{
- my ($class, $pkgname) = @_;
- my $set = $class->new;
- $set->add_newer(OpenBSD::Handle->create_new($pkgname));
- return $set;
-}
-
-sub from_location
-{
- my ($class, $location) = @_;
- my $set = $class->new;
- $set->add_newer(OpenBSD::Handle->from_location($location));
- return $set;
-}
-
-package OpenBSD::PackingList;
-sub compute_size
-{
- my $plist = shift;
- my $totsize = 0;
- $plist->visit('compute_size', \$totsize);
- $totsize = 1 if $totsize == 0;
- $plist->{totsize} = $totsize;
-}
-
-package OpenBSD::PackingElement;
-sub mark_progress
-{
-}
-
-sub compute_size
-{
-}
-
-package OpenBSD::PackingElement::FileBase;
-sub mark_progress
-{
- my ($self, $progress, $donesize, $totsize) = @_;
- return unless defined $self->{size};
- $$donesize += $self->{size};
- $progress->show($$donesize, $totsize);
-}
-
-sub compute_size
-{
- my ($self, $totsize) = @_;
-
- $$totsize += $self->{size} if defined $self->{size};
-}
-
-package OpenBSD::PackingElement::Sample;
-sub compute_size
-{
- &OpenBSD::PackingElement::FileBase::compute_size;
-}
-
1;
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index bef175003ce..be6e75d2c11 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.327 2007/06/26 17:58:23 espie Exp $
+# $OpenBSD: pkg_add,v 1.328 2007/06/30 11:38:38 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -33,7 +33,7 @@ use OpenBSD::Interactive;
use OpenBSD::Add;
use OpenBSD::SharedLibs;
use OpenBSD::Paths;
-# use OpenBSD::UpdateSet;
+use OpenBSD::UpdateSet;
my $bad = 0;
diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete
index c8acd8f19f4..232662d0e19 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.109 2007/06/16 09:29:37 espie Exp $
+# $OpenBSD: pkg_delete,v 1.110 2007/06/30 11:38:38 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -27,7 +27,7 @@ use OpenBSD::Delete;
use OpenBSD::PackageInfo;
use OpenBSD::Vstat;
use OpenBSD::Paths;
-# use OpenBSD::UpdateSet;
+use OpenBSD::UpdateSet;
our %forced = ();
our $not;