X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXDupe.pm;h=6595ef879c7cdd4446106e2a5183758d62fd2af7;hb=e8b741ad3a8df323116b5a42c833080e87ad3f5b;hp=2ab0ca8cee3c81c15e677dafa8d855511186bb10;hpb=44bab9382ffb0bf12639af84729d1c42ac4d9ae2;p=spider.git diff --git a/perl/DXDupe.pm b/perl/DXDupe.pm index 2ab0ca8c..6595ef87 100644 --- a/perl/DXDupe.pm +++ b/perl/DXDupe.pm @@ -19,26 +19,51 @@ $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}; - $t = $main::systime + $default unless $t; - $d{$s} = $t; + my $s = shift; + return 1 if find($s); + add($s, shift); return 0; } +sub find +{ + return $d{$_[0]}; +} + +sub add +{ + my $s = shift; + my $t = shift || $main::systime + $default; + $d{$s} = $t; +} + sub del { my $s = shift; @@ -73,11 +98,12 @@ 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) { my ($dum, $key) = unpack "a1a*", $_; - push @out, "$key = " . cldatetime($d{$_} - $dupage); + push @out, "$key = " . cldatetime($d{$_} - $dupage) . " expires " . cldatetime($d{$_}); } return @out; }