summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add/OpenBSD
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2004-01-27 23:25:32 +0000
committerMarc Espie <espie@cvs.openbsd.org>2004-01-27 23:25:32 +0000
commit14e46dc65bfb2b0776e81e7abcd339f507b7321b (patch)
treef01ac7bb937967e109ecc662e36b10e277ae40f6 /usr.sbin/pkg_add/OpenBSD
parent1def84bbe3db7c06fd2769159bf2f8212b1a4912 (diff)
avoid File::IO, one less module to load.
catch more error conditions and die in a systematic way. okay sturm@
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Ustar.pm30
-rw-r--r--usr.sbin/pkg_add/OpenBSD/md5.pm7
2 files changed, 20 insertions, 17 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Ustar.pm b/usr.sbin/pkg_add/OpenBSD/Ustar.pm
index 78ea34dccd7..6c4810c2d6b 100644
--- a/usr.sbin/pkg_add/OpenBSD/Ustar.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Ustar.pm
@@ -1,4 +1,4 @@
-# $OpenBSD: Ustar.pm,v 1.4 2003/12/19 00:29:20 espie Exp $
+# $OpenBSD: Ustar.pm,v 1.5 2004/01/27 23:25:31 espie Exp $
#
# Copyright (c) 2002 Marc Espie.
#
@@ -212,11 +212,12 @@ sub create
{
my $self = shift;
$self->make_basedir($self->{name});
+ my $linkname = $self->{linkname};
if (defined $self->{cwd}) {
- link $self->{cwd}."/".$self->{linkname}, $self->{name};
- } else {
- link $self->{linkname}, $self->{name};
+ $linkname=$self->{cwd}.'/'.$linkname;
}
+ link $linkname, $self->{name} or
+ die "Can't link $linkname to $self->{name}: $!";
}
sub isLink() { 1 }
@@ -229,7 +230,8 @@ sub create
{
my $self = shift;
$self->make_basedir($self->{name});
- symlink $self->{linkname}, $self->{name};
+ symlink $self->{linkname}, $self->{name} or
+ die "Can't symlink $self->{linkname} to $self->{name}: $!";
}
sub isLink() { 1 }
@@ -238,28 +240,30 @@ sub isHardLink() { 1 }
package OpenBSD::Ustar::File;
our @ISA=qw(OpenBSD::Ustar::Object);
-use IO::File;
-
sub create
{
my $self = shift;
$self->make_basedir($self->{name});
- my $out = new IO::File $self->{name}, "w";
+ open (my $out, '>', $self->{name});
if (!defined $out) {
- print "Can't write to ", $self->{name}, "\n";
- return;
+ die "Can't write to $self->{name}: $!";
}
my $buffer;
my $toread = $self->{size};
while ($toread > 0) {
my $maxread = $buffsize;
$maxread = $toread if $maxread > $toread;
- read($self->{archive}->{fh}, $buffer, $maxread);
+ if (!defined read($self->{archive}->{fh}, $buffer, $maxread)) {
+ die "Error reading from archive: $!";
+ }
$self->{archive}->{swallow} -= $maxread;
- print $out $buffer;
+ unless (print $out $buffer) {
+ die "Error writing to $self->{name}: $!";
+ }
+
$toread -= $maxread;
}
- $out->close();
+ $out->close() or die "Error closing $self->{name}: $!";
$self->SUPER::set_modes();
}
diff --git a/usr.sbin/pkg_add/OpenBSD/md5.pm b/usr.sbin/pkg_add/OpenBSD/md5.pm
index 478d735e5b1..f6f3f7b98b4 100644
--- a/usr.sbin/pkg_add/OpenBSD/md5.pm
+++ b/usr.sbin/pkg_add/OpenBSD/md5.pm
@@ -1,4 +1,4 @@
-# $OpenBSD: md5.pm,v 1.1 2003/10/16 17:43:34 espie Exp $
+# $OpenBSD: md5.pm,v 1.2 2004/01/27 23:25:31 espie Exp $
#
# Copyright (c) 2003 Marc Espie.
#
@@ -32,12 +32,11 @@ use Digest::MD5;
sub fromfile
{
my $fname = shift;
- die "No such file: \"$fname\"\n" unless -f $fname;
- open(my $file, '<', $fname) or return;
+ open(my $file, '<', $fname) or die "can't open $fname: $!";
my $md5 = new Digest::MD5;
$md5->addfile($file);
- close($file);
+ close($file) or die "problem closing $fname: $!";
return $md5->hexdigest();
}
1;