| 1 |
#! /usr/bin/perl -w |
| 2 |
# Migrate an old-style database to the new hashed (db-h) form. |
| 3 |
|
| 4 |
use strict; |
| 5 |
use File::Copy; |
| 6 |
|
| 7 |
if (@ARGV != 2) { |
| 8 |
print <<EOF; |
| 9 |
Usage: $0 old-db-directory new-db-directory |
| 10 |
|
| 11 |
debbugs-dbhash converts an old-style flat debbugs database into a |
| 12 |
new-style hashed-directory debbugs database. |
| 13 |
|
| 14 |
The old database is simply copied, and otherwise left untouched. |
| 15 |
The directory given for the new database must not already exist. |
| 16 |
|
| 17 |
EOF |
| 18 |
exit 0; |
| 19 |
} |
| 20 |
|
| 21 |
my ($db, $dbh) = @ARGV[0, 1]; |
| 22 |
opendir DB, $db or die "Can't opendir $db: $!"; |
| 23 |
mkdir $dbh or die "Can't mkdir $dbh: $!"; |
| 24 |
for my $i (0 .. 99) { |
| 25 |
my $dir = sprintf '%s/%02d', $dbh, $i; |
| 26 |
mkdir $dir or die "Can't mkdir $dir: $!"; |
| 27 |
} |
| 28 |
|
| 29 |
while (defined(my $file = readdir DB)) { |
| 30 |
next if $file =~ /^\.\.?$/; |
| 31 |
my $oldfile = "$db/$file"; |
| 32 |
my $newfile; |
| 33 |
if ($file =~ /(\d*)(\d\d)\.(.*)/) { |
| 34 |
$newfile = "$dbh/$2/$1$2.$3"; |
| 35 |
} else { |
| 36 |
warn "Not hashing $file.\n"; |
| 37 |
$newfile = "$dbh/$file"; |
| 38 |
} |
| 39 |
copy $oldfile, $newfile or warn "Can't copy $oldfile to $newfile: $!"; |
| 40 |
} |
| 41 |
|
| 42 |
closedir DB; |