| Filename | /usr/libdata/perl5/OpenBSD/Ustar.pm |
| Statements | Executed 8890 statements in 46.8ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 122 | 2 | 2 | 14.4ms | 79.4ms | OpenBSD::Ustar::next (recurses: max depth 2, inclusive time 123µs) |
| 476 | 4 | 1 | 4.09ms | 4.09ms | OpenBSD::Ustar::CORE:subst (opcode) |
| 40 | 1 | 1 | 3.43ms | 21.4ms | OpenBSD::Ustar::File::create |
| 40 | 1 | 1 | 1.75ms | 78.6ms | OpenBSD::Ustar::File::contents |
| 119 | 1 | 1 | 1.60ms | 1.60ms | OpenBSD::Ustar::new_object |
| 1 | 1 | 1 | 1.58ms | 1.76ms | OpenBSD::Ustar::BEGIN@48 |
| 40 | 1 | 1 | 1.54ms | 2.80ms | OpenBSD::CompactWriter::new |
| 238 | 2 | 1 | 1.53ms | 1.53ms | OpenBSD::Ustar::CORE:unpack (opcode) |
| 40 | 1 | 1 | 1.51ms | 1.51ms | OpenBSD::Ustar::new |
| 40 | 1 | 1 | 1.48ms | 7.57ms | OpenBSD::Ustar::Object::make_basedir |
| 122 | 1 | 1 | 1.39ms | 5.03ms | OpenBSD::Ustar::skip |
| 40 | 1 | 1 | 1.30ms | 1.30ms | OpenBSD::Ustar::set_description |
| 40 | 1 | 1 | 1.27ms | 1.27ms | OpenBSD::CompactWriter::CORE:syswrite (opcode) |
| 201 | 2 | 1 | 1.18ms | 45.8ms | OpenBSD::Ustar::CORE:read (opcode) |
| 40 | 1 | 1 | 1.16ms | 1.16ms | OpenBSD::CompactWriter::CORE:open (opcode) |
| 40 | 1 | 1 | 925µs | 2.30ms | OpenBSD::Ustar::Object::set_modes |
| 40 | 1 | 1 | 830µs | 2.10ms | OpenBSD::CompactWriter::write |
| 40 | 1 | 1 | 819µs | 819µs | OpenBSD::Ustar::Object::CORE:chown (opcode) |
| 160 | 4 | 1 | 546µs | 546µs | OpenBSD::Ustar::Object::name |
| 80 | 2 | 1 | 495µs | 79.5ms | OpenBSD::Ustar::File::CORE:read (opcode) |
| 1 | 1 | 1 | 473µs | 511µs | OpenBSD::Ustar::BEGIN@49 |
| 238 | 3 | 2 | 466µs | 466µs | OpenBSD::Ustar::File::isFile (xsub) |
| 119 | 1 | 1 | 463µs | 463µs | OpenBSD::Ustar::CORE:match (opcode) |
| 40 | 1 | 1 | 462µs | 462µs | OpenBSD::Ustar::Object::CORE:ftdir (opcode) |
| 40 | 1 | 1 | 314µs | 776µs | OpenBSD::Ustar::Object::ensure_dir |
| 40 | 1 | 1 | 309µs | 309µs | OpenBSD::Ustar::Object::CORE:chmod (opcode) |
| 40 | 1 | 1 | 213µs | 213µs | OpenBSD::Ustar::Object::left_todo |
| 40 | 1 | 1 | 200µs | 200µs | OpenBSD::CompactWriter::close |
| 40 | 1 | 1 | 100µs | 100µs | OpenBSD::CompactWriter::CORE:stat (opcode) |
| 1 | 1 | 1 | 30µs | 36µs | OpenBSD::PackageLocation::BEGIN@20 |
| 1 | 1 | 1 | 22µs | 565µs | OpenBSD::Ustar::BEGIN@25 |
| 1 | 1 | 1 | 13µs | 162µs | OpenBSD::CompactWriter::BEGIN@738 |
| 1 | 1 | 1 | 13µs | 27µs | OpenBSD::PackageLocation::BEGIN@21 |
| 1 | 1 | 1 | 12µs | 33µs | OpenBSD::Ustar::BEGIN@221 |
| 1 | 1 | 1 | 10µs | 10µs | OpenBSD::Ustar::BEGIN@50 |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::UStar::Device::create |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::Dir::create |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::Fifo::create |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::File::copy_contents |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::File::write_contents |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::HardLink::create |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::HardLink::resolve_links |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::Object::alias |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::Object::copy |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::Object::copy_contents |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::Object::errsay |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::Object::fatal |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::Object::recheck_owner |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::Object::resolve_links |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::Object::set_name |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::Object::system |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::Object::write |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::Object::write_contents |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::SoftLink::create |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::close |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::destdir |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::extended_record |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::fatal |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::fh |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::mkheader |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::pack_header |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::pad |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::parse_records |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::prepare |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::read_records |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::set_callback |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Ustar::split_name |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | # ex:ts=8 sw=4: | ||||
| 2 | # $OpenBSD: Ustar.pm,v 1.88 2017/07/23 10:34:44 espie Exp $ | ||||
| 3 | # | ||||
| 4 | # Copyright (c) 2002-2014 Marc Espie <espie@openbsd.org> | ||||
| 5 | # | ||||
| 6 | # Permission to use, copy, modify, and distribute this software for any | ||||
| 7 | # purpose with or without fee is hereby granted, provided that the above | ||||
| 8 | # copyright notice and this permission notice appear in all copies. | ||||
| 9 | # | ||||
| 10 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||||
| 11 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||||
| 12 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||||
| 13 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||||
| 14 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||||
| 15 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||||
| 16 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||||
| 17 | |||||
| 18 | # Handle utar archives | ||||
| 19 | |||||
| 20 | 2 | 54µs | 2 | 42µs | # spent 36µs (30+6) within OpenBSD::PackageLocation::BEGIN@20 which was called:
# once (30µs+6µs) by OpenBSD::PackageLocation::_opened at line 20 # spent 36µs making 1 call to OpenBSD::PackageLocation::BEGIN@20
# spent 6µs making 1 call to strict::import |
| 21 | 2 | 109µs | 2 | 42µs | # spent 27µs (13+14) within OpenBSD::PackageLocation::BEGIN@21 which was called:
# once (13µs+14µs) by OpenBSD::PackageLocation::_opened at line 21 # spent 27µs making 1 call to OpenBSD::PackageLocation::BEGIN@21
# spent 14µs making 1 call to warnings::import |
| 22 | |||||
| 23 | package OpenBSD::Ustar; | ||||
| 24 | |||||
| 25 | # spent 565µs (22+543) within OpenBSD::Ustar::BEGIN@25 which was called:
# once (22µs+543µs) by OpenBSD::PackageLocation::_opened at line 46 | ||||
| 26 | 1 | 1µs | FILE => "\0", | ||
| 27 | FILE1 => '0', | ||||
| 28 | HARDLINK => '1', | ||||
| 29 | SOFTLINK => '2', | ||||
| 30 | CHARDEVICE => '3', | ||||
| 31 | BLOCKDEVICE => '4', | ||||
| 32 | DIR => '5', | ||||
| 33 | FIFO => '6', | ||||
| 34 | CONTFILE => '7', | ||||
| 35 | USTAR_HEADER => 'a100a8a8a8a12a12a8aa100a6a2a32a32a8a8a155a12', | ||||
| 36 | MAXFILENAME => 100, | ||||
| 37 | MAXLINKNAME => 100, | ||||
| 38 | MAXPREFIX => 155, | ||||
| 39 | MAXUSERNAME => 32, | ||||
| 40 | MAXGROUPNAME => 32, | ||||
| 41 | XHDR => 'x', | ||||
| 42 | # XXX those are NOT supported, just recognized | ||||
| 43 | GHDR => 'g', | ||||
| 44 | LONGLINK => 'K', | ||||
| 45 | LONGNAME => 'L', | ||||
| 46 | 1 | 58µs | 2 | 1.11ms | }; # spent 565µs making 1 call to OpenBSD::Ustar::BEGIN@25
# spent 543µs making 1 call to constant::import |
| 47 | |||||
| 48 | 2 | 221µs | 1 | 1.76ms | # spent 1.76ms (1.58+174µs) within OpenBSD::Ustar::BEGIN@48 which was called:
# once (1.58ms+174µs) by OpenBSD::PackageLocation::_opened at line 48 # spent 1.76ms making 1 call to OpenBSD::Ustar::BEGIN@48 |
| 49 | 2 | 127µs | 1 | 511µs | # spent 511µs (473+37) within OpenBSD::Ustar::BEGIN@49 which was called:
# once (473µs+37µs) by OpenBSD::PackageLocation::_opened at line 49 # spent 511µs making 1 call to OpenBSD::Ustar::BEGIN@49 |
| 50 | 2 | 826µs | 1 | 10µs | # spent 10µs within OpenBSD::Ustar::BEGIN@50 which was called:
# once (10µs+0s) by OpenBSD::PackageLocation::_opened at line 50 # spent 10µs making 1 call to OpenBSD::Ustar::BEGIN@50 |
| 51 | |||||
| 52 | 1 | 6µs | 1 | 5µs | our $uidcache = new OpenBSD::UidCache; # spent 5µs making 1 call to OpenBSD::SimpleIdCache::new |
| 53 | 1 | 3µs | 1 | 3µs | our $gidcache = new OpenBSD::GidCache; # spent 3µs making 1 call to OpenBSD::SimpleIdCache::new |
| 54 | 1 | 3µs | 1 | 2µs | our $unamecache = new OpenBSD::UnameCache; # spent 2µs making 1 call to OpenBSD::SimpleIdCache::new |
| 55 | 1 | 3µs | 1 | 2µs | our $gnamecache = new OpenBSD::GnameCache; # spent 2µs making 1 call to OpenBSD::SimpleIdCache::new |
| 56 | |||||
| 57 | # This is a multiple of st_blksize everywhere.... | ||||
| 58 | 1 | 700ns | my $buffsize = 2 * 1024 * 1024; | ||
| 59 | |||||
| 60 | sub new | ||||
| 61 | # spent 1.51ms within OpenBSD::Ustar::new which was called 40 times, avg 38µs/call:
# 40 times (1.51ms+0s) by OpenBSD::PackageLocation::_opened at line 87 of OpenBSD/PackageLocation.pm, avg 38µs/call | ||||
| 62 | 40 | 220µs | my ($class, $fh, $state, $destdir) = @_; | ||
| 63 | |||||
| 64 | 40 | 58µs | $destdir = '' unless defined $destdir; | ||
| 65 | |||||
| 66 | 40 | 913µs | return bless { | ||
| 67 | fh => $fh, | ||||
| 68 | swallow => 0, | ||||
| 69 | state => $state, | ||||
| 70 | key => {}, | ||||
| 71 | destdir => $destdir} , $class; | ||||
| 72 | } | ||||
| 73 | |||||
| 74 | sub set_description | ||||
| 75 | # spent 1.30ms within OpenBSD::Ustar::set_description which was called 40 times, avg 33µs/call:
# 40 times (1.30ms+0s) by OpenBSD::PackageLocation::_opened at line 88 of OpenBSD/PackageLocation.pm, avg 33µs/call | ||||
| 76 | 40 | 288µs | my ($self, $d) = @_; | ||
| 77 | 40 | 767µs | $self->{description} = $d; | ||
| 78 | } | ||||
| 79 | |||||
| 80 | sub set_callback | ||||
| 81 | { | ||||
| 82 | my ($self, $code) = @_; | ||||
| 83 | $self->{callback} = $code; | ||||
| 84 | } | ||||
| 85 | |||||
| 86 | sub fatal | ||||
| 87 | { | ||||
| 88 | my ($self, $msg, @args) = @_; | ||||
| 89 | $self->{state}->fatal("Ustar [#1][#2]: #3", | ||||
| 90 | $self->{description} // '?', $self->{lastname} // '?', | ||||
| 91 | $self->{state}->f($msg, @args)); | ||||
| 92 | } | ||||
| 93 | |||||
| 94 | sub new_object | ||||
| 95 | # spent 1.60ms within OpenBSD::Ustar::new_object which was called 119 times, avg 13µs/call:
# 119 times (1.60ms+0s) by OpenBSD::Ustar::next at line 256, avg 13µs/call | ||||
| 96 | 119 | 126µs | my ($self, $h, $class) = @_; | ||
| 97 | 119 | 150µs | $h->{archive} = $self; | ||
| 98 | 119 | 245µs | $h->{destdir} = $self->{destdir}; | ||
| 99 | 119 | 637µs | bless $h, $class; | ||
| 100 | 119 | 456µs | return $h; | ||
| 101 | } | ||||
| 102 | |||||
| 103 | sub skip | ||||
| 104 | # spent 5.03ms (1.39+3.64) within OpenBSD::Ustar::skip which was called 122 times, avg 41µs/call:
# 122 times (1.39ms+3.64ms) by OpenBSD::Ustar::next at line 186, avg 41µs/call | ||||
| 105 | 122 | 104µs | my $self = shift; | ||
| 106 | 122 | 106µs | my $temp; | ||
| 107 | |||||
| 108 | 122 | 1.30ms | while ($self->{swallow} > 0) { | ||
| 109 | 79 | 88µs | my $toread = $self->{swallow}; | ||
| 110 | 79 | 74µs | if ($toread >$buffsize) { | ||
| 111 | $toread = $buffsize; | ||||
| 112 | } | ||||
| 113 | 79 | 635µs | 158 | 6.85ms | my $actual = read($self->{fh}, $temp, $toread); # spent 3.64ms making 79 calls to OpenBSD::Ustar::CORE:read, avg 46µs/call
# spent 3.21ms making 79 calls to IO::Uncompress::Base::read, avg 41µs/call |
| 114 | 79 | 66µs | if (!defined $actual) { | ||
| 115 | $self->fatal("Error while skipping archive: #1", $!); | ||||
| 116 | } | ||||
| 117 | 79 | 67µs | if ($actual == 0) { | ||
| 118 | $self->fatal("Premature end of archive in header: #1", $!); | ||||
| 119 | } | ||||
| 120 | 79 | 161µs | $self->{swallow} -= $actual; | ||
| 121 | } | ||||
| 122 | } | ||||
| 123 | |||||
| 124 | 1 | 5µs | my $types = { | ||
| 125 | DIR , 'OpenBSD::Ustar::Dir', | ||||
| 126 | HARDLINK , 'OpenBSD::Ustar::HardLink', | ||||
| 127 | SOFTLINK , 'OpenBSD::Ustar::SoftLink', | ||||
| 128 | FILE , 'OpenBSD::Ustar::File', | ||||
| 129 | FILE1 , 'OpenBSD::Ustar::File', | ||||
| 130 | FIFO , 'OpenBSD::Ustar::Fifo', | ||||
| 131 | CHARDEVICE , 'OpenBSD::Ustar::CharDevice', | ||||
| 132 | BLOCKDEVICE , 'OpenBSD::Ustar::BlockDevice', | ||||
| 133 | }; | ||||
| 134 | |||||
| 135 | 1 | 2µs | my $unsupported = { | ||
| 136 | XHDR => 'Extended header', | ||||
| 137 | GHDR => 'GNU header', | ||||
| 138 | LONGLINK => 'Long symlink', | ||||
| 139 | LONGNAME => 'Long file', | ||||
| 140 | }; | ||||
| 141 | |||||
| 142 | sub read_records | ||||
| 143 | { | ||||
| 144 | my ($self, $size) = @_; | ||||
| 145 | my $toread = $self->{swallow}; | ||||
| 146 | my $result = ''; | ||||
| 147 | while ($toread > 0) { | ||||
| 148 | my $buffer; | ||||
| 149 | my $maxread = $buffsize; | ||||
| 150 | $maxread = $toread if $maxread > $toread; | ||||
| 151 | my $actual = read($self->{fh}, $buffer, $maxread); | ||||
| 152 | if (!defined $actual) { | ||||
| 153 | $self->fatal("Error reading from archive: #1", $!); | ||||
| 154 | } | ||||
| 155 | if ($actual == 0) { | ||||
| 156 | $self->fatal("Premature end of archive"); | ||||
| 157 | } | ||||
| 158 | $self->{swallow} -= $actual; | ||||
| 159 | $toread -= $actual; | ||||
| 160 | $result .= $buffer; | ||||
| 161 | } | ||||
| 162 | return substr($result, 0, $size); | ||||
| 163 | } | ||||
| 164 | |||||
| 165 | sub parse_records | ||||
| 166 | { | ||||
| 167 | my ($self, $result, $h) = @_; | ||||
| 168 | open(my $fh, '<', \$h); | ||||
| 169 | while (<$fh>) { | ||||
| 170 | chomp; | ||||
| 171 | if (m/^(\d+)\s+(\w+?)\=(.*)$/) { | ||||
| 172 | my ($k, $v) = ($2, $3); | ||||
| 173 | if ($k eq 'path') { | ||||
| 174 | $result->{name} = $v; | ||||
| 175 | } elsif ($k eq 'linkpath') { | ||||
| 176 | $result->{linkname} = $v; | ||||
| 177 | } | ||||
| 178 | } | ||||
| 179 | } | ||||
| 180 | } | ||||
| 181 | |||||
| 182 | sub next | ||||
| 183 | # spent 79.4ms (14.4+65.0) within OpenBSD::Ustar::next which was called 122 times, avg 651µs/call:
# 120 times (14.4ms+65.0ms) by OpenBSD::PackageLocation::getNext at line 319 of OpenBSD/PackageLocation.pm, avg 662µs/call
# 2 times (34µs+-34µs) by OpenBSD::Ustar::next at line 192, avg 0s/call | ||||
| 184 | 122 | 110µs | my $self = shift; | ||
| 185 | # get rid of the current object | ||||
| 186 | 122 | 424µs | 122 | 5.03ms | $self->skip; # spent 5.03ms making 122 calls to OpenBSD::Ustar::skip, avg 41µs/call |
| 187 | 122 | 97µs | my $header; | ||
| 188 | 122 | 1.14ms | 244 | 83.5ms | my $n = read($self->{fh}, $header, 512); # spent 42.1ms making 122 calls to OpenBSD::Ustar::CORE:read, avg 345µs/call
# spent 41.4ms making 122 calls to IO::Uncompress::Base::read, avg 339µs/call |
| 189 | 122 | 134µs | return if (defined $n) and $n == 0; | ||
| 190 | 121 | 108µs | $self->fatal("Error while reading header") | ||
| 191 | unless defined $n and $n == 512; | ||||
| 192 | 121 | 136µs | 2 | 0s | if ($header eq "\0"x512) { # spent 123µs making 2 calls to OpenBSD::Ustar::next, avg 61µs/call, recursion: max depth 2, sum of overlapping time 123µs |
| 193 | return $self->next; | ||||
| 194 | } | ||||
| 195 | # decode header | ||||
| 196 | 119 | 2.48ms | 119 | 1.15ms | my ($name, $mode, $uid, $gid, $size, $mtime, $chksum, $type, # spent 1.15ms making 119 calls to OpenBSD::Ustar::CORE:unpack, avg 10µs/call |
| 197 | $linkname, $magic, $version, $uname, $gname, $major, $minor, | ||||
| 198 | $prefix, $pad) = unpack(USTAR_HEADER, $header); | ||||
| 199 | 119 | 134µs | if ($magic ne "ustar\0" || $version ne '00') { | ||
| 200 | $self->fatal("Not an ustar archive header"); | ||||
| 201 | } | ||||
| 202 | # verify checksum | ||||
| 203 | 119 | 114µs | my $value = $header; | ||
| 204 | 119 | 132µs | substr($value, 148, 8) = " "x8; | ||
| 205 | 119 | 758µs | 119 | 388µs | my $ck2 = unpack("%C*", $value); # spent 388µs making 119 calls to OpenBSD::Ustar::CORE:unpack, avg 3µs/call |
| 206 | 119 | 139µs | if ($ck2 != oct($chksum)) { | ||
| 207 | $self->fatal("Bad archive checksum"); | ||||
| 208 | } | ||||
| 209 | 119 | 3.22ms | 119 | 2.66ms | $name =~ s/\0*$//o; # spent 2.66ms making 119 calls to OpenBSD::Ustar::CORE:subst, avg 22µs/call |
| 210 | 119 | 133µs | $mode = oct($mode) & 0xfff; | ||
| 211 | 119 | 1.10ms | 119 | 712µs | $uname =~ s/\0*$//o; # spent 712µs making 119 calls to OpenBSD::Ustar::CORE:subst, avg 6µs/call |
| 212 | 119 | 801µs | 119 | 460µs | $gname =~ s/\0*$//o; # spent 460µs making 119 calls to OpenBSD::Ustar::CORE:subst, avg 4µs/call |
| 213 | 119 | 582µs | 119 | 258µs | $linkname =~ s/\0*$//o; # spent 258µs making 119 calls to OpenBSD::Ustar::CORE:subst, avg 2µs/call |
| 214 | 119 | 109µs | $major = oct($major); | ||
| 215 | 119 | 93µs | $minor = oct($minor); | ||
| 216 | 119 | 87µs | $uid = oct($uid); | ||
| 217 | 119 | 90µs | $gid = oct($gid); | ||
| 218 | 119 | 869µs | 119 | 2.76ms | $uid = $uidcache->lookup($uname, $uid); # spent 2.76ms making 119 calls to OpenBSD::IdCache::lookup, avg 23µs/call |
| 219 | 119 | 371µs | 119 | 7.18ms | $gid = $gidcache->lookup($gname, $gid); # spent 7.18ms making 119 calls to OpenBSD::IdCache::lookup, avg 60µs/call |
| 220 | { | ||||
| 221 | 121 | 2.79ms | 2 | 54µs | # spent 33µs (12+21) within OpenBSD::Ustar::BEGIN@221 which was called:
# once (12µs+21µs) by OpenBSD::PackageLocation::_opened at line 221 # spent 33µs making 1 call to OpenBSD::Ustar::BEGIN@221
# spent 21µs making 1 call to warnings::unimport |
| 222 | 119 | 109µs | $mtime = oct($mtime); | ||
| 223 | } | ||||
| 224 | 119 | 834µs | 119 | 463µs | unless ($prefix =~ m/^\0/o) { # spent 463µs making 119 calls to OpenBSD::Ustar::CORE:match, avg 4µs/call |
| 225 | $prefix =~ s/\0*$//o; | ||||
| 226 | $name = "$prefix/$name"; | ||||
| 227 | } | ||||
| 228 | |||||
| 229 | 119 | 169µs | $self->{lastname} = $name; | ||
| 230 | 119 | 104µs | $size = oct($size); | ||
| 231 | 119 | 2.71ms | my $result= { | ||
| 232 | name => $name, | ||||
| 233 | mode => $mode, | ||||
| 234 | atime => $mtime, | ||||
| 235 | mtime => $mtime, | ||||
| 236 | linkname=> $linkname, | ||||
| 237 | uname => $uname, | ||||
| 238 | uid => $uid, | ||||
| 239 | gname => $gname, | ||||
| 240 | gid => $gid, | ||||
| 241 | size => $size, | ||||
| 242 | major => $major, | ||||
| 243 | minor => $minor, | ||||
| 244 | }; | ||||
| 245 | # adjust swallow | ||||
| 246 | 119 | 131µs | $self->{swallow} = $size; | ||
| 247 | 119 | 202µs | if ($size % 512) { | ||
| 248 | $self->{swallow} += 512 - $size % 512; | ||||
| 249 | } | ||||
| 250 | 119 | 125µs | if ($type eq XHDR) { | ||
| 251 | my $h = $self->read_records($size); | ||||
| 252 | $result = $self->next; | ||||
| 253 | $self->parse_records($result, $h); | ||||
| 254 | return $result; | ||||
| 255 | } | ||||
| 256 | 119 | 686µs | 119 | 1.60ms | if (defined $types->{$type}) { # spent 1.60ms making 119 calls to OpenBSD::Ustar::new_object, avg 13µs/call |
| 257 | $self->new_object($result, $types->{$type}); | ||||
| 258 | } else { | ||||
| 259 | $self->fatal("Unsupported type #1 (#2)", $type, | ||||
| 260 | $unsupported->{$type} // "unknown"); | ||||
| 261 | } | ||||
| 262 | 119 | 631µs | 119 | 190µs | if (!$result->isFile && $result->{size} != 0) { # spent 190µs making 119 calls to OpenBSD::Ustar::File::isFile, avg 2µs/call |
| 263 | $self->fatal("Bad archive: non null size for #1 (#2)", | ||||
| 264 | $types->{$type}, $result->{name}); | ||||
| 265 | } | ||||
| 266 | |||||
| 267 | 119 | 196µs | $self->{cachename} = $name; | ||
| 268 | 119 | 588µs | return $result; | ||
| 269 | } | ||||
| 270 | |||||
| 271 | sub split_name | ||||
| 272 | { | ||||
| 273 | my $name = shift; | ||||
| 274 | my $prefix = ''; | ||||
| 275 | |||||
| 276 | my $l = length $name; | ||||
| 277 | if ($l > MAXFILENAME && $l <= MAXFILENAME+MAXPREFIX+1) { | ||||
| 278 | while (length($name) > MAXFILENAME && | ||||
| 279 | $name =~ m/^(.*?\/)(.*)$/o) { | ||||
| 280 | $prefix .= $1; | ||||
| 281 | $name = $2; | ||||
| 282 | } | ||||
| 283 | $prefix =~ s|/$||; | ||||
| 284 | } | ||||
| 285 | return ($prefix, $name); | ||||
| 286 | } | ||||
| 287 | |||||
| 288 | sub extended_record | ||||
| 289 | { | ||||
| 290 | my ($k, $v) = @_; | ||||
| 291 | my $string = " $k=$v\n"; | ||||
| 292 | my $len = length($string); | ||||
| 293 | if ($len < 995) { | ||||
| 294 | return sprintf("%3d", $len+3).$string; | ||||
| 295 | } elsif ($len < 9995) { | ||||
| 296 | return sprintf("%04d", $len+4).$string; | ||||
| 297 | } else { | ||||
| 298 | return sprintf("%05d", $len+5).$string; | ||||
| 299 | } | ||||
| 300 | } | ||||
| 301 | |||||
| 302 | sub pack_header | ||||
| 303 | { | ||||
| 304 | my ($archive, $type, $size, $entry, $prefix, $name, $linkname, | ||||
| 305 | $uname, $gname, $major, $minor) = @_; | ||||
| 306 | |||||
| 307 | my $header; | ||||
| 308 | my $cksum = ' 'x8; | ||||
| 309 | for (1 .. 2) { | ||||
| 310 | $header = pack(USTAR_HEADER, | ||||
| 311 | $name, | ||||
| 312 | sprintf("%07o", $entry->{mode}), | ||||
| 313 | sprintf("%07o", $entry->{uid} // 0), | ||||
| 314 | sprintf("%07o", $entry->{gid} // 0), | ||||
| 315 | sprintf("%011o", $size), | ||||
| 316 | sprintf("%011o", $entry->{mtime} // 0), | ||||
| 317 | $cksum, | ||||
| 318 | $type, | ||||
| 319 | $linkname, | ||||
| 320 | 'ustar', '00', | ||||
| 321 | $uname, | ||||
| 322 | $gname, | ||||
| 323 | sprintf("%07o", $major), | ||||
| 324 | sprintf("%07o", $minor), | ||||
| 325 | $prefix, "\0"); | ||||
| 326 | $cksum = sprintf("%07o", unpack("%C*", $header)); | ||||
| 327 | } | ||||
| 328 | return $header; | ||||
| 329 | } | ||||
| 330 | |||||
| 331 | 1 | 700ns | my $whatever = "usualSuspect000"; | ||
| 332 | |||||
| 333 | sub mkheader | ||||
| 334 | { | ||||
| 335 | my ($archive, $entry, $type) = @_; | ||||
| 336 | my ($prefix, $name) = split_name($entry->name); | ||||
| 337 | my ($extendedname, $extendedlink); | ||||
| 338 | my $linkname = $entry->{linkname}; | ||||
| 339 | my $size = $entry->{size}; | ||||
| 340 | my ($major, $minor); | ||||
| 341 | if ($entry->isDevice) { | ||||
| 342 | $major = $entry->{major}; | ||||
| 343 | $minor = $entry->{minor}; | ||||
| 344 | } else { | ||||
| 345 | $major = 0; | ||||
| 346 | $minor = 0; | ||||
| 347 | } | ||||
| 348 | my ($uname, $gname); | ||||
| 349 | if (defined $entry->{uname}) { | ||||
| 350 | $uname = $entry->{uname}; | ||||
| 351 | } else { | ||||
| 352 | $uname = $entry->{uid}; | ||||
| 353 | } | ||||
| 354 | if (defined $entry->{gname}) { | ||||
| 355 | $gname = $entry->{gname}; | ||||
| 356 | } else { | ||||
| 357 | $gname = $entry->{gid}; | ||||
| 358 | } | ||||
| 359 | |||||
| 360 | if (defined $entry->{cwd}) { | ||||
| 361 | my $cwd = $entry->{cwd}; | ||||
| 362 | $cwd.='/' unless $cwd =~ m/\/$/o; | ||||
| 363 | $linkname =~ s/^\Q$cwd\E//; | ||||
| 364 | } | ||||
| 365 | if (!defined $linkname) { | ||||
| 366 | $linkname = ''; | ||||
| 367 | } | ||||
| 368 | if (length $prefix > MAXPREFIX) { | ||||
| 369 | $prefix = substr($prefix, 0, MAXPREFIX); | ||||
| 370 | $extendedname = 1; | ||||
| 371 | } | ||||
| 372 | if (length $name > MAXFILENAME) { | ||||
| 373 | $name = substr($name, 0, MAXPREFIX); | ||||
| 374 | $extendedname = 1; | ||||
| 375 | } | ||||
| 376 | if (length $linkname > MAXLINKNAME) { | ||||
| 377 | $linkname = substr($linkname, 0, MAXLINKNAME); | ||||
| 378 | $extendedlink = 1; | ||||
| 379 | } | ||||
| 380 | if (length $uname > MAXUSERNAME) { | ||||
| 381 | $archive->fatal("Username too long #1", $uname); | ||||
| 382 | } | ||||
| 383 | if (length $gname > MAXGROUPNAME) { | ||||
| 384 | $archive->fatal("Groupname too long #1", $gname); | ||||
| 385 | } | ||||
| 386 | my $header = $archive->pack_header($type, $size, $entry, | ||||
| 387 | $prefix, $name, $linkname, $uname, $gname, $major, $minor); | ||||
| 388 | my $x; | ||||
| 389 | if ($extendedname) { | ||||
| 390 | $x .= extended_record("path", $entry->name); | ||||
| 391 | } | ||||
| 392 | if ($extendedlink) { | ||||
| 393 | $x .= extended_record("linkpath",$entry->{linkname}); | ||||
| 394 | } | ||||
| 395 | if ($x) { | ||||
| 396 | my $extended = $archive->pack_header(XHDR, length($x), $entry, | ||||
| 397 | '', $whatever, '', $uname, $gname, $major, $minor); | ||||
| 398 | $whatever++; | ||||
| 399 | if ((length $x) % 512) { | ||||
| 400 | $x .= "\0" x (512 - ((length $x) % 512)); | ||||
| 401 | } | ||||
| 402 | return $extended.$x.$header; | ||||
| 403 | } | ||||
| 404 | return $header; | ||||
| 405 | } | ||||
| 406 | |||||
| 407 | sub prepare | ||||
| 408 | { | ||||
| 409 | my ($self, $filename, $destdir) = @_; | ||||
| 410 | |||||
| 411 | $destdir //= $self->{destdir}; | ||||
| 412 | my $realname = "$destdir/$filename"; | ||||
| 413 | |||||
| 414 | my ($dev, $ino, $mode, $uid, $gid, $rdev, $size, $mtime) = | ||||
| 415 | (lstat $realname)[0,1,2, 4,5,6,7, 9]; | ||||
| 416 | |||||
| 417 | my $entry = { | ||||
| 418 | key => "$dev/$ino", | ||||
| 419 | name => $filename, | ||||
| 420 | realname => $realname, | ||||
| 421 | mode => $mode, | ||||
| 422 | uid => $uid, | ||||
| 423 | gid => $gid, | ||||
| 424 | size => $size, | ||||
| 425 | mtime => $mtime, | ||||
| 426 | uname => $unamecache->lookup($uid), | ||||
| 427 | gname => $gnamecache->lookup($gid), | ||||
| 428 | major => $rdev/256, | ||||
| 429 | minor => $rdev%256, | ||||
| 430 | }; | ||||
| 431 | my $k = $entry->{key}; | ||||
| 432 | my $class = "OpenBSD::Ustar::File"; # default | ||||
| 433 | if (defined $self->{key}{$k}) { | ||||
| 434 | $entry->{linkname} = $self->{key}{$k}; | ||||
| 435 | $class = "OpenBSD::Ustar::HardLink"; | ||||
| 436 | } elsif (-l $realname) { | ||||
| 437 | $entry->{linkname} = readlink($realname); | ||||
| 438 | $class = "OpenBSD::Ustar::SoftLink"; | ||||
| 439 | } elsif (-p _) { | ||||
| 440 | $class = "OpenBSD::Ustar::Fifo"; | ||||
| 441 | } elsif (-c _) { | ||||
| 442 | $class = "OpenBSD::Ustar::CharDevice"; | ||||
| 443 | } elsif (-b _) { | ||||
| 444 | $class ="OpenBSD::Ustar::BlockDevice"; | ||||
| 445 | } elsif (-d _) { | ||||
| 446 | $class = "OpenBSD::Ustar::Dir"; | ||||
| 447 | } | ||||
| 448 | $self->new_object($entry, $class); | ||||
| 449 | if (!$entry->isFile) { | ||||
| 450 | $entry->{size} = 0; | ||||
| 451 | } | ||||
| 452 | return $entry; | ||||
| 453 | } | ||||
| 454 | |||||
| 455 | sub pad | ||||
| 456 | { | ||||
| 457 | my $self = shift; | ||||
| 458 | my $fh = $self->{fh}; | ||||
| 459 | print $fh "\0"x1024 or $self->fatal("Error writing to archive: #1", $!); | ||||
| 460 | } | ||||
| 461 | |||||
| 462 | sub close | ||||
| 463 | { | ||||
| 464 | my $self = shift; | ||||
| 465 | if (defined $self->{padout}) { | ||||
| 466 | $self->pad; | ||||
| 467 | } | ||||
| 468 | close($self->{fh}); | ||||
| 469 | } | ||||
| 470 | |||||
| 471 | sub destdir | ||||
| 472 | { | ||||
| 473 | my $self = shift; | ||||
| 474 | if (@_ > 0) { | ||||
| 475 | $self->{destdir} = shift; | ||||
| 476 | } else { | ||||
| 477 | return $self->{destdir}; | ||||
| 478 | } | ||||
| 479 | } | ||||
| 480 | |||||
| 481 | sub fh | ||||
| 482 | { | ||||
| 483 | return $_[0]->{fh}; | ||||
| 484 | } | ||||
| 485 | |||||
| 486 | package OpenBSD::Ustar::Object; | ||||
| 487 | |||||
| 488 | sub recheck_owner | ||||
| 489 | { | ||||
| 490 | my $entry = shift; | ||||
| 491 | # XXX weird format to prevent cvs from expanding OpenBSD id | ||||
| 492 | $entry->{uid} //= $OpenBSD::Ustar::uidcache | ||||
| 493 | ->lookup($entry->{uname}); | ||||
| 494 | $entry->{gid} //= $OpenBSD::Ustar::gidcache | ||||
| 495 | ->lookup($entry->{gname}); | ||||
| 496 | } | ||||
| 497 | |||||
| 498 | sub fatal | ||||
| 499 | { | ||||
| 500 | my ($self, @args) = @_; | ||||
| 501 | $self->{archive}->fatal(@args); | ||||
| 502 | } | ||||
| 503 | |||||
| 504 | sub system | ||||
| 505 | { | ||||
| 506 | my ($self, @args) = @_; | ||||
| 507 | $self->{archive}{state}->system(@args); | ||||
| 508 | } | ||||
| 509 | |||||
| 510 | sub errsay | ||||
| 511 | { | ||||
| 512 | my ($self, @args) = @_; | ||||
| 513 | $self->{archive}{state}->errsay(@args); | ||||
| 514 | } | ||||
| 515 | sub left_todo | ||||
| 516 | # spent 213µs within OpenBSD::Ustar::Object::left_todo which was called 40 times, avg 5µs/call:
# 40 times (213µs+0s) by OpenBSD::Ustar::File::create at line 843, avg 5µs/call | ||||
| 517 | 40 | 43µs | my ($self, $toread) = @_; | ||
| 518 | 40 | 149µs | return if $toread == 0; | ||
| 519 | return unless defined $self->{archive}{callback}; | ||||
| 520 | &{$self->{archive}{callback}}($self->{size} - $toread); | ||||
| 521 | } | ||||
| 522 | |||||
| 523 | sub name | ||||
| 524 | # spent 546µs within OpenBSD::Ustar::Object::name which was called 160 times, avg 3µs/call:
# 40 times (156µs+0s) by OpenBSD::Ustar::Object::make_basedir at line 560, avg 4µs/call
# 40 times (137µs+0s) by OpenBSD::Ustar::File::create at line 813, avg 3µs/call
# 40 times (133µs+0s) by OpenBSD::Ustar::Object::set_modes at line 539, avg 3µs/call
# 40 times (120µs+0s) by OpenBSD::Ustar::Object::set_modes at line 538, avg 3µs/call | ||||
| 525 | 160 | 137µs | my $self = shift; | ||
| 526 | 160 | 759µs | return $self->{name}; | ||
| 527 | } | ||||
| 528 | |||||
| 529 | sub set_name | ||||
| 530 | { | ||||
| 531 | my ($self, $v) = @_; | ||||
| 532 | $self->{name} = $v; | ||||
| 533 | } | ||||
| 534 | |||||
| 535 | sub set_modes | ||||
| 536 | # spent 2.30ms (925µs+1.38) within OpenBSD::Ustar::Object::set_modes which was called 40 times, avg 58µs/call:
# 40 times (925µs+1.38ms) by OpenBSD::Ustar::File::create at line 847, avg 58µs/call | ||||
| 537 | 40 | 43µs | my $self = shift; | ||
| 538 | 40 | 1.14ms | 80 | 938µs | chown $self->{uid}, $self->{gid}, $self->{destdir}.$self->name; # spent 819µs making 40 calls to OpenBSD::Ustar::Object::CORE:chown, avg 20µs/call
# spent 120µs making 40 calls to OpenBSD::Ustar::Object::name, avg 3µs/call |
| 539 | 40 | 606µs | 80 | 442µs | chmod $self->{mode}, $self->{destdir}.$self->name; # spent 309µs making 40 calls to OpenBSD::Ustar::Object::CORE:chmod, avg 8µs/call
# spent 133µs making 40 calls to OpenBSD::Ustar::Object::name, avg 3µs/call |
| 540 | 40 | 194µs | if (defined $self->{mtime} || defined $self->{atime}) { | ||
| 541 | utime $self->{atime} // time, $self->{mtime} // time, | ||||
| 542 | $self->{destdir}.$self->name; | ||||
| 543 | } | ||||
| 544 | } | ||||
| 545 | |||||
| 546 | sub ensure_dir | ||||
| 547 | # spent 776µs (314+462) within OpenBSD::Ustar::Object::ensure_dir which was called 40 times, avg 19µs/call:
# 40 times (314µs+462µs) by OpenBSD::Ustar::Object::make_basedir at line 561, avg 19µs/call | ||||
| 548 | 40 | 42µs | my ($self, $dir) = @_; | ||
| 549 | 40 | 784µs | 40 | 462µs | return if -d $dir; # spent 462µs making 40 calls to OpenBSD::Ustar::Object::CORE:ftdir, avg 12µs/call |
| 550 | $self->ensure_dir(File::Basename::dirname($dir)); | ||||
| 551 | if (mkdir($dir)) { | ||||
| 552 | return; | ||||
| 553 | } | ||||
| 554 | $self->fatal("Error making directory #1: #2", $dir, $!); | ||||
| 555 | } | ||||
| 556 | |||||
| 557 | sub make_basedir | ||||
| 558 | # spent 7.57ms (1.48+6.09) within OpenBSD::Ustar::Object::make_basedir which was called 40 times, avg 189µs/call:
# 40 times (1.48ms+6.09ms) by OpenBSD::Ustar::File::create at line 811, avg 189µs/call | ||||
| 559 | 40 | 43µs | my $self = shift; | ||
| 560 | 40 | 372µs | 80 | 5.32ms | my $dir = $self->{destdir}.File::Basename::dirname($self->name); # spent 5.16ms making 40 calls to File::Basename::dirname, avg 129µs/call
# spent 156µs making 40 calls to OpenBSD::Ustar::Object::name, avg 4µs/call |
| 561 | 40 | 300µs | 40 | 776µs | $self->ensure_dir($dir); # spent 776µs making 40 calls to OpenBSD::Ustar::Object::ensure_dir, avg 19µs/call |
| 562 | } | ||||
| 563 | |||||
| 564 | sub write | ||||
| 565 | { | ||||
| 566 | my $self = shift; | ||||
| 567 | my $arc = $self->{archive}; | ||||
| 568 | my $out = $arc->{fh}; | ||||
| 569 | |||||
| 570 | $arc->{padout} = 1; | ||||
| 571 | my $header = $arc->mkheader($self, $self->type); | ||||
| 572 | print $out $header or $self->fatal("Error writing to archive: #1", $!); | ||||
| 573 | $self->write_contents($arc); | ||||
| 574 | my $k = $self->{key}; | ||||
| 575 | if (!defined $arc->{key}{$k}) { | ||||
| 576 | $arc->{key}{$k} = $self->name; | ||||
| 577 | } | ||||
| 578 | } | ||||
| 579 | |||||
| 580 | sub alias | ||||
| 581 | { | ||||
| 582 | my ($self, $arc, $alias) = @_; | ||||
| 583 | |||||
| 584 | my $k = $self->{archive}.":".$self->{archive}{cachename}; | ||||
| 585 | if (!defined $arc->{key}{$k}) { | ||||
| 586 | $arc->{key}{$k} = $alias; | ||||
| 587 | } | ||||
| 588 | } | ||||
| 589 | |||||
| 590 | sub write_contents | ||||
| 591 | { | ||||
| 592 | # only files have anything to write | ||||
| 593 | } | ||||
| 594 | |||||
| 595 | sub resolve_links | ||||
| 596 | { | ||||
| 597 | # only hard links must cheat | ||||
| 598 | } | ||||
| 599 | |||||
| 600 | sub copy_contents | ||||
| 601 | { | ||||
| 602 | # only files need copying | ||||
| 603 | } | ||||
| 604 | |||||
| 605 | sub copy | ||||
| 606 | { | ||||
| 607 | my ($self, $wrarc) = @_; | ||||
| 608 | my $out = $wrarc->{fh}; | ||||
| 609 | $self->resolve_links($wrarc); | ||||
| 610 | $wrarc->{padout} = 1; | ||||
| 611 | my $header = $wrarc->mkheader($self, $self->type); | ||||
| 612 | print $out $header or $self->fatal("Error writing to archive: #1", $!); | ||||
| 613 | |||||
| 614 | $self->copy_contents($wrarc); | ||||
| 615 | } | ||||
| 616 | |||||
| 617 | sub isDir() { 0 } | ||||
| 618 | sub isFile() { 0 } | ||||
| 619 | sub isDevice() { 0 } | ||||
| 620 | sub isFifo() { 0 } | ||||
| 621 | sub isLink() { 0 } | ||||
| 622 | sub isSymLink() { 0 } | ||||
| 623 | sub isHardLink() { 0 } | ||||
| 624 | |||||
| 625 | package OpenBSD::Ustar::Dir; | ||||
| 626 | 1 | 6µs | our @ISA=qw(OpenBSD::Ustar::Object); | ||
| 627 | |||||
| 628 | sub create | ||||
| 629 | { | ||||
| 630 | my $self = shift; | ||||
| 631 | $self->ensure_dir($self->{destdir}.$self->name); | ||||
| 632 | $self->set_modes; | ||||
| 633 | } | ||||
| 634 | |||||
| 635 | sub isDir() { 1 } | ||||
| 636 | |||||
| 637 | sub type() { OpenBSD::Ustar::DIR } | ||||
| 638 | |||||
| 639 | package OpenBSD::Ustar::HardLink; | ||||
| 640 | 1 | 3µs | our @ISA=qw(OpenBSD::Ustar::Object); | ||
| 641 | |||||
| 642 | sub create | ||||
| 643 | { | ||||
| 644 | my $self = shift; | ||||
| 645 | $self->make_basedir; | ||||
| 646 | my $linkname = $self->{linkname}; | ||||
| 647 | if (defined $self->{cwd}) { | ||||
| 648 | $linkname=$self->{cwd}.'/'.$linkname; | ||||
| 649 | } | ||||
| 650 | link $self->{destdir}.$linkname, $self->{destdir}.$self->name or | ||||
| 651 | $self->fatal("Can't link #1#2 to #1#3: #4", | ||||
| 652 | $self->{destdir}, $linkname, $self->name, $!); | ||||
| 653 | } | ||||
| 654 | |||||
| 655 | sub resolve_links | ||||
| 656 | { | ||||
| 657 | my ($self, $arc) = @_; | ||||
| 658 | |||||
| 659 | my $k = $self->{archive}.":".$self->{linkname}; | ||||
| 660 | if (defined $arc->{key}{$k}) { | ||||
| 661 | $self->{linkname} = $arc->{key}{$k}; | ||||
| 662 | } else { | ||||
| 663 | print join("\n", keys(%{$arc->{key}})), "\n"; | ||||
| 664 | $self->fatal("Can't copy link over: original for #1 NOT available", $k); | ||||
| 665 | } | ||||
| 666 | } | ||||
| 667 | |||||
| 668 | sub isLink() { 1 } | ||||
| 669 | sub isHardLink() { 1 } | ||||
| 670 | |||||
| 671 | sub type() { OpenBSD::Ustar::HARDLINK } | ||||
| 672 | |||||
| 673 | package OpenBSD::Ustar::SoftLink; | ||||
| 674 | 1 | 2µs | our @ISA=qw(OpenBSD::Ustar::Object); | ||
| 675 | |||||
| 676 | sub create | ||||
| 677 | { | ||||
| 678 | my $self = shift; | ||||
| 679 | $self->make_basedir; | ||||
| 680 | symlink $self->{linkname}, $self->{destdir}.$self->name or | ||||
| 681 | $self->fatal("Can't symlink #1 to #2#3: #4", | ||||
| 682 | $self->{linkname}, $self->{destdir}, $self->name, $!); | ||||
| 683 | require POSIX; | ||||
| 684 | POSIX::lchown($self->{uid}, $self->{gid}, $self->{destdir}.$self->name); | ||||
| 685 | } | ||||
| 686 | |||||
| 687 | sub isLink() { 1 } | ||||
| 688 | sub isSymLink() { 1 } | ||||
| 689 | |||||
| 690 | sub type() { OpenBSD::Ustar::SOFTLINK } | ||||
| 691 | |||||
| 692 | package OpenBSD::Ustar::Fifo; | ||||
| 693 | 1 | 2µs | our @ISA=qw(OpenBSD::Ustar::Object); | ||
| 694 | |||||
| 695 | sub create | ||||
| 696 | { | ||||
| 697 | my $self = shift; | ||||
| 698 | $self->make_basedir; | ||||
| 699 | require POSIX; | ||||
| 700 | POSIX::mkfifo($self->{destdir}.$self->name, $self->{mode}) or | ||||
| 701 | $self->fatal("Can't create fifo #1#2: #3", $self->{destdir}, | ||||
| 702 | $self->name, $!); | ||||
| 703 | $self->set_modes; | ||||
| 704 | } | ||||
| 705 | |||||
| 706 | sub isFifo() { 1 } | ||||
| 707 | sub type() { OpenBSD::Ustar::FIFO } | ||||
| 708 | |||||
| 709 | package OpenBSD::UStar::Device; | ||||
| 710 | 1 | 3µs | our @ISA=qw(OpenBSD::Ustar::Object); | ||
| 711 | |||||
| 712 | sub create | ||||
| 713 | { | ||||
| 714 | my $self = shift; | ||||
| 715 | $self->make_basedir; | ||||
| 716 | $self->system(OpenBSD::Paths->mknod, | ||||
| 717 | '-m', $self->{mode}, '--', $self->{destdir}.$self->name, | ||||
| 718 | $self->devicetype, $self->{major}, $self->{minor}); | ||||
| 719 | $self->set_modes; | ||||
| 720 | } | ||||
| 721 | |||||
| 722 | sub isDevice() { 1 } | ||||
| 723 | |||||
| 724 | package OpenBSD::Ustar::BlockDevice; | ||||
| 725 | 1 | 4µs | our @ISA=qw(OpenBSD::Ustar::Device); | ||
| 726 | |||||
| 727 | sub type() { OpenBSD::Ustar::BLOCKDEVICE } | ||||
| 728 | sub devicetype() { 'b' } | ||||
| 729 | |||||
| 730 | package OpenBSD::Ustar::CharDevice; | ||||
| 731 | 1 | 3µs | our @ISA=qw(OpenBSD::Ustar::Device); | ||
| 732 | |||||
| 733 | sub type() { OpenBSD::Ustar::BLOCKDEVICE } | ||||
| 734 | sub devicetype() { 'c' } | ||||
| 735 | |||||
| 736 | package OpenBSD::CompactWriter; | ||||
| 737 | |||||
| 738 | # spent 162µs (13+149) within OpenBSD::CompactWriter::BEGIN@738 which was called:
# once (13µs+149µs) by OpenBSD::PackageLocation::_opened at line 743 | ||||
| 739 | 1 | 1µs | FH => 0, | ||
| 740 | BS => 1, | ||||
| 741 | ZEROES => 2, | ||||
| 742 | UNFINISHED => 3, | ||||
| 743 | 1 | 1.06ms | 2 | 311µs | }; # spent 162µs making 1 call to OpenBSD::CompactWriter::BEGIN@738
# spent 149µs making 1 call to constant::import |
| 744 | |||||
| 745 | sub new | ||||
| 746 | # spent 2.80ms (1.54+1.26) within OpenBSD::CompactWriter::new which was called 40 times, avg 70µs/call:
# 40 times (1.54ms+1.26ms) by OpenBSD::Ustar::File::create at line 813, avg 70µs/call | ||||
| 747 | 40 | 48µs | my ($class, $fname) = @_; | ||
| 748 | 40 | 1.65ms | 40 | 1.16ms | open (my $out, '>', $fname) or return; # spent 1.16ms making 40 calls to OpenBSD::CompactWriter::CORE:open, avg 29µs/call |
| 749 | 40 | 436µs | 40 | 100µs | my $bs = (stat $out)[11]; # spent 100µs making 40 calls to OpenBSD::CompactWriter::CORE:stat, avg 3µs/call |
| 750 | 40 | 31µs | my $zeroes; | ||
| 751 | 40 | 349µs | if (defined $bs) { | ||
| 752 | $zeroes = "\x00"x$bs; | ||||
| 753 | } | ||||
| 754 | 40 | 320µs | bless [ $out, $bs, $zeroes, 0 ], $class; | ||
| 755 | } | ||||
| 756 | |||||
| 757 | sub write | ||||
| 758 | # spent 2.10ms (830µs+1.27) within OpenBSD::CompactWriter::write which was called 40 times, avg 53µs/call:
# 40 times (830µs+1.27ms) by OpenBSD::Ustar::File::create at line 837, avg 53µs/call | ||||
| 759 | 40 | 146µs | my ($self, $buffer) = @_; | ||
| 760 | 40 | 76µs | my ($fh, $bs, $zeroes, $e) = @$self; | ||
| 761 | START: | ||||
| 762 | 40 | 70µs | if (defined $bs) { | ||
| 763 | 40 | 135µs | for (my $i = 0; $i + $bs <= length($buffer); $i+= $bs) { | ||
| 764 | if (substr($buffer, $i, $bs) eq $zeroes) { | ||||
| 765 | my $r = syswrite($fh, $buffer, $i); | ||||
| 766 | unless (defined $r && $r == $i) { | ||||
| 767 | return 0; | ||||
| 768 | } | ||||
| 769 | $i+=$bs; | ||||
| 770 | my $seek_forward = $bs; | ||||
| 771 | while (substr($buffer, $i, $bs) eq $zeroes) { | ||||
| 772 | $i += $bs; | ||||
| 773 | $seek_forward += $bs; | ||||
| 774 | } | ||||
| 775 | defined(sysseek($fh, $seek_forward, 1)) | ||||
| 776 | or return 0; | ||||
| 777 | $buffer = substr($buffer, $i); | ||||
| 778 | if (length $buffer == 0) { | ||||
| 779 | $self->[UNFINISHED] = 1; | ||||
| 780 | return 1; | ||||
| 781 | } | ||||
| 782 | goto START; | ||||
| 783 | } | ||||
| 784 | } | ||||
| 785 | } | ||||
| 786 | 40 | 45µs | $self->[UNFINISHED] = 0; | ||
| 787 | 40 | 1.48ms | 40 | 1.27ms | my $r = syswrite($fh, $buffer); # spent 1.27ms making 40 calls to OpenBSD::CompactWriter::CORE:syswrite, avg 32µs/call |
| 788 | 40 | 191µs | if (defined $r && $r == length $buffer) { | ||
| 789 | return 1; | ||||
| 790 | } else { | ||||
| 791 | return 0; | ||||
| 792 | } | ||||
| 793 | } | ||||
| 794 | |||||
| 795 | sub close | ||||
| 796 | # spent 200µs within OpenBSD::CompactWriter::close which was called 40 times, avg 5µs/call:
# 40 times (200µs+0s) by OpenBSD::Ustar::File::create at line 846, avg 5µs/call | ||||
| 797 | 40 | 48µs | my ($self) = @_; | ||
| 798 | 40 | 52µs | if ($self->[UNFINISHED]) { | ||
| 799 | defined(sysseek($self->[FH], -1, 1)) or return 0; | ||||
| 800 | defined(syswrite($self->[FH], "\0")) or return 0; | ||||
| 801 | } | ||||
| 802 | 40 | 157µs | return 1; | ||
| 803 | } | ||||
| 804 | |||||
| 805 | package OpenBSD::Ustar::File; | ||||
| 806 | 1 | 2µs | our @ISA=qw(OpenBSD::Ustar::Object); | ||
| 807 | |||||
| 808 | sub create | ||||
| 809 | # spent 21.4ms (3.43+17.9) within OpenBSD::Ustar::File::create which was called 40 times, avg 534µs/call:
# 40 times (3.43ms+17.9ms) by OpenBSD::PackageLocation::grab_info at line 170 of OpenBSD/PackageLocation.pm, avg 534µs/call | ||||
| 810 | 40 | 43µs | my $self = shift; | ||
| 811 | 40 | 698µs | 40 | 7.57ms | $self->make_basedir; # spent 7.57ms making 40 calls to OpenBSD::Ustar::Object::make_basedir, avg 189µs/call |
| 812 | 40 | 36µs | my $buffer; | ||
| 813 | 40 | 797µs | 80 | 2.94ms | my $out = OpenBSD::CompactWriter->new($self->{destdir}.$self->name); # spent 2.80ms making 40 calls to OpenBSD::CompactWriter::new, avg 70µs/call
# spent 137µs making 40 calls to OpenBSD::Ustar::Object::name, avg 3µs/call |
| 814 | 40 | 40µs | if (!defined $out) { | ||
| 815 | $self->fatal("Can't write to #1#2: #3", $self->{destdir}, | ||||
| 816 | $self->name, $!); | ||||
| 817 | } | ||||
| 818 | 40 | 55µs | my $toread = $self->{size}; | ||
| 819 | 40 | 48µs | if ($self->{partial}) { | ||
| 820 | $toread -= length($self->{partial}); | ||||
| 821 | unless ($out->write($self->{partial})) { | ||||
| 822 | $self->fatal("Error writing to #1#2: #3", | ||||
| 823 | $self->{destdir}, $self->name, $!); | ||||
| 824 | } | ||||
| 825 | } | ||||
| 826 | 40 | 84µs | while ($toread > 0) { | ||
| 827 | 40 | 39µs | my $maxread = $buffsize; | ||
| 828 | 40 | 47µs | $maxread = $toread if $maxread > $toread; | ||
| 829 | 40 | 357µs | 80 | 4.95ms | my $actual = read($self->{archive}{fh}, $buffer, $maxread); # spent 2.60ms making 40 calls to OpenBSD::Ustar::File::CORE:read, avg 65µs/call
# spent 2.36ms making 40 calls to IO::Uncompress::Base::read, avg 59µs/call |
| 830 | 40 | 35µs | if (!defined $actual) { | ||
| 831 | $self->fatal("Error reading from archive: #1", $!); | ||||
| 832 | } | ||||
| 833 | 40 | 62µs | if ($actual == 0) { | ||
| 834 | $self->fatal("Premature end of archive"); | ||||
| 835 | } | ||||
| 836 | 40 | 58µs | $self->{archive}{swallow} -= $actual; | ||
| 837 | 40 | 174µs | 40 | 2.10ms | unless ($out->write($buffer)) { # spent 2.10ms making 40 calls to OpenBSD::CompactWriter::write, avg 53µs/call |
| 838 | $self->fatal("Error writing to #1#2: #3", | ||||
| 839 | $self->{destdir}, $self->name, $!); | ||||
| 840 | } | ||||
| 841 | |||||
| 842 | 40 | 66µs | $toread -= $actual; | ||
| 843 | 40 | 350µs | 40 | 213µs | $self->left_todo($toread); # spent 213µs making 40 calls to OpenBSD::Ustar::Object::left_todo, avg 5µs/call |
| 844 | } | ||||
| 845 | $out->close or $self->fatal("Error closing #1#2: #3", | ||||
| 846 | 40 | 144µs | 40 | 200µs | $self->{destdir}, $self->name, $!); # spent 200µs making 40 calls to OpenBSD::CompactWriter::close, avg 5µs/call |
| 847 | 40 | 821µs | 40 | 2.30ms | $self->set_modes; # spent 2.30ms making 40 calls to OpenBSD::Ustar::Object::set_modes, avg 58µs/call |
| 848 | } | ||||
| 849 | |||||
| 850 | sub contents | ||||
| 851 | # spent 78.6ms (1.75+76.9) within OpenBSD::Ustar::File::contents which was called 40 times, avg 1.97ms/call:
# 40 times (1.75ms+76.9ms) by OpenBSD::PackageLocation::find_contents at line 119 of OpenBSD/PackageLocation.pm, avg 1.97ms/call | ||||
| 852 | 40 | 60µs | my ($self, $lookfor) = @_; | ||
| 853 | 40 | 58µs | my $toread = $self->{size}; | ||
| 854 | 40 | 38µs | my $buffer; | ||
| 855 | 40 | 44µs | my $offset = 0; | ||
| 856 | 40 | 51µs | if ($self->{partial}) { | ||
| 857 | $buffer = $self->{partial}; | ||||
| 858 | $offset = length($self->{partial}); | ||||
| 859 | $toread -= $offset; | ||||
| 860 | } | ||||
| 861 | |||||
| 862 | 40 | 82µs | while ($toread != 0) { | ||
| 863 | 40 | 37µs | my $sz = $toread; | ||
| 864 | 40 | 38µs | if (defined $lookfor) { | ||
| 865 | last if (defined $buffer) and &$lookfor($buffer); | ||||
| 866 | $sz = 1024 if $sz > 1024; | ||||
| 867 | } | ||||
| 868 | 40 | 387µs | 80 | 153ms | my $actual = read($self->{archive}{fh}, $buffer, $sz, $offset); # spent 76.9ms making 40 calls to OpenBSD::Ustar::File::CORE:read, avg 1.92ms/call
# spent 76.6ms making 40 calls to IO::Uncompress::Base::read, avg 1.92ms/call |
| 869 | 40 | 35µs | if (!defined $actual) { | ||
| 870 | $self->fatal("Error reading from archive: #1", $!); | ||||
| 871 | } | ||||
| 872 | 40 | 44µs | if ($actual != $sz) { | ||
| 873 | $self->fatal("Error: short read from archive"); | ||||
| 874 | } | ||||
| 875 | 40 | 66µs | $self->{archive}{swallow} -= $actual; | ||
| 876 | 40 | 35µs | $toread -= $actual; | ||
| 877 | 40 | 86µs | $offset += $actual; | ||
| 878 | } | ||||
| 879 | |||||
| 880 | 40 | 215µs | $self->{partial} = $buffer; | ||
| 881 | 40 | 162µs | return $buffer; | ||
| 882 | } | ||||
| 883 | |||||
| 884 | sub write_contents | ||||
| 885 | { | ||||
| 886 | my ($self, $arc) = @_; | ||||
| 887 | my $filename = $self->{realname}; | ||||
| 888 | my $size = $self->{size}; | ||||
| 889 | my $out = $arc->{fh}; | ||||
| 890 | open my $fh, "<", $filename or $self->fatal("Can't read file #1: #2", | ||||
| 891 | $filename, $!); | ||||
| 892 | |||||
| 893 | my $buffer; | ||||
| 894 | my $toread = $size; | ||||
| 895 | while ($toread > 0) { | ||||
| 896 | my $maxread = $buffsize; | ||||
| 897 | $maxread = $toread if $maxread > $toread; | ||||
| 898 | my $actual = read($fh, $buffer, $maxread); | ||||
| 899 | if (!defined $actual) { | ||||
| 900 | $self->fatal("Error reading from file: #1", $!); | ||||
| 901 | } | ||||
| 902 | if ($actual == 0) { | ||||
| 903 | $self->fatal("Premature end of file"); | ||||
| 904 | } | ||||
| 905 | unless (print $out $buffer) { | ||||
| 906 | $self->fatal("Error writing to archive: #1", $!); | ||||
| 907 | } | ||||
| 908 | |||||
| 909 | $toread -= $actual; | ||||
| 910 | $self->left_todo($toread); | ||||
| 911 | } | ||||
| 912 | if ($size % 512) { | ||||
| 913 | print $out "\0" x (512 - $size % 512) or | ||||
| 914 | $self->fatal("Error writing to archive: #1", $!); | ||||
| 915 | } | ||||
| 916 | } | ||||
| 917 | |||||
| 918 | sub copy_contents | ||||
| 919 | { | ||||
| 920 | my ($self, $arc) = @_; | ||||
| 921 | my $out = $arc->{fh}; | ||||
| 922 | my $buffer; | ||||
| 923 | my $size = $self->{size}; | ||||
| 924 | my $toread = $size; | ||||
| 925 | while ($toread > 0) { | ||||
| 926 | my $maxread = $buffsize; | ||||
| 927 | $maxread = $toread if $maxread > $toread; | ||||
| 928 | my $actual = read($self->{archive}{fh}, $buffer, $maxread); | ||||
| 929 | if (!defined $actual) { | ||||
| 930 | $self->fatal("Error reading from archive: #1", $!); | ||||
| 931 | } | ||||
| 932 | if ($actual == 0) { | ||||
| 933 | $self->fatal("Premature end of archive"); | ||||
| 934 | } | ||||
| 935 | $self->{archive}{swallow} -= $actual; | ||||
| 936 | unless (print $out $buffer) { | ||||
| 937 | $self->fatal("Error writing to archive #1", $!); | ||||
| 938 | } | ||||
| 939 | |||||
| 940 | $toread -= $actual; | ||||
| 941 | } | ||||
| 942 | if ($size % 512) { | ||||
| 943 | print $out "\0" x (512 - $size % 512) or | ||||
| 944 | $self->fatal("Error writing to archive: #1", $!); | ||||
| 945 | } | ||||
| 946 | $self->alias($arc, $self->name); | ||||
| 947 | } | ||||
| 948 | |||||
| 949 | sub isFile() { 1 } | ||||
| 950 | |||||
| 951 | sub type() { OpenBSD::Ustar::FILE1 } | ||||
| 952 | |||||
| 953 | 1 | 11µs | 1; | ||
# spent 1.16ms within OpenBSD::CompactWriter::CORE:open which was called 40 times, avg 29µs/call:
# 40 times (1.16ms+0s) by OpenBSD::CompactWriter::new at line 748, avg 29µs/call | |||||
# spent 100µs within OpenBSD::CompactWriter::CORE:stat which was called 40 times, avg 3µs/call:
# 40 times (100µs+0s) by OpenBSD::CompactWriter::new at line 749, avg 3µs/call | |||||
# spent 1.27ms within OpenBSD::CompactWriter::CORE:syswrite which was called 40 times, avg 32µs/call:
# 40 times (1.27ms+0s) by OpenBSD::CompactWriter::write at line 787, avg 32µs/call | |||||
# spent 463µs within OpenBSD::Ustar::CORE:match which was called 119 times, avg 4µs/call:
# 119 times (463µs+0s) by OpenBSD::Ustar::next at line 224, avg 4µs/call | |||||
sub OpenBSD::Ustar::CORE:read; # opcode | |||||
# spent 4.09ms within OpenBSD::Ustar::CORE:subst which was called 476 times, avg 9µs/call:
# 119 times (2.66ms+0s) by OpenBSD::Ustar::next at line 209, avg 22µs/call
# 119 times (712µs+0s) by OpenBSD::Ustar::next at line 211, avg 6µs/call
# 119 times (460µs+0s) by OpenBSD::Ustar::next at line 212, avg 4µs/call
# 119 times (258µs+0s) by OpenBSD::Ustar::next at line 213, avg 2µs/call | |||||
sub OpenBSD::Ustar::CORE:unpack; # opcode | |||||
sub OpenBSD::Ustar::File::CORE:read; # opcode | |||||
# spent 466µs within OpenBSD::Ustar::File::isFile which was called 238 times, avg 2µs/call:
# 119 times (190µs+0s) by OpenBSD::Ustar::next at line 262, avg 2µs/call
# 79 times (228µs+0s) by OpenBSD::PackageLocation::grab_info at line 166 of OpenBSD/PackageLocation.pm, avg 3µs/call
# 40 times (48µs+0s) by OpenBSD::PackageLocation::find_contents at line 116 of OpenBSD/PackageLocation.pm, avg 1µs/call | |||||
# spent 309µs within OpenBSD::Ustar::Object::CORE:chmod which was called 40 times, avg 8µs/call:
# 40 times (309µs+0s) by OpenBSD::Ustar::Object::set_modes at line 539, avg 8µs/call | |||||
# spent 819µs within OpenBSD::Ustar::Object::CORE:chown which was called 40 times, avg 20µs/call:
# 40 times (819µs+0s) by OpenBSD::Ustar::Object::set_modes at line 538, avg 20µs/call | |||||
# spent 462µs within OpenBSD::Ustar::Object::CORE:ftdir which was called 40 times, avg 12µs/call:
# 40 times (462µs+0s) by OpenBSD::Ustar::Object::ensure_dir at line 549, avg 12µs/call |