summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2014-01-11 11:54:44 +0000
committerMarc Espie <espie@cvs.openbsd.org>2014-01-11 11:54:44 +0000
commitbd57a2be98cf0daca26fcda3b4f7184d9e3d90d7 (patch)
tree7b6254786ab4b338d66d564aa175f759d55aad76
parent7e816aa13e3d87647ad11c61f6d789ff1072e00e (diff)
simplify code: always extract, then install, so that initial installations
and updates are more similar.
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Add.pm197
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PkgAdd.pm47
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Replace.pm115
3 files changed, 164 insertions, 195 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Add.pm b/usr.sbin/pkg_add/OpenBSD/Add.pm
index 352d7dd3dfd..b4c6d7bfde8 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.141 2014/01/11 11:51:01 espie Exp $
+# $OpenBSD: Add.pm,v 1.142 2014/01/11 11:54:43 espie Exp $
#
# Copyright (c) 2003-2014 Marc Espie <espie@openbsd.org>
#
@@ -102,13 +102,20 @@ sub perform_installation
{
my ($handle, $state) = @_;
- $state->{archive} = $handle->{location};
- $handle->{partial} //= {};
- $state->{partial} = $handle->{partial};
$state->progress->visit_with_size($handle->{plist}, 'install', $state);
$handle->{location}->finish_and_close;
}
+sub perform_extraction
+{
+ my ($handle, $state) = @_;
+
+ $handle->{partial} = {};
+ $state->{partial} = $handle->{partial};
+ $state->{archive} = $handle->{location};
+ $state->progress->visit_with_size($handle->{plist}, 'extract', $state);
+}
+
my $user_tagged = {};
sub extract_pkgname
@@ -173,13 +180,22 @@ sub prepare_for_addition
{
}
-sub install
+sub extract
{
my ($self, $state) = @_;
+ $state->{partial}->{$self} = 1;
if ($state->{interrupted}) {
die "Interrupted";
}
+}
+
+sub install
+{
+ my ($self, $state) = @_;
$state->{partial}->{$self} = 1;
+ if ($state->{interrupted}) {
+ die "Interrupted";
+ }
}
sub copy_info
@@ -347,6 +363,7 @@ package OpenBSD::PackingElement::FileBase;
use OpenBSD::Error;
use File::Basename;
use File::Path;
+use OpenBSD::Temp;
sub prepare_for_addition
{
@@ -370,52 +387,6 @@ sub prepare_for_addition
}
}
-sub install
-{
- my ($self, $state) = @_;
- $self->SUPER::install($state);
- my $fullname = $self->fullname;
- my $destdir = $state->{destdir};
- if ($fullname =~ m,^$state->{localbase}/share/doc/pkg-readmes/,) {
- $state->{readmes}++;
- }
-
- if ($state->{extracted_first}) {
- if ($state->{not}) {
- $state->say("moving tempfile -> #1",
- $destdir.$fullname) if $state->verbose >= 5;
- return;
- }
- File::Path::mkpath(dirname($destdir.$fullname));
- if (defined $self->{link}) {
- link($destdir.$self->{link}, $destdir.$fullname);
- } elsif (defined $self->{symlink}) {
- symlink($self->{symlink}, $destdir.$fullname);
- } else {
- rename($self->{tempname}, $destdir.$fullname) or
- $state->fatal("can't move #1 to #2: #3",
- $self->{tempname}, $fullname, $!);
- $state->say("moving #1 -> #2",
- $self->{tempname}, $destdir.$fullname)
- if $state->verbose >= 5;
- undef $self->{tempname};
- }
- } else {
- my $file = $self->prepare_to_extract($state);
- $state->say("extracting #1", $destdir.$fullname)
- if $state->verbose >= 5;
- if ($state->{not}) {
- $state->{archive}->skip;
- return;
- } else {
- $file->create;
- $self->may_check_digest($file, $state);
-
- }
- }
- $self->set_modes($state, $destdir.$fullname);
-}
-
sub prepare_to_extract
{
my ($self, $state) = @_;
@@ -464,6 +435,100 @@ sub prepare_to_extract
return $file;
}
+sub extract
+{
+ my ($self, $state) = @_;
+
+ my $file = $self->prepare_to_extract($state);
+
+ if (defined $self->{link} || defined $self->{symlink}) {
+ $state->{archive}->skip;
+ return;
+ }
+
+ $self->SUPER::extract($state);
+
+ # figure out a safe directory where to put the temp file
+ my $d = dirname($file->{destdir}.$file->name);
+ # we go back up until we find an existing directory.
+ # hopefully this will be on the same file system.
+ while (!-d $d && -e _ || defined $state->{noshadow}->{$d}) {
+ $d = dirname($d);
+ }
+ if ($state->{not}) {
+ $state->say("extracting tempfile under #1", $d)
+ if $state->verbose >= 3;
+ $state->{archive}->skip;
+ } else {
+ if (!-e _) {
+ File::Path::mkpath($d);
+ }
+ my ($fh, $tempname) = OpenBSD::Temp::permanent_file($d, "pkg");
+ $self->{tempname} = $tempname;
+
+ # XXX don't apply destdir twice
+ $file->{destdir} = '';
+ $file->set_name($tempname);
+
+ if ($self->{tieto}) {
+ my $src = $self->{tieto}->realname($state);
+ unlink($tempname);
+ $state->say("linking #1 to #2", $src, $tempname)
+ if $state->verbose >= 3;
+ if (link($src, $tempname) ||
+ $state->copy_file($src, $tempname)) {
+ # we still need to adjust properties
+ $file->set_modes;
+ $state->{archive}->skip;
+ return;
+ }
+ # okay, it didn't work. recreate tempname.
+ open $fh, ">", $tempname;
+ }
+
+ $state->say("extracting #1", $tempname) if $state->verbose >= 3;
+
+ if (!$file->isFile) {
+ $state->fatal("can't extract #1, it's not a file",
+ $self->stringize);
+ }
+ $file->create;
+ $self->may_check_digest($file, $state);
+ }
+}
+
+sub install
+{
+ my ($self, $state) = @_;
+ $self->SUPER::install($state);
+ my $fullname = $self->fullname;
+ my $destdir = $state->{destdir};
+ if ($fullname =~ m,^$state->{localbase}/share/doc/pkg-readmes/,) {
+ $state->{readmes}++;
+ }
+
+ if ($state->{not}) {
+ $state->say("moving tempfile -> #1",
+ $destdir.$fullname) if $state->verbose >= 5;
+ return;
+ }
+ File::Path::mkpath(dirname($destdir.$fullname));
+ if (defined $self->{link}) {
+ link($destdir.$self->{link}, $destdir.$fullname);
+ } elsif (defined $self->{symlink}) {
+ symlink($self->{symlink}, $destdir.$fullname);
+ } else {
+ rename($self->{tempname}, $destdir.$fullname) or
+ $state->fatal("can't move #1 to #2: #3",
+ $self->{tempname}, $fullname, $!);
+ $state->say("moving #1 -> #2",
+ $self->{tempname}, $destdir.$fullname)
+ if $state->verbose >= 5;
+ undef $self->{tempname};
+ }
+ $self->set_modes($state, $destdir.$fullname);
+}
+
package OpenBSD::PackingElement::RcScript;
sub install
{
@@ -500,6 +565,10 @@ sub prepare_for_addition
}
}
+sub extract
+{
+}
+
sub install
{
my ($self, $state) = @_;
@@ -544,6 +613,9 @@ sub install
}
package OpenBSD::PackingElement::Sampledir;
+sub extract
+{
+}
sub install
{
@@ -606,6 +678,20 @@ sub install
}
package OpenBSD::PackingElement::Dir;
+sub extract
+{
+ my ($self, $state) = @_;
+ my $fullname = $self->fullname;
+ my $destdir = $state->{destdir};
+
+ return if -e $destdir.$fullname;
+ $self->SUPER::extract($state);
+ $state->say("new directory #1", $destdir.$fullname)
+ if $state->verbose >= 3;
+ return if $state->{not};
+ File::Path::mkpath($destdir.$fullname);
+}
+
sub install
{
my ($self, $state) = @_;
@@ -613,7 +699,8 @@ sub install
my $fullname = $self->fullname;
my $destdir = $state->{destdir};
- $state->say("new directory #1", $destdir.$fullname) if $state->verbose >= 5;
+ $state->say("new directory #1", $destdir.$fullname)
+ if $state->verbose >= 5;
return if $state->{not};
File::Path::mkpath($destdir.$fullname);
$self->set_modes($state, $destdir.$fullname);
@@ -692,12 +779,10 @@ sub copy_info
$self->fullname, $dest, $!);
}
-sub install
+sub extract
{
my ($self, $state) = @_;
- if (!$state->{extracted_first}) {
- $self->may_verify_digest($state);
- }
+ $self->may_verify_digest($state);
}
package OpenBSD::PackingElement::FCONTENTS;
diff --git a/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm b/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm
index c0aa991b002..662fc69ac11 100644
--- a/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm
@@ -1,7 +1,7 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: PkgAdd.pm,v 1.44 2014/01/09 20:20:01 espie Exp $
+# $OpenBSD: PkgAdd.pm,v 1.45 2014/01/11 11:54:43 espie Exp $
#
# Copyright (c) 2003-2014 Marc Espie <espie@openbsd.org>
#
@@ -740,42 +740,39 @@ sub really_add
OpenBSD::OldLibs->save($set, $state);
}
- if ($replacing && !$state->{delete_first}) {
- $state->{extracted_first} = 1;
- for my $handle ($set->newer) {
- next if $state->{size_only};
- $set->setup_header($state, $handle, "extracting");
+ if ($state->{delete_first}) {
+ delete_old_packages($set, $state);
+ }
- try {
- OpenBSD::Replace::perform_extraction($handle,
- $state);
- } catchall {
- unless ($state->{interrupted}) {
- $state->errsay($_);
- $errors++;
- }
- };
- if ($state->{interrupted} || $errors) {
- $state->fatal(partial_install("Installation of ".
- $handle->pkgname." failed", $set, $state));
+ for my $handle ($set->newer) {
+ next if $state->{size_only};
+ $set->setup_header($state, $handle, "extracting");
+
+ try {
+ OpenBSD::Add::perform_extraction($handle,
+ $state);
+ } catchall {
+ unless ($state->{interrupted}) {
+ $state->errsay($_);
+ $errors++;
}
+ };
+ if ($state->{interrupted} || $errors) {
+ $state->fatal(partial_install("Installation of ".
+ $handle->pkgname." failed", $set, $state));
}
- } else {
- $state->{extracted_first} = 0;
}
-
- if ($replacing) {
+ if (!$state->{delete_first}) {
delete_old_packages($set, $state);
}
iterate($set->newer, sub {
return if $state->{size_only};
my $handle = shift;
-
my $pkgname = $handle->pkgname;
my $plist = $handle->plist;
- $set->setup_header($state, $handle,
- $replacing ? "installing" : undef);
+
+ $set->setup_header($state, $handle, "installing");
$state->set_name_from_handle($handle, '+');
try {
diff --git a/usr.sbin/pkg_add/OpenBSD/Replace.pm b/usr.sbin/pkg_add/OpenBSD/Replace.pm
index 10524834263..f9ae8d4b10c 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.86 2014/01/09 20:20:01 espie Exp $
+# $OpenBSD: Replace.pm,v 1.87 2014/01/11 11:54:43 espie Exp $
#
# Copyright (c) 2004-2014 Marc Espie <espie@openbsd.org>
#
@@ -33,109 +33,6 @@ sub can_update
sub update_issue { undef }
-sub extract
-{
- my ($self, $state) = @_;
- $state->{partial}->{$self} = 1;
- if ($state->{interrupted}) {
- die "Interrupted";
- }
-}
-
-package OpenBSD::PackingElement::FileBase;
-use OpenBSD::Temp;
-
-sub extract
-{
- my ($self, $state) = @_;
-
- my $file = $self->prepare_to_extract($state);
-
- if (defined $self->{link} || defined $self->{symlink}) {
- $state->{archive}->skip;
- return;
- }
-
- $self->SUPER::extract($state);
-
- # figure out a safe directory where to put the temp file
- my $d = dirname($file->{destdir}.$file->name);
- # we go back up until we find an existing directory.
- # hopefully this will be on the same file system.
- while (!-d $d && -e _ || defined $state->{noshadow}->{$d}) {
- $d = dirname($d);
- }
- if ($state->{not}) {
- $state->say("extracting tempfile under #1", $d)
- if $state->verbose >= 3;
- $state->{archive}->skip;
- } else {
- if (!-e _) {
- File::Path::mkpath($d);
- }
- my ($fh, $tempname) = OpenBSD::Temp::permanent_file($d, "pkg");
- $self->{tempname} = $tempname;
-
- # XXX don't apply destdir twice
- $file->{destdir} = '';
- $file->set_name($tempname);
-
- if ($self->{tieto}) {
- my $src = $self->{tieto}->realname($state);
- unlink($tempname);
- $state->say("linking #1 to #2", $src, $tempname)
- if $state->verbose >= 3;
- if (link($src, $tempname) ||
- $state->copy_file($src, $tempname)) {
- # we still need to adjust properties
- $file->set_modes;
- $state->{archive}->skip;
- return;
- }
- # okay, it didn't work. recreate tempname.
- open $fh, ">", $tempname;
- }
-
- $state->say("extracting #1", $tempname) if $state->verbose >= 3;
-
- $file->create;
- $self->may_check_digest($file, $state);
- }
-}
-
-package OpenBSD::PackingElement::Dir;
-sub extract
-{
- my ($self, $state) = @_;
- my $fullname = $self->fullname;
- my $destdir = $state->{destdir};
-
- return if -e $destdir.$fullname;
- $self->SUPER::extract($state);
- $state->say("new directory #1", $destdir.$fullname)
- if $state->verbose >= 3;
- return if $state->{not};
- File::Path::mkpath($destdir.$fullname);
-}
-
-
-package OpenBSD::PackingElement::Sample;
-sub extract
-{
-}
-
-package OpenBSD::PackingElement::Sampledir;
-sub extract
-{
-}
-
-package OpenBSD::PackingElement::SpecialFile;
-sub extract
-{
- my ($self, $state) = @_;
- $self->may_verify_digest($state);
-}
-
package OpenBSD::PackingElement::Exec;
sub update_issue
{
@@ -162,16 +59,6 @@ sub update_issue { undef }
package OpenBSD::Replace;
-sub perform_extraction
-{
- my ($handle, $state) = @_;
-
- $handle->{partial} = {};
- $state->{partial} = $handle->{partial};
- $state->{archive} = $handle->{location};
- $state->progress->visit_with_size($handle->{plist}, 'extract', $state);
-}
-
sub check_plist_exec
{
my ($plist, $state, $new) = @_;