From c4a523cac7688706a96e7bd394b7871aeb101166 Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Tue, 14 Sep 2004 22:40:02 +0000 Subject: use IdCache. --- usr.sbin/pkg_add/OpenBSD/Ustar.pm | 44 +++++++++++---------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/pkg_add/OpenBSD/Ustar.pm b/usr.sbin/pkg_add/OpenBSD/Ustar.pm index dd0eb8bfc49..1e8fda782a6 100644 --- a/usr.sbin/pkg_add/OpenBSD/Ustar.pm +++ b/usr.sbin/pkg_add/OpenBSD/Ustar.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Ustar.pm,v 1.9 2004/08/06 08:06:01 espie Exp $ +# $OpenBSD: Ustar.pm,v 1.10 2004/09/14 22:40:01 espie Exp $ # # Copyright (c) 2002-2004 Marc Espie # @@ -30,44 +30,24 @@ use constant BLOCKDEVICE => '4'; use constant DIR => '5'; use constant FIFO => '6'; use constant CONTFILE => '7'; +use constant USTAR_HEADER => 'a100a8a8a8a12a12a8aa100a6a2a32a32a8a8a155'; use File::Path (); use File::Basename (); +use OpenBSD::IdCache; -my $uidcache = {}; -my $gidcache = {}; +my $uidcache = new OpenBSD::UidCache; +my $gidcache = new OpenBSD::GidCache; my $buffsize = 2 * 1024 * 1024; sub new { - my ($class, $fh) = @_; - - return bless { fh => $fh, swallow => 0} , $class; -} + my ($class, $fh, $destdir) = @_; + $destdir = '' unless defined $destdir; -sub name2uid -{ - my $name = shift; - return $uidcache->{$name} if defined $uidcache->{$name}; - my @entry = getpwnam($name); - if (@entry == 0) { - return $uidcache->{$name} = shift; - } else { - return $uidcache->{$name} = $entry[2]; - } + return bless { fh => $fh, swallow => 0, destdir => $destdir} , $class; } -sub name2gid -{ - my $name = shift; - return $gidcache->{$name} if defined $gidcache->{$name}; - my @entry = getgrnam($name); - if (@entry == 0) { - return $gidcache->{$name} = shift; - } else { - return $gidcache->{$name} = $entry[2]; - } -} sub skip { @@ -99,7 +79,7 @@ sub next # decode header my ($name, $mode, $uid, $gid, $size, $mtime, $chksum, $type, $linkname, $magic, $version, $uname, $gname, $major, $minor, - $prefix) = unpack('a100a8a8a8a12a12a8aa100a6a2a32a32a8a8a155', $header); + $prefix) = unpack(USTAR_HEADER, $header); if ($magic ne "ustar\0" || $version ne '00') { die "Not an ustar archive header"; } @@ -116,8 +96,8 @@ sub next $gname =~ s/\0*$//; $uid = oct($uid); $gid = oct($gid); - $uid = name2uid($uname, $uid); - $gid = name2gid($gname, $gid); + $uid = $uidcache->lookup($uname, $uid); + $gid = $gidcache->lookup($gname, $gid); $mtime = oct($mtime); unless ($prefix =~ m/^\0/) { $prefix =~ s/\0*$//; @@ -136,7 +116,7 @@ sub next gid => $gid, size => $size, archive => $self, - destdir => '' + destdir => $self->{destdir} }; # adjust swallow $self->{swallow} = $size; -- cgit v1.2.3