X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXDupe.pm;h=ac4dea2172a6f991c81b4c897f7cb512c69a8dcc;hb=4327a846608d5828537a3c37f90848db0f10d06f;hp=5a01bee99a6acdfa1e6e39c204e623a2d1c46ba4;hpb=2b58ccdf81685a1167a43c38705a0d84b9d8d661;p=spider.git diff --git a/perl/DXDupe.pm b/perl/DXDupe.pm index 5a01bee9..ac4dea21 100644 --- a/perl/DXDupe.pm +++ b/perl/DXDupe.pm @@ -21,13 +21,20 @@ $fn = "$main::data/dupefile"; use vars qw($VERSION $BRANCH); $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ ); -$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ ) || 0; +$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/,(0,0)); $main::build += $VERSION; $main::branch += $BRANCH; sub init { - $dbm = tie (%d, 'DB_File', $fn) or confess "can't open dupe file: $fn ($!)"; + $dbm = tie (%d, 'DB_File', $fn); + unless ($dbm) { + eval { untie %d }; + dbg("Dupefile $fn corrupted, removing..."); + unlink $fn; + $dbm = tie (%d, 'DB_File', $fn) or confess "can't open dupe file: $fn ($!)"; + confess "cannot open $fn $!" unless $dbm; + } } sub finish @@ -40,10 +47,21 @@ sub finish sub check { my ($s, $t) = @_; - return 1 if exists $d{$s}; + return 1 if find($s); + add($s, $t); + return 0; +} + +sub find +{ + return 1 if exists $d{$_[0]}; +} + +sub add +{ + my ($s, $t) = @_; $t = $main::systime + $default unless $t; $d{$s} = $t; - return 0; } sub del