[interchange-cvs] interchange - ramoore modified lib/Vend/File.pm
interchange-core@icdevgroup.org
interchange-core@icdevgroup.org
Tue Apr 1 22:07:01 2003
User: ramoore
Date: 2003-04-02 03:06:18 GMT
Modified: lib/Vend File.pm
Log:
Ugly workarourd for flock bug in Perl 5.8.0
Revision Changes Path
2.2 +14 -3 interchange/lib/Vend/File.pm
rev 2.2, prev_rev 2.1
Index: File.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/File.pm,v
retrieving revision 2.1
retrieving revision 2.2
diff -u -r2.1 -r2.2
--- File.pm 1 Apr 2003 04:12:32 -0000 2.1
+++ File.pm 2 Apr 2003 03:06:18 -0000 2.2
@@ -1,6 +1,6 @@
# Vend::File - Interchange file functions
#
-# $Id: File.pm,v 2.1 2003/04/01 04:12:32 mheins Exp $
+# $Id: File.pm,v 2.2 2003/04/02 03:06:18 ramoore Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
#
@@ -52,7 +52,7 @@
use Vend::Util;
use subs qw(logError logGlobal);
use vars qw($VERSION @EXPORT @EXPORT_OK);
-$VERSION = substr(q$Revision: 2.1 $, 10);
+$VERSION = substr(q$Revision: 2.2 $, 10);
sub writefile {
my($file, $data, $opt) = @_;
@@ -228,7 +228,18 @@
my $flag = $excl ? $flock_LOCK_EX : $flock_LOCK_SH;
if ($wait) {
- flock($fh, $flag) or die "Could not lock file: $!\n";
+ my $trylimit = $Vend::Cfg->{Limit}{file_lock_retries} || 5;
+ my $failedcount;
+ while (
+ ! flock($fh, $flag)
+ and
+ $failedcount < $trylimit
+ )
+ {
+ $failedcount++;
+ select(undef,undef,undef,0.05 * $failedcount);
+ }
+ die "Could not lock file after $trylimit tries: $!\n" if ($failedcount == $trylimit);
return 1;
}
else {