use Cwd; $root = $ENV{IFILEREPO} or die "IFILEREPO not set"; %special = ( "AUTO" => 1, "DIR" => 2, "ZERO" => 3, "ZEROHDR" => 4); sub loadCache { open $in, "<", "$root/diskIndex/__cache__" or die "Can't open __cache__, $!"; while (<$in>) { chomp; my ($key, @locations) = split /:/; my($file,$checksum) = split /\x1c/, $key; my $rfile = lc($file); push @{$lookup{$rfile,$checksum}}, @locations; push @{$all{$checksum}}, @locations; } } sub reIndex { my $index = $_[0]; my $updated = 0; 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 (/^#/) { if (/^# Also/i) { $updated++; } else { print $out $_; } next; } chomp; my ($file,$attributes,$checksum,$location) = (split ','); my $rfile = lc($file); if (substr($location, 0, 1) eq "*" || defined($special{$location})) { ; } elsif (defined($all{$checksum})) { # there is at least one file in the reposity $location = substr($location, 1) if substr($location, 0, 1) eq "^"; # remove the ^ if (defined($lookup{$rfile,$checksum})) { @locations = @{$lookup{$rfile,$checksum}}; # prefer matching isis name } else { @locations = @{$all{$checksum}}; } if (grep {$location eq $_ } @locations) { # don't change if existing name ok $location = "^$location"; } else { $location = "^" . shift @locations; # first in list; $location .= "\n# Also " . join(" ", @locations) if $#locations >= 0; $updated++; } } print $out "$file,$attributes,$checksum,$location\n"; } close $in; close $out; if ($updated) { unlink $index; rename "$index.tmp",$index; } else { unlink "$index.tmp"; } } else { print "Can't load $index\n"; } print "$index - $updated update(s)\n" if ($updated); } loadCache(); opendir my $dir, '.' or die "Couldn't read directory, $!"; while (my $f = readdir $dir) { reIndex($f) if $f =~ /^\@/; }