X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXDupe.pm;h=fb1210a2a15b7186c11980712b52ba6120d80a1d;hb=2145c6711ead2e9bc0e599044343c5c9064c3ddc;hp=cd4272c787530d24473dc821fcd7b724596762c9;hpb=334765d047bc6f15f8c15686afc07b0242c6919f;p=spider.git diff --git a/perl/DXDupe.pm b/perl/DXDupe.pm index cd4272c7..fb1210a2 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 ($!)"; + 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