diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2007-06-06 15:31:07 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2007-06-06 15:31:07 +0000 |
commit | 90cb3427e2ac45ac819802bb9297290a0e9ec312 (patch) | |
tree | 44b098ac0b559accdce2f57709d4b70b33fe62bb /usr.sbin/pkg_add | |
parent | c22f5e4243f80337cc5b0d73449cc61db1e5508a (diff) |
separate the size computation from other operations in `prepare_for_addition'
`prepare_for_deletion' -> move that to Vstat, as it is common code.
Do the splitting of libraries through a deep copy and shallow copy, so that
we keep any State information related to libraries (like special group/owners).
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Add.pm | 9 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Delete.pm | 7 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Replace.pm | 82 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Vstat.pm | 31 |
4 files changed, 93 insertions, 36 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Add.pm b/usr.sbin/pkg_add/OpenBSD/Add.pm index b0558563006..5a35bcb0220 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.73 2007/06/06 12:32:09 espie Exp $ +# $OpenBSD: Add.pm,v 1.74 2007/06/06 15:31:06 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -59,11 +59,8 @@ sub validate_plist { my ($plist, $state) = @_; - $state->{totsize} = 0; - $plist->prepare_for_addition($state, $plist->pkgname); - $state->{totsize} = 1 if $state->{totsize} == 0; - $plist->{totsize} = $state->{totsize}; + return $plist->compute_size; } sub record_partial_installation @@ -309,7 +306,6 @@ sub prepare_for_addition $state->{problems}++; return; } - $state->{totsize} += $self->{size} if defined $self->{size}; my $s = OpenBSD::Vstat::add($fname, $self->{size}, \$pkgname); return unless defined $s; if ($s->{ro}) { @@ -430,7 +426,6 @@ sub prepare_for_addition return; } my $size = $self->{copyfrom}->{size}; - $state->{totsize} += $size if defined $size; my $s = OpenBSD::Vstat::add($fname, $size, \$pkgname); return unless defined $s; if ($s->{ro}) { diff --git a/usr.sbin/pkg_add/OpenBSD/Delete.pm b/usr.sbin/pkg_add/OpenBSD/Delete.pm index dd5a8799fc3..b55f5ab1800 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.63 2007/06/06 12:32:09 espie Exp $ +# $OpenBSD: Delete.pm,v 1.64 2007/06/06 15:31:06 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -84,10 +84,8 @@ sub validate_plist { my ($plist, $state) = @_; - $state->{totsize} = 0; $plist->prepare_for_deletion($state, $plist->pkgname); - $state->{totsize} = 1 if $state->{totsize} == 0; - $plist->{totsize} = $state->{totsize}; + return $plist->compute_size; } sub remove_packing_info @@ -330,7 +328,6 @@ sub prepare_for_deletion my ($self, $state, $pkgname) = @_; my $fname = $state->{destdir}.$self->fullname; - $state->{totsize} += $self->{size} if defined $self->{size}; my $s = OpenBSD::Vstat::remove($fname, $self->{size}); return unless defined $s; if ($s->{ro}) { diff --git a/usr.sbin/pkg_add/OpenBSD/Replace.pm b/usr.sbin/pkg_add/OpenBSD/Replace.pm index 3b6f6b8d606..13fef63eb67 100644 --- a/usr.sbin/pkg_add/OpenBSD/Replace.pm +++ b/usr.sbin/pkg_add/OpenBSD/Replace.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Replace.pm,v 1.34 2007/06/06 14:09:47 espie Exp $ +# $OpenBSD: Replace.pm,v 1.35 2007/06/06 15:31:06 espie Exp $ # # Copyright (c) 2004-2006 Marc Espie <espie@openbsd.org> # @@ -54,6 +54,12 @@ sub unmark_lib { } +sub separate_element +{ + my ($self, $libs, $c1, $c2) = @_; + $c2->{$self} = 1; +} + sub extract_and_progress { my ($self, $state, $donesize, $totsize) = @_; @@ -64,6 +70,22 @@ sub extract_and_progress $self->mark_progress($state->progress, $donesize, $totsize); } +package OpenBSD::PackingElement::Meta; + +sub separate_element +{ + my ($self, $libs, $c1, $c2) = @_; + $c1->{$self} = 1; + $c2->{$self} = 1; +} + +package OpenBSD::PackingElement::State; + +sub separate_element +{ + &OpenBSD::PackingElement::Meta::separate_element; +} + package OpenBSD::PackingElement::FileBase; use OpenBSD::Temp; @@ -164,6 +186,18 @@ sub update_issue($$) return '@unexec '.$self->{expanded}; } +package OpenBSD::PackingElement::Depend; +sub separate_element +{ + &OpenBSD::PackingElement::separate_element; +} + +package OpenBSD::PackingElement::SpecialFile; +sub separate_element +{ + &OpenBSD::PackingElement::separate_element; +} + package OpenBSD::PackingElement::Dependency; use OpenBSD::Error; @@ -206,6 +240,16 @@ sub mark_lib $libs->{$libname} = 1; } +sub separate_element +{ + my ($self, $libs, $c1, $c2) = @_; + if ($libs->{$self->fullname}) { + $c1->{$self} = 1; + } else { + $c2->{$self} = 1; + } +} + sub unmark_lib { my ($self, $libs, $libpatterns) = @_; @@ -314,21 +358,26 @@ sub is_safe return $state->{okay}; } +sub split_some_libs +{ + my ($plist, $libs) = @_; + my $c1 = {}; + my $c2 = {}; + $plist->separate_element($libs, $c1, $c2); + my $p1 = $plist->make_deep_copy($c1); + my $p2 = $plist->make_shallow_copy($c2); + return ($p1, $p2); +} + # create a packing-list with only the libraries we want to keep around. sub split_libs { my ($plist, $to_split) = @_; - my $items = []; - - my $splitted = OpenBSD::PackingList->new; + (my $splitted, $plist) = split_some_libs($plist, $to_split); $splitted->set_pkgname(".libs-".$plist->pkgname); - if (defined $plist->{conflict}) { - for my $item (@{$plist->{conflict}}) { - $item->clone->add_object($splitted); - } - } + if (defined $plist->{'no-default-conflict'}) { # we conflict with the package we just removed... OpenBSD::PackingElement::Conflict->add($splitted, $plist->pkgname); @@ -338,19 +387,6 @@ sub split_libs my $stem = OpenBSD::PackageName::splitstem($plist->pkgname); OpenBSD::PackingElement::Conflict->add($splitted, $stem."-*"); } - - for my $item (@{$plist->{items}}) { - if ($item->isa("OpenBSD::PackingElement::Lib") && - defined $to_split->{$item->fullname}) { - $item->clone->add_object($splitted); - next; - } - if ($item->isa("OpenBSD::PackingElement::Cwd")) { - $item->clone->add_object($splitted); - } - push(@$items, $item); - } - $plist->{items} = $items; return ($plist, $splitted); } @@ -391,6 +427,8 @@ sub save_old_libraries print "Libraries to keep: ", join(",", sort(keys %$libs)), "\n" if $state->{beverbose}; ($o->{plist}, my $stub_list) = split_libs($o->{plist}, $libs); + $o->{totsize} = $o->{plist}->compute_size; + my $stub_name = $stub_list->pkgname; my $dest = installed_info($stub_name); print "Keeping them in $stub_name\n" if $state->{beverbose}; diff --git a/usr.sbin/pkg_add/OpenBSD/Vstat.pm b/usr.sbin/pkg_add/OpenBSD/Vstat.pm index 523f25b3935..2830db844bc 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.34 2007/06/05 23:19:00 espie Exp $ +# $OpenBSD: Vstat.pm,v 1.35 2007/06/06 15:31:06 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -411,7 +411,7 @@ sub validate_plists my ($self, $state) = @_; $state->{problems} = 0; - for my $o ($self->older) { + for my $o ($self->older_to_do) { require OpenBSD::Delete; $o->{totsize} = OpenBSD::Delete::validate_plist($o->{plist}, $state); @@ -448,11 +448,25 @@ sub handle } } +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 { @@ -462,4 +476,17 @@ sub mark_progress $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; |