1 package IndexData::Utils::PersistentCounter;
12 my($file, $create) = @_;
15 return undef if !$create;
16 # ### There is a bit of a race condition here, but it's not
17 # something that's going to crop up in real life.
18 my $fh = new IO::File(">$file") || return undef;
20 $fh->close() or return undef;
34 my $fh = new IO::File('+<' . $this->{file}) || return undef;
35 flock($fh, 2) || die "can't lock file";
38 $fh->print($n+1, "\n");
39 $fh->close() or return undef;
47 unlink $this->{file} or return 0;