From 06c80259664033fa613b1ed7a6cbee347edfd69f Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Sun, 27 Jan 2013 11:39:23 +0000 Subject: add a -u option to make it possible to build on an existing database --- usr.sbin/pkg_add/pkg_mklocatedb | 59 ++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 12 deletions(-) (limited to 'usr.sbin/pkg_add/pkg_mklocatedb') diff --git a/usr.sbin/pkg_add/pkg_mklocatedb b/usr.sbin/pkg_add/pkg_mklocatedb index b7c295fdeb0..e6d72fe86cf 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 -# $OpenBSD: pkg_mklocatedb,v 1.38 2012/05/28 10:14:33 espie Exp $ +# $OpenBSD: pkg_mklocatedb,v 1.39 2013/01/27 11:39:22 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 @@ -31,8 +31,8 @@ sub handle_options { my $state = shift; $state->{no_exports} = 1; - $state->SUPER::handle_options('aCd:nqs:x:r:p:P', - '[-aCnPq] [-d repository] [-p portsdir] [-r release] [-s src] ', + $state->SUPER::handle_options('aCd:Knqs:x:r:p:Pu', + '[-aCKnPqu] [-d repository] [-p portsdir] [-r release] [-s src] ', '[-x X11src] [pkg-name [...]]'); $state->{srcdir} = $state->opt('s'); $state->{xdir} = $state->opt('x'); @@ -44,6 +44,8 @@ sub handle_options $state->{allinfo} = $state->opt('a'); $state->{nopipe} = $state->opt('n'); $state->{check} = $state->opt('C'); + $state->{full} = $state->opt('K'); + $state->{update} = $state->opt('u'); if ($state->{check}) { unless ($state->{srcdir} or $state->{portsdir}) { $state->usage("-C without -s dir or -x dir"); @@ -72,14 +74,27 @@ sub set_header } elsif ($state->{pkgpath}) { $state->{currentheader} = $self->{subdir}.':'; } + $state->{done}{$self->{subdir}} = 1; $state->errsay($state->{currentheader}) unless $state->{quiet}; } package OpenBSD::PackingElement::FileObject; +sub object_name +{ + my ($self, $state) = @_; + if ($state->{full}) { + if ($self->needs_keyword) { + return "\@".$self->keyword." ".$self->fullname; + } + } + return $self->fullname; +} + sub print_name { my ($self, $state) = @_; - print {$state->{out}} $state->{currentheader}, $self->fullname, "\n"; + print {$state->{out}} $state->{currentheader}, + $self->object_name($state), "\n"; } package OpenBSD::PackingElement::Action; @@ -101,7 +116,8 @@ package OpenBSD::PackingElement::DirBase; sub print_name { my ($self, $state) = @_; - print {$state->{out}} $state->{currentheader}, $self->fullname, "/\n"; + print {$state->{out}} $state->{currentheader}, + $self->object_name($state), "/\n"; } package main; @@ -259,6 +275,19 @@ sub do_pkgdir }, $state->{pkgdir}); } +sub copy_stdin +{ + my $state = shift; + while () { + # if we find something that looks like a pkgpath we've done + # assume we were updating it + if (m,([^:]*/[^:]*)\:,) { + next if defined $state->{done}{$1}; + } + print {$state->{out}} $_; + } +} + my $state = OpenBSD::Pkgmklocatedb::State->new("pkg_mklocatedb"); $state->handle_options; @@ -281,13 +310,16 @@ if ($state->{portsdir}) { } 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; - print_out($plist, $state); - }); + if (!$state->{update}) { + $state->progress->for_list("Scanning installation", + [installed_packages()], sub { + my $pkgname = shift; + my $plist = + OpenBSD::PackingList->from_installation($pkgname); + return unless defined $plist; + print_out($plist, $state); + }); + } } else { $state->progress->for_list("Scanning packages", \@ARGV, sub { @@ -297,3 +329,6 @@ if ($state->{portsdir}) { print_out($plist, $state); }); } +if ($state->{update}) { + copy_stdin($state); +} -- cgit v1.2.3