+ . $v;
+ }
+ untie %packages_contents_db;
+
+ rename("$DBDIR/reverse.tmp", "$DBDIR/reverse_${suite}_${arch}.txt");
+
+ activate($filelist_db);
+ #FIXME: hardcoded archs. (debports has no contrib/non-free)
+ if ($arch !~ m/^kfreebsd-.*$/) {
+ system("ln", "-sf", basename($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;
+
+ print "Merging reverse path lists for ${suite}...\n";
+
+ open MERGED, "-|", "sort -m $DBDIR/reverse_${suite}_*.txt"
+ or die "Failed to open merged list";
+ open FILENAMES, ">", "$DBDIR/filenames_$suite.txt.new"
+ or die "Failed to open filenames list";
+ tie my %reverse_path_db, "DB_File", "$DBDIR/reverse_${suite}.db.new",
+ O_RDWR|O_CREAT, 0666, $DB_BTREE
+ or die "Error creating DB: $!";
+
+ my $lastpath = my $lastcasepath = my $lastfile = "";
+ my %matches = ();
+ while (<MERGED>) {
+ print "Doing line ".($NR/1000000)."M (out of approx. 20M)\n"
+ if $NR % 1000000 == 0;
+ chomp;
+ my @line = split m/\0/o, $_;
+ my $revpath = shift @line;
+ my $casepath = shift @line;
+ if ($revpath ne $lastpath) {
+ # Wrap: Do useful stuff with this ($lastpath, @matches)
+ if ($lastpath ne "") {
+ my @matches;
+ while (my ($k, $v) = each %matches) {
+ push @matches, join("\0", $k, @$v);
+ }
+ $reverse_path_db{$lastpath} = join "\1", @matches;
+ %matches = ();
+ }
+ $lastpath =~ s,/.*,,o;
+ if ($lastfile ne $lastpath) {
+ $lastfile = $lastpath;
+ print FILENAMES (reverse $lastfile)."\n";
+ }
+ #
+ $lastpath = $revpath;
+ $lastcasepath = $casepath;
+ $matches{$casepath} = \@line;
+ next;
+# } elsif ($lastcasepath ne "" and $casepath ne $lastcasepath) {
+# warn reverse($revpath)." has more than one casepath: $casepath $lastcasepath\n";
+ }
+ push @{$matches{$casepath}}, @line;
+ }
+ # Note: do useful stuff here too, for out last entry. Maybe prevent this by
+ # adding a fake ultimate entry?
+ {
+ my @matches;
+ while (my ($k, $v) = each %matches) {
+ push @matches, join("\0", $k, @$v);