+ }
+}
+
+print "Writing databases...\n";
+my %sources_small_db;
+tie %sources_small_db, "DB_File", "$DBDIR/sources_small.db.new",
+ O_RDWR|O_CREAT, 0666, $DB_BTREE
+ or die "Error creating DB: $!";
+while (my ($k, $v) = each(%sources_small)) {
+ $v =~ s/.$//s;
+ $sources_small_db{$k} = $v;
+}
+untie %sources_small_db;
+
+# package names stuff:
+for my $pkg (keys %source_names) {
+ for (my $i=0;$i<length($pkg)-1;$i++) {
+ my $before = substr($pkg, 0, $i);
+ my $after = substr($pkg, $i);
+ $before = "^" if $before eq ""; # otherwise split doesn't work properly
+ $source_postfixes{$after} .= "$before\0";
+ }
+}
+my %source_postfixes_db;
+tie %source_postfixes_db, "DB_File", "$DBDIR/source_postfixes.db.new",
+ O_RDWR|O_CREAT, 0666, $DB_BTREE
+ or die "Error creating DB: $!";
+while (my ($k, $v) = each(%source_postfixes)) {
+ $v =~ s/.$//s;
+ my $nr = ($v =~ tr/\000/\000/) + 1;
+ if ($nr > $MAX_SOURCE_POSTFIXES) {
+ $v = ($v =~ /\^/) ? "^\001" . $nr
+ : "\001" . $nr;
+ }
+ $source_postfixes_db{$k} = $v;