From owner-freebsd-hackers@FreeBSD.ORG Thu Apr 22 17:40:01 2010 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9ED9B1065674 for ; Thu, 22 Apr 2010 17:40:01 +0000 (UTC) (envelope-from mandree@FreeBSD.org) Received: from unimail.uni-dortmund.de (mx1.HRZ.Uni-Dortmund.DE [129.217.128.51]) by mx1.freebsd.org (Postfix) with ESMTP id 2F9A58FC1F for ; Thu, 22 Apr 2010 17:40:00 +0000 (UTC) Received: from [131.234.21.116] (baloo.cs.uni-paderborn.de [131.234.21.116]) (authenticated bits=0) by unimail.uni-dortmund.de (8.14.4/8.14.4) with ESMTP id o3MHdxdv004584 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NOT) for ; Thu, 22 Apr 2010 19:39:59 +0200 (CEST) Message-ID: <4BD089EE.4020508@FreeBSD.org> Date: Thu, 22 Apr 2010 19:39:58 +0200 From: Matthias Andree User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.1.9) Gecko/20100317 Lightning/1.0b1 Thunderbird/3.0.4 MIME-Version: 1.0 To: freebsd-hackers@FreeBSD.org References: <4BCE5ECC.6070202@gmail.com> <20100422124932.GA21661@night.db.net> In-Reply-To: <20100422124932.GA21661@night.db.net> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Subject: Re: regenerating /var/db/pkg X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Apr 2010 17:40:01 -0000 Am 22.04.2010 14:49, schrieb Diane Bruce: > On Tue, Apr 20, 2010 at 10:11:24PM -0400, Aryeh M. Friedman wrote: >> I acciddentally rm'ed my /var/db/pkg and want to know is it possible to >> rgenerate it (I have portmaster and portupgrade installed) > > > You would have to write a script which went through each file in > /usr/local/bin and /usr/local/lib (mostly sufficient) and examined > every single pkg-plist looking for the corresponding file. Then you > know what port the file was generated by. Needless to say, this would > be somewhat horrible. Diane, it's not *that* bad. Consider this algorithm: 1. scan for files under /usr/local/{bin,include,lib,libexec,sbin} and sort or hash the list - perhaps guess just a port name from an executable in /usr/local/bin 2. Repeat: 2.1 use the next file from the list and search for it 2.2 once you have a port name for this file, obtain the packing list and remove it from the file list in 1. This cuts down the list from 1 quite a bit. 3. Now print the list of ports found, and print the list of files not found in ports Surely and index of plist files in port default configurations could help big time, but even a blunt ( cd /usr/ports && find . -mindepth 3 -maxdepth 3 -name pkg-plist -exec egrep FILENAME '{}' + ) might be reasonable given sufficient RAM so that it runs from cache for the 2nd file you inquire. If that is too slow, a step between 1 and 2 could procure all pkg-plists as some sort of FILEINDEX file to accelerate searches. HTH Matthias