File: update-dlocatedb

package info (click to toggle)
dlocate 0.5-0.3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 80 kB
  • sloc: sh: 156; perl: 77; makefile: 43
file content (34 lines) | stat: -rwxr-xr-x 1,095 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/perl                                                                 

# perl script originally by hallon@debian.org, much faster than sed & sh.
# modified by cas to pass it's output through frcode and then > to the
# db file.

$dbfile='/var/lib/dlocate/dlocatedb' ;

$frcode='/usr/lib/locate/frcode' ;

open(FRCODE,"|$frcode >$dbfile.new") || die "couldn't open pipe to $frcode: $!\n" ;

opendir(DIR, "/var/lib/dpkg/info") || die "can't open dir";
@pkgs = grep { /list$/ && s/\.list// } readdir(DIR);
closedir DIR;
 
chdir "/var/lib/dpkg/info";
foreach $pkg (@pkgs) {
    open(FILE, $pkg . ".list") || die "can't open file";
    foreach (<FILE>) {
        print FRCODE $pkg, ": ", $_;
    }                                                                           
    close FILE;
}    
close FRCODE ;

# Create a backup to the database before replacing it with the new database.
# This is effectively two rename's done atomically.
if (-e $dbfile) {
	unlink("$dbfile.old") if (-e "$dbfile.old");
	link("$dbfile", "$dbfile.old") if (-e $dbfile);
}

rename("$dbfile.new","$dbfile") ;