+ 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";
+ }
+
+ 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 $lastfile = "";
+ my @matches = ();
+ while (<MERGED>) {
+ print "Doing line ".($./1000000)."M (out of approx. 16M)\n" if $. % 1000000 == 0;
+ chomp;
+ my @line = split /\0/o, $_;
+ my $revpath = shift @line;
+ if ($revpath ne $lastpath) {
+ # Wrap: Do useful stuff with this ($lastpath, @matches)
+ $reverse_path_db{$lastpath} = join "\0", @matches if $lastpath ne "";
+ $lastpath =~ s,/.*,,o;
+ if ($lastfile ne $lastpath) {
+ $lastfile = $lastpath;
+ print FILENAMES (reverse $lastfile)."\n";
+ }
+ #
+ $lastpath = $revpath;
+ @matches = @line;
+ next;
+ }
+ push @matches, @line
+ }
+ # Note: do useful stuff here too, for out last entry. Maybe prevent this by
+ # adding a fake ultimate entry?
+ $reverse_path_db{$lastpath} = join "\0", @matches;
+
+ untie %reverse_path_db;
+ close FILENAMES;
+ close MERGED;
+
+ rename "$DBDIR/filenames_$suite.txt.new", "$DBDIR/filenames_$suite.txt";
+ rename "$DBDIR/reverse_$suite.db.new", "$DBDIR/reverse_$suite.db";
+}}
+
+#print "Writing databases...\n";