diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2009-11-16 14:42:19 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2009-11-16 14:42:19 +0000 |
commit | e1af5a0f736b329a05da47f95370d0f2d7421f03 (patch) | |
tree | 37d956d49c2d7bd4de7f4cec54a528f84a163407 /usr.sbin/pkg_add | |
parent | d9c6826637e56e7598b639022b391767a841c767 (diff) |
create a pseudo vstat object inside state, so that we can modify Vstat
interface very locally...
model hints objects like Locations, to uniformize further treatment.
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Add.pm | 14 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/AddDelete.pm | 58 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/CollisionReport.pm | 5 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Delete.pm | 10 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Tracker.pm | 7 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/UpdateSet.pm | 28 |
6 files changed, 91 insertions, 31 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Add.pm b/usr.sbin/pkg_add/OpenBSD/Add.pm index a2edd2951a9..bab630d2ada 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.96 2009/11/11 13:00:40 espie Exp $ +# $OpenBSD: Add.pm,v 1.97 2009/11/16 14:42:18 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -359,12 +359,12 @@ sub prepare_for_addition my ($self, $state, $pkgname) = @_; my $fname = $state->{destdir}.$self->fullname; # check for collisions with existing stuff - if (OpenBSD::Vstat::vexists($fname)) { + if ($state->vstat->exists($fname)) { push(@{$state->{colliding}}, $self); $state->{problems}++; return; } - my $s = OpenBSD::Vstat::add($fname, $self->{size}, \$pkgname); + my $s = $state->vstat->add($fname, $self->{size}, \$pkgname); return unless defined $s; if ($s->{ro}) { $s->report_ro($state, $fname); @@ -479,11 +479,11 @@ sub prepare_for_addition } my $fname = $state->{destdir}.$self->fullname; # If file already exists, we won't change it - if (OpenBSD::Vstat::vexists($fname)) { + if ($state->vstat->exists($fname)) { return; } my $size = $self->{copyfrom}->{size}; - my $s = OpenBSD::Vstat::add($fname, $size, \$pkgname); + my $s = $state->vstat->add($fname, $size, \$pkgname); return unless defined $s; if ($s->{ro}) { $s->report_ro($state, $fname); @@ -662,12 +662,12 @@ sub prepare_for_addition $size = (stat $cname)[7]; } if ($self->exec_on_add) { - my $s2 = OpenBSD::Vstat::filestat($cname); + my $s2 = $state->vstat->stat($cname); if (defined $s2 && $s2->{noexec}) { $s2->report_noexec($state, $cname); } } - my $s = OpenBSD::Vstat::add($fname, $self->{size}, \$pkgname); + my $s = $state->vstat->add($fname, $self->{size}, \$pkgname); return unless defined $s; if ($s->{ro}) { $s->report_ro($state, $fname); diff --git a/usr.sbin/pkg_add/OpenBSD/AddDelete.pm b/usr.sbin/pkg_add/OpenBSD/AddDelete.pm index 5d01755239f..48d3e1c8d66 100644 --- a/usr.sbin/pkg_add/OpenBSD/AddDelete.pm +++ b/usr.sbin/pkg_add/OpenBSD/AddDelete.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: AddDelete.pm,v 1.2 2009/11/16 12:53:27 espie Exp $ +# $OpenBSD: AddDelete.pm,v 1.3 2009/11/16 14:42:18 espie Exp $ # # Copyright (c) 2007-2009 Marc Espie <espie@openbsd.org> # @@ -23,10 +23,6 @@ our $state; our ($opt_n, $opt_x, $opt_v, $opt_B, $opt_L, $opt_i, $opt_q, $opt_c, $opt_I); $opt_v = 0; -sub setup_state -{ -} - sub handle_options { my ($opt_string, $hash, @usage) = @_; @@ -100,7 +96,7 @@ sub framework OpenBSD::PackingElement::Lib::ensure_ldconfig($state); OpenBSD::PackingElement::Fontdir::finish_fontdirs($state); if ($state->{beverbose}) { - OpenBSD::Vstat::tally(); + $state->vstat->tally; } $state->progress->clear; $state->log->dump; @@ -144,6 +140,50 @@ sub cleanup OpenBSD::SharedItems::cleanup($self, $state); } +package OpenBSD::MyStat; +use OpenBSD::Vstat; +sub new +{ + my $class = shift; + bless {}, $class +} + +sub add +{ + shift; + &OpenBSD::Vstat::add; +} + +sub remove +{ + shift; + &OpenBSD::Vstat::remove; +} + +sub exists +{ + shift; + &OpenBSD::Vstat::vexists; +} + +sub stat +{ + shift; + &OpenBSD::Vstat::filestat; +} + +sub tally +{ + shift; + &OpenBSD::Vstat::tally; +} + +sub synchronize +{ + shift; + &OpenBSD::Vstat::synchronize; +} + package OpenBSD::Log; use OpenBSD::Error; our @ISA = qw(OpenBSD::Error); @@ -174,9 +214,15 @@ sub init { my $self = shift; $self->{l} = OpenBSD::Log->new; + $self->{vstat} = OpenBSD::MyStat->new; $self->{progressmeter} = bless {}, "OpenBSD::StubProgress"; } +sub vstat +{ + return shift->{vstat}; +} + sub log { my $self = shift; diff --git a/usr.sbin/pkg_add/OpenBSD/CollisionReport.pm b/usr.sbin/pkg_add/OpenBSD/CollisionReport.pm index dacd3539111..8ae0d943845 100644 --- a/usr.sbin/pkg_add/OpenBSD/CollisionReport.pm +++ b/usr.sbin/pkg_add/OpenBSD/CollisionReport.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: CollisionReport.pm,v 1.26 2009/11/15 09:01:55 espie Exp $ +# $OpenBSD: CollisionReport.pm,v 1.27 2009/11/16 14:42:18 espie Exp $ # # Copyright (c) 2003-2006 Marc Espie <espie@openbsd.org> # @@ -21,7 +21,6 @@ use warnings; package OpenBSD::CollisionReport; use OpenBSD::PackingList; use OpenBSD::PackageInfo; -use OpenBSD::Vstat; sub find_collisions { @@ -29,7 +28,7 @@ sub find_collisions my $verbose = $state->{verbose}; my $bypkg = {}; for my $name (keys %$todo) { - my $p = OpenBSD::Vstat::vexists $name; + my $p = $state->vstat->exists($name); if (ref $p) { my $pkg = $$p; push(@{$bypkg->{$pkg}}, $name); diff --git a/usr.sbin/pkg_add/OpenBSD/Delete.pm b/usr.sbin/pkg_add/OpenBSD/Delete.pm index 64ac8838d55..ef3d4c8294e 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.87 2009/11/11 13:00:40 espie Exp $ +# $OpenBSD: Delete.pm,v 1.88 2009/11/16 14:42:18 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -20,7 +20,6 @@ use warnings; package OpenBSD::Delete; use OpenBSD::Error; -use OpenBSD::Vstat; use OpenBSD::PackageInfo; use OpenBSD::RequiredBy; use OpenBSD::Paths; @@ -113,7 +112,7 @@ sub delete_package $plist->compute_size; Fatal "fatal issues in deinstalling $pkgname" if $state->{problems}; - OpenBSD::Vstat::synchronize(); + $state->vstat->synchronize; delete_plist($plist, $state); $state->progress->next; @@ -361,14 +360,13 @@ sub should_run package OpenBSD::PackingElement::FileBase; use OpenBSD::Error; -use OpenBSD::Vstat; sub prepare_for_deletion { my ($self, $state, $pkgname) = @_; my $fname = $state->{destdir}.$self->fullname; - my $s = OpenBSD::Vstat::remove($fname, $self->{size}); + my $s = $state->vstat->remove($fname, $self->{size}); return unless defined $s; if ($s->{ro}) { $s->report_ro($state, $fname); @@ -459,7 +457,7 @@ sub prepare_for_deletetion if (!defined $size) { $size = (stat $fname)[7]; } - my $s = OpenBSD::Vstat::remove($fname, $self->{size}); + my $s = $state->vstat->remove($fname, $self->{size}); return unless defined $s; if ($s->{ro}) { $s->report_ro($state, $fname); diff --git a/usr.sbin/pkg_add/OpenBSD/Tracker.pm b/usr.sbin/pkg_add/OpenBSD/Tracker.pm index ce505d2c4f0..f94ad253b40 100644 --- a/usr.sbin/pkg_add/OpenBSD/Tracker.pm +++ b/usr.sbin/pkg_add/OpenBSD/Tracker.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Tracker.pm,v 1.8 2009/11/10 11:36:56 espie Exp $ +# $OpenBSD: Tracker.pm,v 1.9 2009/11/16 14:42:18 espie Exp $ # # Copyright (c) 2009 Marc Espie <espie@openbsd.org> # @@ -44,12 +44,9 @@ sub add_set for my $n ($set->newer) { $self->{to_install}->{$n->pkgname} = $set; } - for my $n ($set->older) { + for my $n ($set->older, $set->hints) { $self->{to_update}->{$n->pkgname} = $set; } - for my $n ($set->hints) { - $self->{to_update}->{$n} = $set; - } return $self; } diff --git a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm index f129e3b9ea0..d78ce1e3ca2 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.24 2009/11/16 12:20:32 espie Exp $ +# $OpenBSD: UpdateSet.pm,v 1.25 2009/11/16 14:42:18 espie Exp $ # # Copyright (c) 2007 Marc Espie <espie@openbsd.org> # @@ -35,6 +35,19 @@ use strict; use warnings; +# hints should behave like locations +package OpenBSD::hint; +sub new +{ + my ($class, $name) = @_; + bless {name => $name}, $class; +} + +sub pkgname +{ + return shift->{name}; +} + package OpenBSD::UpdateSet; sub new { @@ -52,7 +65,9 @@ sub add_newer sub add_hints { my ($self, @hints) = @_; - push(@{$self->{hints}}, @hints); + for my $h (@hints) { + push(@{$self->{hints}}, OpenBSD::hint->new($h)); + } return $self; } @@ -82,6 +97,11 @@ sub hints my $self =shift; return @{$self->{hints}}; } +sub hint_names +{ + my $self =shift; + return map {$_->pkgname} $self->hints; +} sub older_names { @@ -163,13 +183,13 @@ sub validate_plists OpenBSD::CollisionReport::collision_report($state->{colliding}, $state); } if (defined $state->{overflow}) { - OpenBSD::Vstat::tally(); + $state->vstat->tally; } if ($state->{problems}) { require OpenBSD::Error; OpenBSD::Error::Fatal "fatal issues in ", $self->print; } - OpenBSD::Vstat::synchronize(); + $state->vstat->synchronize; } sub compute_size |