X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXDupe.pm;h=3ccb23c89dd22df1b21369691cd2cf4950f8caf8;hb=1a3106f748d8123a2b88572227f18147019c61c5;hp=2ab0ca8cee3c81c15e677dafa8d855511186bb10;hpb=44bab9382ffb0bf12639af84729d1c42ac4d9ae2;p=spider.git diff --git a/perl/DXDupe.pm b/perl/DXDupe.pm index 2ab0ca8c..3ccb23c8 100644 --- a/perl/DXDupe.pm +++ b/perl/DXDupe.pm @@ -19,24 +19,49 @@ $default = 48*24*60*60; $lasttime = 0; $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,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 { undef $dbm; untie %d; + undef %d; } 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 @@ -73,6 +98,7 @@ sub listdups my $regex = shift; $regex =~ s/[\^\$\@\%]//g; + $regex = ".*$regex" if $regex; $regex = "^$let" . $regex; my @out; for (sort { $d{$a} <=> $d{$b} } grep { m{$regex}i } keys %d) {