-print "Writing databases...\n";
-my %packages_contents_db;
-tie %packages_contents_db, "DB_File", "packages_contents.db.new",
- O_RDWR|O_CREAT, 0666, $DB_BTREE
- or die "Error creating DB: $!";
-while (my ($k, $v) = each(%packages_contents)) {
- $v =~ s/.$//s;
- $packages_contents_db{$k} = $v;
-}
-untie %packages_contents_db;
+ my $filename = "$TOPDIR/archive/$archive/$suite/Contents-$arch.gz";
+ next unless -f $filename;
+ print "Reading $archive/$suite/$arch...\n";
+
+ open CONT, "zcat $filename|$what"
+ or die $!;
+ while (<CONT>) {last if /^FILE/mo;}
+ open CONT, "zcat $filename|$what" if eof(CONT);
+ while (<CONT>) {
+ my $data = "";
+ my %data = ();
+ chomp;
+ print "Doing line ".($./1000)."k (out of approx 1.5M)\n" if $. % 250000 == 0;
+ /^(.+?)\s+(\S+)$/o;
+ my ($file, $value) = ($1, $2);
+ $value =~ s#[^,/]+/##og;
+ my @packages = split /,/, $value;
+ for (@packages) {
+ $packages_contents_nr{$_}++;
+ my $lw = $packages_contents_lastword{$_} || "\0";
+ my $i=0;
+ while (substr($file,$i,1) eq substr($lw,$i++,1)) {}
+ $i--;
+ $i = 255 if $i > 255;
+ $packages_contents{$_} .= pack "CC/a*", ($i, substr($file, $i));
+ $packages_contents_lastword{$_} = "$file\0";
+ }
+ # Searches are case-insensitive
+ $file =~ tr [A-Z] [a-z];
+
+ print REVERSED (reverse $file)."\0".(join ":$arch\0", @packages).":$arch\n";
+ }
+ close CONT;
+
+ }
+ close REVERSED;
+
+ print "Sorting reverse list if needed\n";
+ system("cd $DBDIR && sort reverse.tmp > reverse.sorted && mv reverse.{sorted,tmp}") == 0
+ or die "Failed to sort reverse"
+ unless $SORT_REVERSE_CONCURRENTLY;
+
+ print "Writing filelist db\n";
+ tie my %packages_contents_db, "DB_File", "$filelist_db.new",
+ O_RDWR|O_CREAT, 0666, $DB_BTREE
+ or die "Error creating DB: $!";
+ while (my ($k, $v) = each(%packages_contents)) {
+ $packages_contents_db{$k} = (pack "L", $packages_contents_nr{$k})
+ . $v;
+ }
+ untie %packages_contents_db;
+
+ rename("$DBDIR/reverse.tmp", "$DBDIR/reverse_${suite}_${arch}.txt");
+
+ rename("$filelist_db.new", $filelist_db);
+ system("ln -sf $filelist_db $DBDIR/filelists_${suite}_all.db") == 0
+ or die "Oops";
+ }
+ }
+
+ my $go = 0;
+ my $suite_mtime = (stat "$DBDIR/reverse_$suite.db")[9];
+ for my $file (glob "$DBDIR/reverse_${suite}_*.txt") {
+ $go = 1 if not defined $suite_mtime
+ or $suite_mtime < (stat $file)[9];
+ }
+ next unless $go;