summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2007-04-29 12:31:55 +0000
committerMarc Espie <espie@cvs.openbsd.org>2007-04-29 12:31:55 +0000
commit73a7912043f5b56fcc4cbf944ca64884b134534b (patch)
treea5451fcb34b5dd7adf1fe1269e16ffcde9f676ea /usr.sbin/pkg_add
parent8bfc57ca0f53ee0798ddd6dad317ecbac9395136 (diff)
now that checksum creation uses OO methods, reuse the same code for
create_checksum and verify_checksum.
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r--usr.sbin/pkg_add/pkg_create46
1 files changed, 17 insertions, 29 deletions
diff --git a/usr.sbin/pkg_add/pkg_create b/usr.sbin/pkg_add/pkg_create
index 84bb1f35815..43b87febf87 100644
--- a/usr.sbin/pkg_add/pkg_create
+++ b/usr.sbin/pkg_add/pkg_create
@@ -1,6 +1,6 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_create,v 1.62 2007/04/29 12:26:32 espie Exp $
+# $OpenBSD: pkg_create,v 1.63 2007/04/29 12:31:54 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -179,54 +179,42 @@ sub verify_checksum
package OpenBSD::PackingElement::FileBase;
use OpenBSD::md5;
-sub create_checksum
+sub compute_checksum
{
- my ($self, $plist, $base, $stash) = @_;
+ my ($self, $result, $base, $stash) = @_;
+
my $fname = $self->fullname();
if (-l "$base/$fname") {
my $value = readlink "$base/$fname";
- $self->make_symlink($value);
- return if $base eq '/' or $base eq '';
- if ($value =~ m/^\Q$base/) {
- print STDERR "Error in package: symlink $base/$fname refers to $value\n";
- $main::errors++;
- }
+ $result->make_symlink($value);
} elsif (-f _) {
my ($dev, $ino, $size) = (stat _)[0,1,7];
if (defined $stash->{"$dev/$ino"}) {
- $self->make_hardlink($stash->{"$dev/$ino"});
+ $result->make_hardlink($stash->{"$dev/$ino"});
} else {
$stash->{"$dev/$ino"} = $fname;
- $self->add_md5(OpenBSD::md5::fromfile("$base/$fname"));
- $self->add_size($size);
+ $result->add_md5(OpenBSD::md5::fromfile("$base/$fname"));
+ $result->add_size($size);
}
} else {
- print STDERR "Error in package: \"$base/$fname\" does not exist\n";
+ print STDERR "Error in package: $base/$fname does not exist\n";
$main::errors++;
}
}
+sub create_checksum
+{
+ my ($self, $plist, $base, $stash) = @_;
+ $self->compute_checksum($self, $base, $stash);
+}
+
sub verify_checksum
{
my ($self, $base, $stash) = @_;
my $fname = $self->fullname();
my $check = ref($self)->new($self->{name});
- if (-l "$base/$fname") {
- my $value = readlink "$base/$fname";
- $check->make_symlink($value);
- } elsif (-f _) {
- my ($dev, $ino, $size) = (stat _)[0,1,7];
- if (defined $stash->{"$dev/$ino"}) {
- $check->make_hardlink($stash->{"$dev/$ino"});
- } else {
- $stash->{"$dev/$ino"} = $fname;
- $check->add_md5(OpenBSD::md5::fromfile("$base/$fname"));
- $check->add_size($size);
- }
- } else {
- print STDERR "Error in package: $base/$fname does not exist\n";
- $main::errors++;
- }
+ $self->compute_checksum($check, $base, $stash);
+
for my $field (qw(symlink link md5 size)) {
if ((defined $check->{$field} && defined $self->{$field} &&
$check->{$field} ne $self->{$field}) ||