use Digest::SHA1 qw(sha1_base64); %special = (AUTO => 1, ZERO => 2, ZEROHDR =>3, DIR => 4); $root = $ENV{"IFILEREPO"} || "./"; # the file repo $root =~ s/([^\/\\])$/\1\//; sub reIndex { my $index = $_[0]; print "$index\n"; if (open my $in,"<",$index) { open my $out, ">", "$index.tmp" or die "can't create $index.tmp\n"; while (<$in>) { print $out $_; last if /^Files:/; } while (<$in>) { if (/^#/) { print $out $_; next; } chomp; my ($file,$attributes,$len, $checksum,$location) = (split ','); my $srcFile = $location; $srcFile =~ s/^\^/$root/; if (defined($special{$srcFile}) || substr($srcFile, 0, 1) eq "*") { $checksum = "N/A"; } elsif (open ($src, "<:raw", $srcFile)) { local $/; $checksum = sha1_base64(<$src>); close $src; } else { $checksum = "TO FIX"; } print $out "$file,$attributes,$checksum,$location\n"; } close $in; close $out; unlink $index or die "can't delete $index $!"; rename "$index.tmp", $index; } } opendir my $dir, '.' or die "Couldn't open DiskIndex, $!"; while (my $f = readdir $dir) { reIndex($f) if $f =~ /^\@/; }