diff options
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/ArcCheck.pm | 29 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackageLocation.pm | 6 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PkgCreate.pm | 14 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Ustar.pm | 108 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_merge | 4 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_mklocatedb | 220 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pod/OpenBSD::Ustar.pod | 13 |
7 files changed, 239 insertions, 155 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/ArcCheck.pm b/usr.sbin/pkg_add/OpenBSD/ArcCheck.pm index cc73a646264..d2efe04500e 100644 --- a/usr.sbin/pkg_add/OpenBSD/ArcCheck.pm +++ b/usr.sbin/pkg_add/OpenBSD/ArcCheck.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: ArcCheck.pm,v 1.17 2010/06/30 10:51:04 espie Exp $ +# $OpenBSD: ArcCheck.pm,v 1.18 2010/07/28 12:19:54 espie Exp $ # # Copyright (c) 2005-2006 Marc Espie <espie@openbsd.org> # @@ -68,30 +68,29 @@ sub verify_modes if (!defined $item->{owner} && !$o->isSymLink) { if ($o->{uname} ne 'root' && $o->{uname} ne 'bin') { - print STDERR "Error: no \@owner for ", - $item->fullname, " (", $o->{uname}, ")\n"; + $o->errsay("Error: no \@owner for #1 (#2)", + $item->fullname, $o->{uname}); $result = 0; } } if (!defined $item->{group} && !$o->isSymLink) { if ($o->{gname} ne 'bin' && $o->{gname} ne 'wheel') { if (($o->{mode} & (S_ISUID | S_ISGID | S_IWGRP)) != 0) { - print STDERR "Error: no \@group for ", - $item->fullname, " (", $o->{uname}, - "), which has mode ", - sprintf("%4o", $o->{mode} & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID)), "\n"; + $o->errsay("Error: no \@group for #1 (#2), which has mode #3", + $item->fullname, $o->{uname}, + sprintf("%4o", $o->{mode} & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID))); $result = 0; } else { - print STDERR "Warning: no \@group for ", - $item->fullname, " (", $o->{gname}, ")\n"; + $o->errsay("Warning: no \@group for #1 (#2)", + $item->fullname, $o->{gname}); } } } if (!defined $item->{mode} && $o->isFile) { if (($o->{mode} & (S_ISUID | S_ISGID | S_IWOTH)) != 0) { - print STDERR "Error: weird mode for ", - $item->fullname, ": ", - sprintf("%4o", $o->{mode} & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID)), "\n"; + $o->errsay("Error: weird mode for #1: #2", + $item->fullname, + sprintf("%4o", $o->{mode} & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID))); $result = 0; } } @@ -122,10 +121,12 @@ sub prepare_long my $filename = $item->name; my $entry = $self->prepare($filename); if (!defined $entry->{uname}) { - die "No user name for ", $entry->name, " (uid ", $entry->{uid}, ")"; + $self->fatal("No user name for #1 (uid #2)", + $entry->name, $entry->{uid}); } if (!defined $entry->{gname}) { - die "No group name for ", $entry->name, " (gid ", $entry->{gid}. ")"; + $self->fatal("No group name for #1 (uid #2)", + $entry->name, $entry->{gid}); } my ($prefix, $name) = split_name($entry->name); if (length($name) > MAXFILENAME || length($prefix) > MAXPREFIX) { diff --git a/usr.sbin/pkg_add/OpenBSD/PackageLocation.pm b/usr.sbin/pkg_add/OpenBSD/PackageLocation.pm index 65241924b83..d6cb3cd9500 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackageLocation.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackageLocation.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackageLocation.pm,v 1.22 2010/06/30 10:51:04 espie Exp $ +# $OpenBSD: PackageLocation.pm,v 1.23 2010/07/28 12:19:54 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -28,7 +28,7 @@ sub new { my ($class, $repository, $name, $arch) = @_; - my $self = { repository => $repository, name => $repository->canonicalize($name)}; + my $self = { repository => $repository, name => $repository->canonicalize($name), state => $repository->{state} }; if (defined $arch) { $self->{arch} = $arch; } @@ -86,7 +86,7 @@ sub _opened return; } require OpenBSD::Ustar; - my $archive = new OpenBSD::Ustar $fh; + my $archive = OpenBSD::Ustar->new($fh, $self->{state}); $self->{_archive} = $archive; if (defined $self->{_current}) { diff --git a/usr.sbin/pkg_add/OpenBSD/PkgCreate.pm b/usr.sbin/pkg_add/OpenBSD/PkgCreate.pm index beac7f1e047..e75eccf9b4d 100644 --- a/usr.sbin/pkg_add/OpenBSD/PkgCreate.pm +++ b/usr.sbin/pkg_add/OpenBSD/PkgCreate.pm @@ -1,6 +1,6 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: PkgCreate.pm,v 1.21 2010/07/09 12:42:43 espie Exp $ +# $OpenBSD: PkgCreate.pm,v 1.22 2010/07/28 12:19:54 espie Exp $ # # Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org> # @@ -621,9 +621,9 @@ sub add_signature sub create_archive { - my ($self, $filename, $dir) = @_; + my ($self, $state, $filename, $dir) = @_; open(my $fh, "|-", OpenBSD::Paths->gzip, "-f", "-o", $filename); - return OpenBSD::Ustar->new($fh, $dir); + return OpenBSD::Ustar->new($fh, $state, $dir); } sub sign_existing_package @@ -639,7 +639,7 @@ sub sign_existing_package $self->add_signature($plist, $cert, $privkey); $plist->save; my $tmp = OpenBSD::Temp::permanent_file(".", "pkg"); - my $wrarc = $self->create_archive($tmp, "."); + my $wrarc = $self->create_archive($state, $tmp, "."); $plist->copy_over($wrarc, $true_package); $wrarc->close; $true_package->wipe_info; @@ -774,7 +774,8 @@ sub create_package local $SIG{'HUP'} = $h; local $SIG{'KILL'} = $h; local $SIG{'TERM'} = $h; - $state->{archive} = $self->create_archive($wname, $plist->infodir); + $state->{archive} = $self->create_archive($state, $wname, + $plist->infodir); $state->set_status("archiving"); $state->progress->visit_with_size($plist, 'create_package', $state); $state->end_status; @@ -944,7 +945,8 @@ sub parse_and_run } if ($state->opt('n')) { - $state->{archive} = OpenBSD::Ustar->new(undef, $plist->infodir); + $state->{archive} = OpenBSD::Ustar->new(undef, $state, + $plist->infodir); $plist->pretend_to_archive($state); } else { $self->create_package($state, $plist, $wname); diff --git a/usr.sbin/pkg_add/OpenBSD/Ustar.pm b/usr.sbin/pkg_add/OpenBSD/Ustar.pm index fc4aafc494b..6abf41bb0e6 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.60 2010/07/04 19:34:47 espie Exp $ +# $OpenBSD: Ustar.pm,v 1.61 2010/07/28 12:19:54 espie Exp $ # # Copyright (c) 2002-2007 Marc Espie <espie@openbsd.org> # @@ -55,17 +55,23 @@ my $buffsize = 2 * 1024 * 1024; sub new { - my ($class, $fh, $destdir) = @_; + my ($class, $fh, $state, $destdir) = @_; $destdir = '' unless defined $destdir; return bless { fh => $fh, swallow => 0, + state => $state, key => {}, destdir => $destdir} , $class; } +sub fatal +{ + my ($self, $msg, @args) = $_; + $self->{state}->fatal("Ustar: $msg", @args); +} sub new_object { @@ -87,10 +93,10 @@ sub skip } my $actual = read($self->{fh}, $temp, $toread); if (!defined $actual) { - die "Error while skipping archive: $!"; + $self->fatal("Error while skipping archive: #1", $!); } if ($actual == 0) { - die "Premature end of archive in header: $!"; + $self->fatal("Premature end of archive in header: #1", $!); } $self->{swallow} -= $actual; } @@ -115,7 +121,7 @@ sub next my $header; my $n = read $self->{fh}, $header, 512; return if (defined $n) and $n == 0; - die "Error while reading header" + $self->fatal("Error while reading header") unless defined $n and $n == 512; if ($header eq "\0"x512) { return $self->next; @@ -125,14 +131,14 @@ sub next $linkname, $magic, $version, $uname, $gname, $major, $minor, $prefix, $pad) = unpack(USTAR_HEADER, $header); if ($magic ne "ustar\0" || $version ne '00') { - die "Not an ustar archive header"; + $self->fatal("Not an ustar archive header"); } # verify checksum my $value = $header; substr($value, 148, 8) = " "x8; my $ck2 = unpack("%C*", $value); if ($ck2 != oct($chksum)) { - die "Bad archive checksum"; + $self->fatal("Bad archive checksum"); } $name =~ s/\0*$//o; $mode = oct($mode) & 0xfff; @@ -168,7 +174,7 @@ sub next if (defined $types->{$type}) { $types->{$type}->new($result); } else { - die "Unsupported type $type"; + $self->fatal("Unsupported type #1", $type); } # adjust swallow $self->{swallow} = $size; @@ -234,19 +240,19 @@ sub mkheader $linkname = ''; } if (length $prefix > MAXPREFIX) { - die "Prefix too long $prefix"; + $archive->fatal("Prefix too long #1", $prefix); } if (length $name > MAXFILENAME) { - die "Name too long $name"; + $archive->fatal("Name too long #1", $name); } if (length $linkname > MAXLINKNAME) { - die "Linkname too long $linkname"; + $archive->fatal("Linkname too long #1", $linkname); } if (length $uname > MAXUSERNAME) { - die "Username too long $uname"; + $archive->fatal("Username too long #1", $uname); } if (length $gname > MAXGROUPNAME) { - die "Groupname too long $gname"; + $archive->fatal("Groupname too long #1", $gname); } my $header; my $cksum = ' 'x8; @@ -318,8 +324,9 @@ sub prepare sub pad { - my $fh = $_[0]->{fh}; - print $fh "\0"x1024 or die "Error writing to archive: $!"; + my $self = shift; + my $fh = $self->{fh}; + print $fh "\0"x1024 or $self->fatal("Error writing to archive: #1", $!); } sub close @@ -351,12 +358,25 @@ sub new { my ($class, $object) = @_; + bless $object, $class; if ($object->{size} != 0) { - die "Bad archive: non null size for arbitrary entry"; + $object->fatal("Bad archive: non null size for #1", + $class ); } - bless $object, $class; + return $object; } +sub fatal +{ + my ($self, @args) = @_; + $self->{archive}->fatal(@args); +} + +sub errsay +{ + my ($self, @args) = @_; + $self->{archive}->{state}->errsay(@args); +} sub todo { my ($self, $toread) = @_; @@ -400,7 +420,7 @@ sub write $arc->{padout} = 1; my $header = $arc->mkheader($self, $self->type); - print $out $header or die "Error writing to archive: $!"; + print $out $header or $self->fatal("Error writing to archive: #1", $!); $self->write_contents($arc); my $k = $self->{key}; if (!defined $arc->{key}->{$k}) { @@ -440,7 +460,7 @@ sub copy $self->resolve_links($wrarc); $wrarc->{padout} = 1; my $header = $wrarc->mkheader($self, $self->type); - print $out $header or die "Error writing to archive: $!"; + print $out $header or $self->fatal("Error writing to archive: #1", $!); $self->copy_contents($wrarc); } @@ -479,8 +499,8 @@ sub create $linkname=$self->{cwd}.'/'.$linkname; } link $self->{destdir}.$linkname, $self->{destdir}.$self->name or - die "Can't link $self->{destdir}$linkname to $self->{destdir}", - $self->name, ": $!"; + $self->fatal("Can't link #1#2 to #1#3: #4", + $self->{destdir}, $linkname, $self->name, $!); } sub resolve_links @@ -492,7 +512,7 @@ sub resolve_links $self->{linkname} = $arc->{key}->{$k}; } else { print join("\n", keys(%{$arc->{key}})), "\n"; - die "Can't copy link over: original for $k NOT available"; + $self->fatal("Can't copy link over: original for #1 NOT available", $k); } } @@ -509,8 +529,8 @@ sub create my $self = shift; $self->make_basedir($self->name); symlink $self->{linkname}, $self->{destdir}.$self->name or - die "Can't symlink $self->{linkname} to $self->{destdir}", - $self->name, ": $!"; + $self->fatal("Can't symlink #1 to #2#3: #4", + $self->{linkname}, $self->{destdir}, $self->name, $!); } sub isLink() { 1 } @@ -527,7 +547,7 @@ sub create $self->make_basedir($self->name); require POSIX; POSIX::mkfifo($self->{destdir}.$self->name, $self->{mode}) or - die "Can't create fifo ", $self->name,": $!"; + $self->fatal("Can't create fifo #1: #2", $self->name, $!); $self->set_modes; } @@ -646,7 +666,8 @@ sub create my $buffer; my $out = OpenBSD::CompactWriter->new($self->{destdir}.$self->name); if (!defined $out) { - die "Can't write to $self->{destdir}", $self->name, ": $!"; + $self->fatal("Can't write to #1#2: #3", $self->{destdir}, + $self->name, $!); } my $toread = $self->{size}; while ($toread > 0) { @@ -654,22 +675,22 @@ sub create $maxread = $toread if $maxread > $toread; my $actual = read($self->{archive}->{fh}, $buffer, $maxread); if (!defined $actual) { - die "Error reading from archive: $!"; + $self->fatal("Error reading from archive: #1", $!); } if ($actual == 0) { - die "Premature end of archive"; + $self->fatal("Premature end of archive"); } $self->{archive}->{swallow} -= $actual; unless ($out->write($buffer)) { - die "Error writing to $self->{destdir}", $self->name, - ": $!"; + $self->fatal("Error writing to #1#2: #3", + $self->{destdir}, $self->name, $!); } $toread -= $actual; $self->todo($toread); } - $out->close or die "Error closing $self->{destdir}", $self->name, - ": $!"; + $out->close or $self->fatal("Error closing #1#2: #3", + $self->{destdir}, $self->name, $!); $self->set_modes; } @@ -681,10 +702,10 @@ sub contents my $actual = read($self->{archive}->{fh}, $buffer, $toread); if (!defined $actual) { - die "Error reading from archive: $!"; + $self->fatal("Error reading from archive: #1", $!); } if ($actual != $toread) { - die "Error: short read from archive"; + $self->fatal("Error: short read from archive"); } $self->{archive}->{swallow} -= $actual; return $buffer; @@ -696,7 +717,8 @@ sub write_contents my $filename = $self->{realname}; my $size = $self->{size}; my $out = $arc->{fh}; - open my $fh, "<", $filename or die "Can't read file $filename: $!"; + open my $fh, "<", $filename or $self->fatal("Can't read file #1: #2", + $filename, $!); my $buffer; my $toread = $size; @@ -705,13 +727,13 @@ sub write_contents $maxread = $toread if $maxread > $toread; my $actual = read($fh, $buffer, $maxread); if (!defined $actual) { - die "Error reading from file: $!"; + $self->fatal("Error reading from file: #1", $!); } if ($actual == 0) { - die "Premature end of file"; + $self->fatal("Premature end of file"); } unless (print $out $buffer) { - die "Error writing to archive: $!"; + $self->fatal("Error writing to archive: #1", $!); } $toread -= $actual; @@ -719,7 +741,7 @@ sub write_contents } if ($size % 512) { print $out "\0" x (512 - $size % 512) or - die "Error writing to archive: $!"; + $self->fatal("Error writing to archive: #1", $!); } } @@ -735,21 +757,21 @@ sub copy_contents $maxread = $toread if $maxread > $toread; my $actual = read($self->{archive}->{fh}, $buffer, $maxread); if (!defined $actual) { - die "Error reading from archive: $!"; + $self->fatal("Error reading from archive: #1", $!); } if ($actual == 0) { - die "Premature end of archive"; + $self->fatal("Premature end of archive"); } $self->{archive}->{swallow} -= $actual; unless (print $out $buffer) { - die "Error writing to archive $!"; + $self->fatal("Error writing to archive #1", $!); } $toread -= $actual; } if ($size % 512) { print $out "\0" x (512 - $size % 512) or - die "Error writing to archive: $!"; + $self->fatal("Error writing to archive: #1", $!); } $self->alias($arc, $self->name); } diff --git a/usr.sbin/pkg_add/pkg_merge b/usr.sbin/pkg_add/pkg_merge index 14ff559a1fe..790d5814e87 100644 --- a/usr.sbin/pkg_add/pkg_merge +++ b/usr.sbin/pkg_add/pkg_merge @@ -1,6 +1,6 @@ #! /usr/bin/perl # Copyright (c) 2005-2007 Marc Espie <espie@openbsd.org> -# $OpenBSD: pkg_merge,v 1.20 2010/07/04 19:34:06 espie Exp $ +# $OpenBSD: pkg_merge,v 1.21 2010/07/28 12:19:54 espie Exp $ # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -152,7 +152,7 @@ my $prefix = 'a'; my $allprefix = ''; open(my $outfh, "|-", OpenBSD::Paths->gzip, "-o", $out); -my $wrarc = OpenBSD::Ustar->new($outfh, "."); +my $wrarc = OpenBSD::Ustar->new($outfh, $ui, "."); for my $pkgname (@ARGV) { my $true_package = $ui->repo->find($pkgname); $ui->fatal("No such package #1", $pkgname) unless $true_package; diff --git a/usr.sbin/pkg_add/pkg_mklocatedb b/usr.sbin/pkg_add/pkg_mklocatedb index 499e7285792..0bfbc9d2165 100644 --- a/usr.sbin/pkg_add/pkg_mklocatedb +++ b/usr.sbin/pkg_add/pkg_mklocatedb @@ -1,6 +1,6 @@ #! /usr/bin/perl # Copyright (c) 2005-2010 Marc Espie <espie@openbsd.org> -# $OpenBSD: pkg_mklocatedb,v 1.28 2010/06/30 11:33:57 espie Exp $ +# $OpenBSD: pkg_mklocatedb,v 1.29 2010/07/28 12:19:54 espie Exp $ # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -25,112 +25,140 @@ use OpenBSD::Paths; use OpenBSD::AddCreateDelete; use File::Path; +package OpenBSD::Pkgmklocatedb::State; +our @ISA = qw(OpenBSD::AddCreateDelete::State); + +sub handle_options +{ + my $state = shift; + $state->{no_exports} = 1; + $state->SUPER::handle_options('ad:nqs:x:r:p:P', + '[-anPq] [-d repository] [-p portsdir] [-r release] [-s src] ', + '[-x X11src] [pkg-name [...]]'); + $state->{srcdir} = $state->opt('s'); + $state->{xdir} = $state->opt('x'); + $state->{releasedir} = $state->opt('r'); + $state->{portsdir} = $state->opt('p'); + $state->{pkgdir} = $state->opt('d'); + $state->{quiet} = $state->opt('q'); + $state->{pkgpath} = $state->opt('P'); + $state->{allinfo} = $state->opt('a'); + $state->{nopipe} = $state->opt('n'); +} + + package OpenBSD::PackingElement; sub print_name {} -package OpenBSD::PackingElement::FileObject; +package OpenBSD::PackingElement::Name; sub print_name { - my ($self, $fh, $pkgname) = @_; - print $fh $pkgname, ":", $self->fullname, "\n"; + my ($self, $state) = @_; + $state->{currentheader} = $self->{name}.':'; } -package main; - -our ($opt_a, $opt_n, $opt_q, $opt_s, $opt_x, $opt_r, $opt_p, $opt_P, $opt_d); - -sub info +package OpenBSD::PackingElement::ExtraInfo; +sub print_name { - my $plist = shift; - my $r; - if ($opt_a) { - $r = $plist->fullpkgpath.":".$plist->pkgname; - } elsif ($opt_P) { - $r = $plist->fullpkgpath; - } else { - $r = $plist->pkgname; + my ($self, $state) = @_; + if ($state->{allinfo}) { + $state->{currentheader} .= $self->{subdir}.':'; + } elsif ($state->{pkgpath}) { + $state->{currentheader} = $self->{subdir}.':'; } - print STDERR "$r\n" unless $opt_q; - return $r; + $state->errsay($state->{currentheader}) unless $state->{quiet}; } +package OpenBSD::PackingElement::FileObject; +sub print_name +{ + my ($self, $state) = @_; + print {$state->{out}} $state->{currentheader}, $self->fullname, "\n"; +} + +package main; + sub tag { - my ($dir, $set, $rev) = @_; + my ($state, $dir, $set, $rev) = @_; my $r; - if ($opt_a) { + if ($state->{allinfo}) { $r = "$dir/$set:$set$rev"; - } elsif ($opt_P) { + } elsif ($state->{pkgpath}) { $r = "$dir/$set"; } else { $r = "$set$rev"; } - print STDERR "$r\n" unless $opt_q; + $state->errsay($r) unless $state->{quiet}; return $r; } -my $state = OpenBSD::AddCreateDelete::State->new("pkg_mklocatedb"); -$state->handle_options('ad:nqs:x:r:p:P', - '[-anPq] [-d repository] [-p portsdir] [-r release] [-s src] ', - '[-x X11src] [pkg-name [...]]'); - -my $fh; -my $MKLOCATEDB = OpenBSD::Paths->mklocatedb; - -if ($opt_n or -t STDOUT) { - $fh = \*STDOUT; -} else { - open $fh, "|-", $MKLOCATEDB, $MKLOCATEDB or - $state->fatal("couldn't open pipe: #1", $!); -} -if ($opt_s || $opt_x) { +my ($rev, $arch); +sub findos +{ my $cmd = OpenBSD::Paths->uname." -mr"; - my ($rev, $arch) = split(/\s+/o, `$cmd`); + ($rev, $arch) = split(/\s+/o, `$cmd`); chomp $arch; $rev =~ s/\.//; - if ($opt_s) { - my $dir = "$opt_s/distrib/sets/lists"; - for my $set (qw(base comp etc game man misc)) { - my $tag = tag('src', $set, $rev); - for my $f ("$dir/$set/mi", "$dir/$set/md.$arch") { - open my $l, '<', $f or next; - while (my $e = <$l>) { - chomp $e; - $e =~ s/^\.//; - print $fh "$tag:$e\n"; - } - } - } +} + +sub open_output +{ + my $state = shift; + + + if ($state->{nopipe} or -t STDOUT) { + $state->{out} = \*STDOUT; + } else { + my $MKLOCATEDB = OpenBSD::Paths->mklocatedb; + + open $state->{out}, "|-", $MKLOCATEDB, $MKLOCATEDB or + $state->fatal("couldn't open pipe to mklocatedb: #1", $!); } - if ($opt_x) { - my $dir = "$opt_x/distrib/sets/lists"; - for my $set (qw(xbase xetc xfont xserv xshare)) { - my $tag = tag('XF4', $set, $rev); - for my $f ("$dir/$set/mi", "$dir/$set/md.$arch") { - open my $l, '<', $f or next; - while (my $e = <$l>) { - chomp $e; - $e =~ s/^\.//; - print $fh "$tag:$e\n"; - } +} + +sub do_src +{ + my ($state, $src, $tag, @sets) = @_; + findos() if !defined $arch; + my $dir = "$src/distrib/sets/lists"; + for my $set (@sets) { + my $tag = tag($state, $tag, $set, $rev); + my $output = 0; + for my $f ("$dir/$set/mi", "$dir/$set/md.$arch") { + open my $l, '<', $f or next; + while (my $e = <$l>) { + chomp $e; + $e =~ s/^\.//; + print {$state->{out}} "$tag:$e\n"; + $output = 1; } } + if (!$output) { + $state->fatal("Couldn't find set #1", $set); + } } } -if ($opt_r) { +sub do_release +{ + my $state = shift; + require OpenBSD::Ustar; - opendir(my $dir, $opt_r) or next; + opendir(my $dir, $state->{releasedir}) or return; while (my $e = readdir $dir) { if ($e =~ m/^(\w+\d\d)\.tgz$/o) { my $set = $1; - open my $arc, '-|', OpenBSD::Paths->gzip, '-c', '-d', "--", "$opt_r/$e"; - my $u = OpenBSD::Ustar->new($arc, '/'); + open my $arc, '-|', OpenBSD::Paths->gzip, '-c', '-d', + "--", $state->{releasedir}."/".$e or + $state->fatal("couldn't open pipe from gzip: #1", $!); + + my $u = OpenBSD::Ustar->new($arc, $state, '/'); while (my $f = $u->next) { my $name = $f->{name}; $name =~ s/^\.//o; - print $fh "$set:$name\n"; + print {$state->{out}} "$set:$name\n"; } close $arc; } @@ -138,9 +166,11 @@ if ($opt_r) { closedir($dir); } -if ($opt_p) { +sub do_portsdir +{ + my $state = shift; my $make = $ENV{MAKE} || 'make'; - open my $in, "cd $opt_p && $make print-plist-all |"; + open my $in, "cd $state->{portsdir} && $make print-plist-all |"; my $done = 0; while (!$done) { my $plist = OpenBSD::PackingList->read($in, @@ -155,31 +185,57 @@ if ($opt_p) { $done = 1; }); if (defined $plist && defined $plist->pkgname) { - $plist->print_name($fh, info($plist)); + $plist->print_name($state); } } close($in); } -elsif ($opt_d) { +sub do_pkgdir +{ + my $state = shift; + require File::Find; no warnings qw(once); - $state->fatal("Bad argument: #1 is not a directory", $opt_d) - unless -d $opt_d; + $state->fatal("Bad argument: #1 is not a directory", $state->{pkgdir}) + unless -d $state->{pkgdir}; File::Find::find( - sub { - return unless -f $_; - my $plist = $state->repo->grabPlist($File::Find::name); - return unless defined $plist; - $plist->print_name($fh, info($plist)); - }, $opt_d); + sub { + return unless -f $_; + my $plist = $state->repo->grabPlist($File::Find::name); + return unless defined $plist; + $plist->print_name($state); + }, $state->{pkgdir}); +} + +my $state = OpenBSD::Pkgmklocatedb::State->new("pkg_mklocatedb"); +$state->handle_options; + +open_output($state); + +if ($state->{srcdir}) { + do_source($state, $state->{srcdir}, 'src', + qw(base comp etc game misc)); +} +if ($state->{xdir}) { + do_source($state, $state->{xdir}, 'xenocara', + qw(xbase xetc xfont xserv xshare)); +} +if ($state->{releasedir}) { + do_release($state); +} + +if ($state->{portsdir}) { + do_portsdir($state); +} elsif ($state->{pkgdir}) { + do_pkgdir($state); } elsif (@ARGV == 0) { $state->progress->for_list("Scanning installation", [installed_packages()], sub { my $pkgname = shift; my $plist = OpenBSD::PackingList->from_installation($pkgname); return unless defined $plist; - $plist->print_name($fh, info($plist)); + $plist->print_name($state); }); } else { $state->progress->for_list("Scanning packages", \@ARGV, @@ -187,6 +243,6 @@ elsif ($opt_d) { my $pkgname = shift; my $plist = $state->repo->grabPlist($pkgname); next unless $plist; - $plist->print_name($fh, info($plist)); + $plist->print_name($state); }); } diff --git a/usr.sbin/pkg_add/pod/OpenBSD::Ustar.pod b/usr.sbin/pkg_add/pod/OpenBSD::Ustar.pod index 08df5e3d5db..a17f603472d 100644 --- a/usr.sbin/pkg_add/pod/OpenBSD::Ustar.pod +++ b/usr.sbin/pkg_add/pod/OpenBSD::Ustar.pod @@ -1,4 +1,4 @@ -$OpenBSD: OpenBSD::Ustar.pod,v 1.14 2010/06/30 10:51:04 espie Exp $ +$OpenBSD: OpenBSD::Ustar.pod,v 1.15 2010/07/28 12:19:54 espie Exp $ =head1 NAME @@ -10,7 +10,7 @@ OpenBSD::Ustar - simple access to Ustar C<tar(1)> archives # for reading open(my $in, "<", $arcnameforreading) or die; - $rdarc = OpenBSD::Ustar->new($in, $destdir); + $rdarc = OpenBSD::Ustar->new($in, $state, $destdir); while (my $o = $rdarc->next) { # decide whether we want to extract it, change object attributes $o->create; @@ -19,7 +19,7 @@ OpenBSD::Ustar - simple access to Ustar C<tar(1)> archives # for writing open(my $out, ">", $arcnameforwriting) or die; - $wrarc = OpenBSD::Ustar->new($fh, $destdir); + $wrarc = OpenBSD::Ustar->new($fh, $state, $destdir); # loop my $o = $wrarc->prepare($filename); # tweak some entry parameters @@ -29,9 +29,9 @@ OpenBSD::Ustar - simple access to Ustar C<tar(1)> archives # for copying open(my $in, "<", $arcnameforreading) or die; - $rdarc = OpenBSD::Ustar->new($in, $destdir); + $rdarc = OpenBSD::Ustar->new($in, $state, $destdir); open(my $out, ">", $arcnameforwriting) or die; - $wrarc = OpenBSD::Ustar->new($fh, $destdir); + $wrarc = OpenBSD::Ustar->new($fh, $state, $destdir); while (my $o = $rdarc->next) { $o->copy($wrarc); } @@ -50,6 +50,9 @@ C<read>. C<OpenBSD::Ustar> does not rely on C<seek> or C<rewind> in order to be usable on pipe outputs. For archive writing, the filehandle should support C<print>. +Error messages and fatal errors will be handled through the C<$state> object, +which should conform to C<OpenBSD::State(3p)> (uses C<errsay> and C<fatal>). + Note that read and write support are mutually exclusive, though there is no need to specify the mode used at creation time; it is implicitly provided by the underlying filehandle. |