diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2007-05-30 12:52:08 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2007-05-30 12:52:08 +0000 |
commit | 3d5d9adbd951905c2763f1dc6bb67dc2fb2f767d (patch) | |
tree | 36a5dd0108b4d0cc5151e3e7c1b4da17dee481f7 | |
parent | 56c084c338d17c6fd1b01bc15ad242674a0b314f (diff) |
simplify the way partial installations get recorded: store elements
already installed in a hash, and do a shallow copy of the list when
necessary, using make_copy.
This removes a lot of action-at-a-distance in packing-list elements.
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Add.pm | 29 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackingElement.pm | 3 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Replace.pm | 10 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_add | 18 |
4 files changed, 35 insertions, 25 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Add.pm b/usr.sbin/pkg_add/OpenBSD/Add.pm index 3f4da7dc96a..8bb37288bbf 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.62 2007/05/30 11:40:07 espie Exp $ +# $OpenBSD: Add.pm,v 1.63 2007/05/30 12:52:07 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -68,17 +68,17 @@ sub validate_plist sub record_partial_installation { - my $plist = shift; + my ($plist, $h) = @_; use OpenBSD::PackingElement; + my $n = $plist->make_copy($h); my $borked = borked_package($plist->pkgname); - # fix packing list for pkg_delete - $plist->{items} = $plist->{done}; - + $n->set_pkgname($borked); + # last file may have not copied correctly - my $last = $plist->{items}->[@{$plist->{items}}-1]; - if ($last->IsFile && defined($last->{md5})) { + my $last = $n->{state}->{lastfile}; + if (defined $last && defined($last->{md5})) { require OpenBSD::md5; my $old = $last->{md5}; @@ -94,9 +94,7 @@ sub record_partial_installation unpack('H*', $old), " to ", unpack('H*', $last->{md5}), "\n"; } } - OpenBSD::PackingElement::Cwd->add($plist, '.'); - $plist->{name}->{name} = $borked; - register_installation($plist); + register_installation($n); return $borked; } @@ -112,6 +110,8 @@ sub prepare_for_addition sub install { + my ($self, $state) = @_; + $state->{partial}->{$self} = 1; } sub copy_info @@ -206,6 +206,7 @@ sub prepare_for_addition sub install { my ($self, $state) = @_; + $state->{partial}->{$self} = 1; my $auth = $self->{name}; print "adding ", $self->type, " $auth\n" if $state->{verbose}; return if $state->{not}; @@ -252,6 +253,7 @@ sub install my ($self, $state) = @_; my $name = $self->{name}; + $state->{partial}->{$self} = 1; open(my $pipe, '-|', '/sbin/sysctl', '-n', $name); my $actual = <$pipe>; chomp $actual; @@ -301,6 +303,7 @@ sub prepare_for_addition sub install { my ($self, $state) = @_; + $state->{partial}->{$self} = 1; my $fullname = $self->fullname; my $destdir = $state->{destdir}; @@ -312,10 +315,8 @@ sub install File::Path::mkpath(dirname($destdir.$fullname)); if (defined $self->{link}) { link($destdir.$self->{link}, $destdir.$fullname); - delete $self->{zap}; } elsif (defined $self->{symlink}) { symlink($self->{symlink}, $destdir.$fullname); - delete $self->{zap}; } else { rename($self->{tempname}, $destdir.$fullname) or Fatal "Can't move ", $self->{tempname}, " to $fullname: $!"; @@ -383,6 +384,7 @@ sub install { my ($self, $state) = @_; + $state->{partial}->{$self} = 1; $state->{end_faked} = 1; } @@ -420,6 +422,7 @@ sub install { my ($self, $state) = @_; + $state->{partial}->{$self} = 1; my $destdir = $state->{destdir}; my $filename = $destdir.$self->fullname; my $orig = $self->{copyfrom}; @@ -519,6 +522,7 @@ package OpenBSD::PackingElement::Dir; sub install { my ($self, $state) = @_; + $state->{partial}->{$self} = 1; my $fullname = $self->fullname; my $destdir = $state->{destdir}; @@ -535,6 +539,7 @@ sub install { my ($self, $state) = @_; + $state->{partial}->{$self} = 1; $self->run($state); } diff --git a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm index 9e81dbf5acf..32f5285e2a1 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackingElement.pm,v 1.119 2007/05/30 12:29:19 espie Exp $ +# $OpenBSD: PackingElement.pm,v 1.120 2007/05/30 12:52:07 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -265,7 +265,6 @@ use File::Basename; sub write { my ($self, $fh) = @_; - return if defined $self->{zap}; print $fh "\@comment no checksum\n" if defined $self->{nochecksum}; $self->SUPER::write($fh); if (defined $self->{md5}) { diff --git a/usr.sbin/pkg_add/OpenBSD/Replace.pm b/usr.sbin/pkg_add/OpenBSD/Replace.pm index 82b8f851524..f96651db371 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.22 2007/05/27 22:39:09 espie Exp $ +# $OpenBSD: Replace.pm,v 1.23 2007/05/30 12:52:07 espie Exp $ # # Copyright (c) 2004-2006 Marc Espie <espie@openbsd.org> # @@ -42,6 +42,8 @@ sub update_issue($$) { undef } sub extract { + my ($self, $state) = @_; + $state->{partial}->{$self} = 1; } sub mark_lib @@ -62,10 +64,10 @@ sub extract my $file = $self->prepare_to_extract($state); if (defined $self->{link} || defined $self->{symlink}) { - $self->{zap} = 1; return; } + $state->{partial}->{$self} = 1; my $d = dirname($file->{destdir}.$file->{name}); while (!-d $d && -e _) { $d = dirname($d); @@ -94,11 +96,13 @@ sub extract my $destdir = $state->{destdir}; return if -e $destdir.$fullname; + $state->{partial}->{$self} = 1; print "new directory ", $destdir, $fullname, "\n" if $state->{very_verbose}; return if $state->{not}; File::Path::mkpath($destdir.$fullname); } + package OpenBSD::PackingElement::Sample; sub extract { @@ -290,7 +294,7 @@ sub split_libs my $splitted = OpenBSD::PackingList->new; - OpenBSD::PackingElement::Name->add($splitted, ".libs-".$plist->pkgname); + $splitted->set_pkgname(".libs-".$plist->pkgname); if (defined $plist->{conflict}) { for my $item (@{$plist->{conflict}}) { $item->clone()->add_object($splitted); diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add index a199d4be77d..f00fd76de3a 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.291 2007/05/30 11:40:07 espie Exp $ +# $OpenBSD: pkg_add,v 1.292 2007/05/30 12:52:06 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -322,8 +322,8 @@ sub save_partial_set return () if $not; my @l = (); for my $h ($set->newer) { - next unless defined $h->{plist}->{done}; - push(@l, OpenBSD::Add::record_partial_installation($h->{plist})); + next unless defined $h->{partial}; + push(@l, OpenBSD::Add::record_partial_installation($h->{plist}, $h->{partial})); } return @l; } @@ -384,7 +384,8 @@ sub really_add OpenBSD::Replace::save_old_libraries($set, $state); my $donesize = 0; - $plist->{done} = []; + $handle->{partial} = {}; + $state->{partial} = $handle->{partial}; my $totsize = $handle->{totsize}; $state->{archive} = $handle->{location}; for my $item (@{$plist->{items}}) { @@ -394,7 +395,6 @@ sub really_add Warn $_; $errors++; }; - push(@{$plist->{done}}, $item); if (defined $item->{size}) { $donesize += $item->{size}; OpenBSD::ProgressMeter::show($donesize, $totsize); @@ -462,6 +462,10 @@ sub really_add $state->{archive} = $handle->{location}; my $donesize = 0; $state->{end_faked} = 0; + if (!defined $handle->{partial}) { + $handle->{partial} = {}; + } + $state->{partial} = $handle->{partial}; for my $item (@{$plist->{groups}}, @{$plist->{users}}, @{$plist->{items}}) { try { $item->install($state); } @@ -470,9 +474,6 @@ sub really_add $errors++; }; last if $errors; - if (!$replacing) { - push(@{$plist->{done}}, $item); - } if (defined $item->{size}) { $donesize += $item->{size}; OpenBSD::ProgressMeter::show($donesize, $totsize); @@ -510,6 +511,7 @@ sub really_add OpenBSD::SharedLibs::add_libs_from_plist($plist); $plist->to_cache; OpenBSD::Add::register_installation($plist); + delete $handle->{partial}; if (defined $handle->{solver}) { $handle->{solver}->register_dependencies; } |