regenerating /var/db/pkg

Matthias Andree mandree at FreeBSD.org
Thu Apr 22 17:40:01 UTC 2010


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


More information about the freebsd-hackers mailing list