#!/usr/bin/perl use File::Find; my $ID="MP_file_index"; my $dir=shift || $ENV{MP_ROOT}; die("this is not a valid directory\n") unless (-d $dir); %mpindex = index_import_init("$dir/$ID"); find(sub{ my $path=$File::Find::name; for($path){ if(/xml$/ and not defined $mpindex{$_}) { $mpindex{__LAST__}++; $mpindex{$_}{perm} = (/fotos/ ? 0 : 1 ); $mpindex{$_}{id} = $mpindex{__LAST__}} # elsif(-d $_ and $mpindex{$path}{perm} == 0 ) { # $File::Find::prune;} } }, $dir); index_save("$dir/$ID", %mpindex); sub index_save{ my $path=shift; my %ind = @_; open(F, ">$path"); print F join("", (map {((/__LAST__/)?():("$ind{$_}{id}:$_:$ind{$_}{perm}\n")) } sort keys %ind)); print F "$mpindex{__LAST__}:__LAST__\n"; close F; } sub index_import_init{ my $path=shift; my %ind=(); if(-f $path) { open(F, $path ); while(){ if(/(.+):(.+):(.*)/){ $ind{$2}{id} = $1; $ind{$2}{perm} = $3} elsif(/(.+):(.+)/){ $ind{$2} = $1;} } close F; } else { $ind{__LAST__}=0;} %ind; }